List of usage examples for org.apache.commons.math3.util MathArrays sortInPlace
public static void sortInPlace(double[] x, double[]... yList) throws DimensionMismatchException, NullArgumentException
From source file:org.eclipse.january.dataset.DatasetUtils.java
/** * Sort in place given dataset and reorder ancillary datasets too * @param a dataset to be sorted/*www .j a v a 2 s . com*/ * @param b ancillary datasets */ public static void sort(Dataset a, Dataset... b) { if (!DTypeUtils.isDTypeNumerical(a.getDType())) { throw new UnsupportedOperationException("Sorting non-numerical datasets not supported yet"); } // gather all datasets as double dataset copies DoubleDataset s = copy(DoubleDataset.class, a); int l = b == null ? 0 : b.length; DoubleDataset[] t = new DoubleDataset[l]; int n = 0; for (int i = 0; i < l; i++) { if (b[i] != null) { if (!DTypeUtils.isDTypeNumerical(b[i].getDType())) { throw new UnsupportedOperationException("Sorting non-numerical datasets not supported yet"); } t[i] = copy(DoubleDataset.class, b[i]); n++; } } double[][] y = new double[n][]; for (int i = 0, j = 0; i < l; i++) { if (t[i] != null) { y[j++] = t[i].getData(); } } MathArrays.sortInPlace(s.getData(), y); a.setSlice(s); for (int i = 0; i < l; i++) { if (b[i] != null) { b[i].setSlice(t[i]); } } }