Suggestions for two new methods
Lippold, Dietmar
Dietmar.Lippold at zi-mannheim.de
Fri Aug 11 12:15:46 UTC 2017
Hi,
I want to suggest to add two new methods to the Vector API. The first method
named "minIndex" returns the first index of a value in a vector and is
suitable for every type of vector. In particular it can be used to determine
the index of the minimum and maximum value of a vector. The second method
named "indexVector" returns a vector of the integer values form zero up to
a given value.
Below are example implementations of the methods. But of course methods
which use intrinsics would probably be much more efficient.
public static IntVector indexVector(int elementNumber) {
IntVector indexVector;
indexVector = new IntVector(elementNumber);
for (int i = 0; i < elementNumber; i++) {
indexVector.set(i, i);
}
return indexVector;
}
public int minIndex(long value) {
IntVector lengthValVector;
IntVector intMaskVector;
IntVector indexVector;
int minIndex;
// The indexVector is independent of <code>value</code> and can be
// defined as a final attribute.
indexVector = IntVector.indexVector(length());
lengthValVector = new IntVector(length());
lengthValVector.setAll(length());
intMaskVector = new IntVector(length());
intMaskVector.setAll(1, equal(value));
minIndex = length() - lengthValVector.sub(indexVector).mul(intMaskVector).max();
if (minIndex < length()) {
return minIndex;
} else {
return -1;
}
}
Best regrads,
Dietmar
More information about the panama-dev
mailing list