[vector api] Vector elements shift confusion
Tomasz Kowalczewski
tomasz.kowalczewski at gmail.com
Mon Jan 21 12:35:28 UTC 2019
Hi,
I started this email having problems using rotateER on vectors. I have
not found any way to call this method without getting an exception :).
More investigation revealed that shift-ing vector elements does not
work in accordance with javadoc. I realised this email will be quite
long so I split it up and will describe just shift issues. If my
suspicions are correct I will follow up with rotations.
First shiftEL operation describes itself "as if rotating left the lane
elements by i [...] zero value is placed into the result vector at
lane indexes less than i % this.length()."
*I suspect that the rotation is described in the wrong direction*.
Lets try to confirm it but just looking at zeroed lane indices (using
get() which "Gets the lane element at lane index i"):
@Test
public void shouldShiftElementsLeft() {
// Given
IntVector intVector =
IntVector.species(Vector.Shape.S_128_BIT).fromArray(new int[]{
1, 2, 3, 4
}, 0);
// When
intVector = intVector.shiftEL(2);
// Then
assertThat(intVector.get(0)).isEqualTo(0);
assertThat(intVector.get(1)).isEqualTo(0);
}
So after the shift of "2" lane indexes less than "2" should be zero.
This test fails as the rotation is done in the opposite (to me -
correct) direction:
@Test
public void shouldShiftElementsLeft() {
// Given
IntVector intVector =
IntVector.species(Vector.Shape.S_128_BIT).fromArray(new int[]{
1, 2, 3, 4
}, 0);
// When
intVector = intVector.shiftEL(2);
// Then
assertThat(intVector.toArray()).containsExactly(3, 4, 0, 0);
}
Same case is with shiftER. Java doc says that "zero value is placed
into the result vector at lane indexes greater or equal to
this.length() - (i % this.length()).". But zeroed are indexes < i %
this.length().
Looks like implementations are correct but javadoc-s are swapped (I
hope I am not making fool of myself).
Please advise,
Tomasz
More information about the panama-dev
mailing list