<div dir="ltr">Hi Vladimir,<div><br></div><div>Not sure I understand how that helps. Can you elaborate?</div><div><br></div><div>What I'm looking for is something like this:</div><div><br></div><div>private static <E> VectorShuffle<E> makeShuffle(VectorSpecies<E> species, int[] template)<br>{<br>  if (species.length() % template.length != 0) {<br>    throw new IllegalArgumentException();<br>  }<br><br>  int[] indexes = new int[species.length()];<br><br>  for (int i = 0; i < indexes.length; i++) {<br>    int index = template[i % template.length] + i - i % template.length;<br>    if (index < 0 || index >= species.length()) {<br>      throw new IllegalArgumentException();<br>    }<br>    indexes[i] = index;<br>  }<br><br>  return VectorShuffle.fromArray(species, indexes, 0);<br>}</div><div><br><div>Essentially, you give it a "template", such as {1, 0} to indicate you want those two lanes rearranged, and the function creates a shuffle array that replicates that pattern up to the length of the vector for the given species.</div><div><br></div><div>Maybe it's too niche, but without something of that sort it seems impossible to write code that uses rearrange() and works with SPECIES_PREFERRED.</div><div><br></div><div>- Martin<br></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 9, 2024 at 10:33 AM Vladimir Ivanov <<a href="mailto:vladimir.x.ivanov@oracle.com">vladimir.x.ivanov@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Martin,<br>
<br>
What about loading indices as a Vector first (using <br>
IntVector.fromArray()) and then converting it to VectorShuffle using <br>
Vector.toShuffle()?<br>
<br>
Best regards,<br>
Vladimir Ivanov<br>
<br>
On 7/9/24 09:59, Martin Traverso wrote:<br>
> Hi,<br>
> <br>
> I've been experimenting with the Vector API in an attempt to port the <br>
> XXH3 hashing algorithm to Java. One of the steps requires rearranging <br>
> the elements of a vector by swapping adjacent values. I.e., (v0, v1, v2, <br>
> v3, ...) -> (v1, v0, v3, v2, ...).<br>
> <br>
> One usability issue I'm running into is creating the VectorShuffle in a <br>
> species-agnostic manner. The VectorShuffle.fromArray() expects a number <br>
> of indices that matches *exactly* the length of the vector for the given <br>
> species, so it's harder to create a shuffle that uses SPECIES_PREFERRED <br>
> without additional logic to construct that array of indices dynamically.<br>
> <br>
> To illustrate, I need to do the following for each species:<br>
> <br>
>Â Â Â Â VectorShuffle.fromArray(LongVector.SPECIES_128, new int[] { 1, 0 }, 0)<br>
>Â Â Â Â VectorShuffle.fromArray(LongVector.SPECIES_256, new int[] { 1, 0, <br>
> 3, 2 }, 0)<br>
>Â Â Â Â VectorShuffle.fromArray(LongVector.SPECIES_512, new int[] { 1, 0, <br>
> 3, 2, 5, 4, 7, 6 }, 0)<br>
> <br>
> Of course, I could make something like this<br>
> <br>
>Â Â Â Â VectorShuffle.fromArray(LongVector.SPECIES_PREFERRED, <br>
> makeIndexesFromTemplate(new int[] { 1, 0 }), 0)<br>
> <br>
> with my own custom "makeIndexesFromTemplate" function to create the <br>
> array of indices of the appropriate length.<br>
> <br>
> Is there anything like that in the Vector APIs that I haven't been able <br>
> to find? If not, would it make sense to add something like it, or allow <br>
> VectorShuffle.fromXXX to derive such mapping?<br>
> <br>
> - Martin<br>
> <br>
</blockquote></div>