Found while working on JDK-8369699.
The exception messages from convertShape are not very helpful. When the "part" argument is out of bounds, I would expect it to give me the valid range. It does not.
The "part" argument is a bit complicated, and depends on the "contraction" or "expansion" of the logical vs output vector. Already this naming is quite confusing, and it may be worth to adjust the naming there as well.
---------------------------------------------
I see 2 issues here:
1) The exception message for "part" does NOT currently give the range that would have been valid. It talks about expansion/contraction of element, which can be different to the expansion/contraction of the vector, which would have been more relevant.
2) I don't like calling something that does zero-padding a "contraction". And similarly, I don't like using "expansion" for something that truncates/selects a smaller part out of a larger one. If anything, the names should be swapped. But maybe it is better to just use "zero-pad" and "truncate/select".
---------------------------------------------
About the example:
The lanes are expanding by 2 is technically correct for the elements, but the valid range for part is -3..0 , indicating contraction of the vector!
The message is also not helping the user find out what input would have been acceptable.
Rather than telling the user about the elements, we should tell them about the valid range for part, so they can more quickly fix their bug.
Or maybe we give them an even more verbose message that is even more helpful.
Reading the spec: https://download.java.net/java/early_access/jdk26/docs/api/jdk.incubator.vector/jdk/incubator/vector/Vector.html#expansion
> In the first case, of a too-large logical result being crammed into a too-small output VSHAPE, we say that data has expanded. In other words, an expansion operation has caused the output shape to overflow. Symmetrically, in the second case of a small logical result fitting into a roomy output VSHAPE, the data has contracted, and the contraction operation has required the output shape to pad itself with extra zero lanes.
Applying this spec to our example:
- input: 2-floats
- logical: 2-double (elements were expanded by 2)
- output: 8-double (vector is contracted, i.e. we had to pad with zeros)
Personally, I'm not very happy with calling the transition from logical 2-double -> output 8-double a "contraction"...
But we can discuss that.
More from the spec:
>If a vector method might expand its data, it accepts an extra int parameter called part, or the "part number". The part number must be in the range [0..M-1], where M is the expansion ratio. The part number selects one of M contiguous disjoint equally-sized blocks of lanes from the logical result and fills the physical output vector with this block of lanes.
So expansion (I would prefer calling it select / truncate) needs a positive part.
> In the case of a contraction, the part number must be in the non-positive range [-M+1..0].
And contraction (I'd prefer calling it (zero-)padding) needs a non-positive part.
java Test.java
part = -10 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -10 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -9 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -9 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -8 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -8 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -7 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -7 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -6 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -6 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -5 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -5 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -4 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -4 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -3 success: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0]
part = -2 success: [0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0]
part = -1 success: [0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
part = 0 success: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
part = 1 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 1 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 2 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 2 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 3 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 3 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 4 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 4 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 5 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 5 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 6 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 6 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 7 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 7 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 8 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 8 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 9 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 9 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
The exception messages from convertShape are not very helpful. When the "part" argument is out of bounds, I would expect it to give me the valid range. It does not.
The "part" argument is a bit complicated, and depends on the "contraction" or "expansion" of the logical vs output vector. Already this naming is quite confusing, and it may be worth to adjust the naming there as well.
---------------------------------------------
I see 2 issues here:
1) The exception message for "part" does NOT currently give the range that would have been valid. It talks about expansion/contraction of element, which can be different to the expansion/contraction of the vector, which would have been more relevant.
2) I don't like calling something that does zero-padding a "contraction". And similarly, I don't like using "expansion" for something that truncates/selects a smaller part out of a larger one. If anything, the names should be swapped. But maybe it is better to just use "zero-pad" and "truncate/select".
---------------------------------------------
About the example:
The lanes are expanding by 2 is technically correct for the elements, but the valid range for part is -3..0 , indicating contraction of the vector!
The message is also not helping the user find out what input would have been acceptable.
Rather than telling the user about the elements, we should tell them about the valid range for part, so they can more quickly fix their bug.
Or maybe we give them an even more verbose message that is even more helpful.
Reading the spec: https://download.java.net/java/early_access/jdk26/docs/api/jdk.incubator.vector/jdk/incubator/vector/Vector.html#expansion
> In the first case, of a too-large logical result being crammed into a too-small output VSHAPE, we say that data has expanded. In other words, an expansion operation has caused the output shape to overflow. Symmetrically, in the second case of a small logical result fitting into a roomy output VSHAPE, the data has contracted, and the contraction operation has required the output shape to pad itself with extra zero lanes.
Applying this spec to our example:
- input: 2-floats
- logical: 2-double (elements were expanded by 2)
- output: 8-double (vector is contracted, i.e. we had to pad with zeros)
Personally, I'm not very happy with calling the transition from logical 2-double -> output 8-double a "contraction"...
But we can discuss that.
More from the spec:
>If a vector method might expand its data, it accepts an extra int parameter called part, or the "part number". The part number must be in the range [0..M-1], where M is the expansion ratio. The part number selects one of M contiguous disjoint equally-sized blocks of lanes from the logical result and fills the physical output vector with this block of lanes.
So expansion (I would prefer calling it select / truncate) needs a positive part.
> In the case of a contraction, the part number must be in the non-positive range [-M+1..0].
And contraction (I'd prefer calling it (zero-)padding) needs a non-positive part.
java Test.java
part = -10 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -10 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -9 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -9 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -8 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -8 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -7 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -7 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -6 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -6 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -5 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -5 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -4 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number -4 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = -3 success: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0]
part = -2 success: [0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 0.0, 0.0]
part = -1 success: [0.0, 0.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0]
part = 0 success: [2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
part = 1 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 1 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 2 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 2 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 3 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 3 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 4 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 4 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 5 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 5 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 6 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 6 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 7 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 7 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 8 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 8 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
part = 9 exception: java.lang.ArrayIndexOutOfBoundsException: bad part number 9 converting Species[float, 2, S_64_BIT] -> Species[double, 8, S_512_BIT] (lanes are expanding by 2)
- relates to
-
JDK-8369699 Template Framework Library: add VectorAPI types and operations
-
- Open
-