}
@Override
public MultipleObjectsBundle filter(MultipleObjectsBundle objects) {
final int len = objects.dataLength();
MultipleObjectsBundle bundle = new MultipleObjectsBundle();
for(int r = 0; r < objects.metaLength(); r++) {
final SimpleTypeInformation<?> type = objects.meta(r);
final List<?> column = objects.getColumn(r);
if(!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(type)) {
bundle.appendColumn(type, column);
continue;
}
@SuppressWarnings("unchecked")
final List<? extends NumberVector<?, ?>> castColumn = (List<? extends NumberVector<?, ?>>) column;
// Get the replacement type information
final int dim = ((VectorFieldTypeInformation<?>) type).dimensionality();
final VectorFieldTypeInformation<IntegerVector> outType = new VectorFieldTypeInformation<IntegerVector>(IntegerVector.class, dim, IntegerVector.STATIC);
// Output vectors
int[][] posvecs = new int[len][dim];
// Sort for each dimension
// TODO: an int[] array would be enough, if we could use a comparator...
DoubleIntPair[] sorter = new DoubleIntPair[len];
for(int i = 0; i < sorter.length; i++) {
sorter[i] = new DoubleIntPair(Double.NaN, -1);
}
for(int d = 1; d <= dim; d++) {
// fill array
for(int i = 0; i < sorter.length; i++) {
sorter[i].first = castColumn.get(i).doubleValue(d);
sorter[i].second = i;
}
// Sort
Arrays.sort(sorter);
// Transfer positions to output vectors
for(int sta = 0; sta < sorter.length;) {
// Compute ties
int end = sta + 1;
while(end < sorter.length && sorter[sta].first == sorter[end].first) {
end++;
}
final int pos = (sta + end - 1);
for(int i = sta; i < end; i++) {
posvecs[sorter[i].second][d - 1] = pos;
}
sta = end;
}
}
// Prepare output data
final List<IntegerVector> outColumn = new ArrayList<IntegerVector>(len);
for(int i = 0; i < len; i++) {
outColumn.add(new IntegerVector(posvecs[i]));
}
bundle.appendColumn(outType, outColumn);
}
return bundle;
}