@Test public void testInvertPermutationInt(){ assertArrayEquals( new int[]{ 2, 4, 3, 0, 1 }, ArrayUtil.invertPermutation(3, 4, 0, 2, 1) ); }
public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; }
ArrayUtil { public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; } }
ArrayUtil { public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; } private  ArrayUtil(); }
ArrayUtil { public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; } private  ArrayUtil(); static boolean containsAnyNegative(int[] arr); static boolean containsAnyNegative(long[] arr); static boolean contains(int[] arr, int value); static boolean contains(long[] arr, int value); static boolean anyLargerThan(int[] arrs, int check); static boolean anyLessThan(int[] arrs, int check); static String[] convertToString(int[] arr); static boolean listOfIntsContains(List<int[]> list,int[] target); static int[] nTimes(int n, int toReplicate); static long[] nTimes(long n, long toReplicate); static T[] nTimes(int n, T toReplicate, Class<T> tClass); static boolean allUnique(int[] toTest); static int[] randomPermutation(int size); static short toBFloat16(float data); static short toBFloat16(double data); static short toHalf(float data); static short toHalf(double data); static short[] toHalfs(float[] data); static short[] toHalfs(int[] data); static short[] toHalfs(long[] data); static short[] toBfloats(float[] data); static short[] toBfloats(int[] data); static short[] toBfloats(long[] data); static long[] toLongs(byte[] data); static long[] toLongs(boolean[] data); static long[] toLongs(short[] data); static long[] toLongs(int[] data); static long[] toLongs(float[] data); static long[] toLongs(double[] data); static short[] toHalfs(double[] data); static short fromFloat(float v); static int[] toInts(float[] data); static int[] toInts(double[] data); static byte[] toBytes(int[] array); static byte[] toBytes(float[] array); static byte[] toBytes(double[] array); static byte[] toBytes(long[] array); static int[] toInts(long[] array); static int[] mod(int[] input,int mod); static int offsetFor(int[] stride, int i); static int sum(List<Integer> add); static int sum(int[] add); static long sumLong(long... add); static int prod(List<Integer> mult); static int prod(long... mult); static int prod(int... mult); static long prodLong(List<? extends Number> mult); static long prodLong(int... mult); static long prodLong(long... mult); static boolean equals(float[] data, double[] data2); static int[] consArray(int a, int[] as); static boolean isZero(int[] as); static boolean isZero(long[] as); static boolean anyMore(int[] target, int[] test); static boolean anyLess(int[] target, int[] test); static boolean lessThan(int[] target, int[] test); static boolean greaterThan(int[] target, int[] test); static int calcOffset(List<Integer> shape, List<Integer> offsets, List<Integer> strides); static int calcOffset(int[] shape, int[] offsets, int[] strides); static long calcOffsetLong(List<Integer> shape, List<Integer> offsets, List<Integer> strides); static long calcOffsetLong2(List<Long> shape, List<Long> offsets, List<Long> strides); static long calcOffsetLong(int[] shape, int[] offsets, int[] strides); static int dotProduct(List<Integer> xs, List<Integer> ys); static int dotProduct(int[] xs, int[] ys); static long dotProductLong(List<Integer> xs, List<Integer> ys); static long dotProductLong2(List<Long> xs, List<Long> ys); static long dotProductLong(int[] xs, int[] ys); static int[] empty(); static int[] of(int... arr); static int[] copy(int[] copy); static long[] copy(long[] copy); static double[] doubleCopyOf(float[] data); static float[] floatCopyOf(double[] data); static double[] range(double[] data, int to); static double[] range(double[] data, int to, int stride); static double[] range(double[] data, int to, int stride, int numElementsEachStride); static List<Integer> toList(int... ints); static int[] toArray(List<Integer> list); static long[] toArrayLong(List<Long> list); static double[] toArrayDouble(List<Double> list); static int[] range(int from, int to, int increment); static long[] range(long from, long to, long increment); static int[] range(int from, int to); static long[] range(long from, long to); static double[] toDoubles(int[] ints); static double[] toDoubles(long[] ints); static double[] toDoubles(float[] ints); static float[] toFloats(int[][] ints); static double[] toDoubles(int[][] ints); static short[] toShorts(long[] ints); static short[] toShorts(int[] ints); static short[] toShorts(float[] ints); static short[] toShorts(double[] ints); static float[] toFloats(int[] ints); static float[] toFloats(long[] ints); static float[] toFloats(double[] ints); static int[] cutBelowZero(int[] data); static long[] cutBelowZero(long[] data); static short[] cutBelowZero(short[] data); static byte[] cutBelowZero(byte[] data); static int[] replace(int[] data, int index, int newValue); static int[] keep(int[] data, int... index); static long[] keep(long[] data, int... index); static int[] removeIndex(int[] data, int... index); static long[] removeIndex(long[] data, int... index); static int[][] zip(int[] as, int[] bs); static long[] getTensorMmulShape(long[] aShape, long[] bShape, int[][] axes); static int[] permute(int[] shape, int[] dimensions); static long[] permute(long[] shape, int[] dimensions); static int[] argsort(int[] a); static int[] argsort(final int[] a, final boolean ascending); static int[] convertNegativeIndices(int range, int[] axes); static int[] copyOfRangeFrom(int length, int from, int to); static byte[] toByteArray(double[] doubleArray); static double[] toDoubleArray(byte[] byteArray); static byte[] toByteArray(float[] doubleArray); static long[] toLongArray(int[] intArray); static long[] toLongArray(float[] array); static float[] toFloatArray(byte[] byteArray); static byte[] toByteArray(int[] intArray); static int[] toIntArray(byte[] byteArray); static int[] removeIndex(int[] data, int index); static long[] removeIndex(long[] data, int index); static int[] valueStartingAt(int valueStarting, int[] copy, int idxFrom, int idxAt, int length); static Integer[] removeIndex(Integer[] data, int index); static int[] calcStridesFortran(int[] shape, int startNum); static long[] calcStridesFortran(long[] shape, int startNum); static int[] calcStridesFortran(int[] shape); static long[] calcStridesFortran(long[] shape); static int[] calcStrides(int[] shape, int startValue); static long[] calcStrides(long[] shape, int startValue); static boolean isInverse(int[] first, int[] second); static int[] plus(int[] ints, int mult); static int[] plus(int[] ints, int[] mult); static int[] times(int[] ints, int mult); static int[] times(int[] ints, int[] mult); static int nonOneStride(int[] arr); static int[] calcStrides(int[] shape); static long[] calcStrides(long[] shape); static int[] reverseCopy(int[] e); static long[] reverseCopy(long[] e); static double[] read(int length, DataInputStream dis); static void write(double[] data, DataOutputStream dos); static double[] readDouble(int length, DataInputStream dis); static float[] readFloat(int length, DataInputStream dis); static void write(float[] data, DataOutputStream dos); static void assertSquare(double[]... d); static void multiplyBy(int[] arr, int mult); static void reverse(int[] e); static void reverse(long[] e); static List<double[]> zerosMatrix(long... dimensions); static List<double[]> zerosMatrix(int... dimensions); static float[] reverseCopy(float[] e); static E[] reverseCopy(E[] e); static void reverse(E[] e); static boolean[] flatten(boolean[][] arr); static boolean[] flatten(boolean[][][] arr); static float[] flatten(float[][] arr); static float[] flatten(float[][][] arr); static double[] flatten(double[][][] arr); static int[] flatten(int[][][] arr); static short[] flatten(short[][][] arr); static byte[] flatten(byte[][][] arr); static long[] flatten(long[][][][] arr); static short[] flatten(short[][][][] arr); static byte[] flatten(byte[][][][] arr); static boolean[] flatten(boolean[][][][] arr); static float[] flatten(float[][][][] arr); static double[] flatten(double[][][][] arr); static int[] flatten(int[][][][] arr); static int[] flatten(int[][] arr); static short[] flatten(short[][] arr); static byte[] flatten(byte[][] arr); static long[] flatten(long[][] arr); static long[] flatten(long[][][] arr); static double[] flatten(double[][] arr); static double[] flattenF(double[][] arr); static float[] flattenF(float[][] arr); static int[] flattenF(int[][] arr); static long[] flattenF(long[][] arr); static int[][] reshapeInt(int[] in, int rows, int cols); static int[][][] reshapeInt(int[] in, int d0, int d1, int d2); static double[][] reshapeDouble(double[] in, int rows, int cols); static double[][][] reshapeDouble(double[] in, int d0, int d1, int d2); static long[][] reshapeLong(long[] in, int rows, int cols); static long[][][] reshapeLong(long[] in, int d0, int d1, int d2); static boolean[][] reshapeBoolean(boolean[] in, int rows, int cols); static boolean[][][] reshapeBoolean(boolean[] in, int d0, int d1, int d2); static T[][] reshapeObject(T[] in, int rows, int cols); static T[][][] reshapeObject(T[] in, int d0, int d1, int d2); static double[][] toDouble(int[][] arr); static float[] combineFloat(List<float[]> nums); static float[] combine(List<float[]> nums); static double[] combineDouble(List<double[]> nums); static double[] combine(float[]... ints); static int[] combine(int[]... ints); static long[] combine(long[]... ints); static E[] combine(E[]... arrs); static int[] toOutcomeArray(int outcome, int numOutcomes); static double[] toDouble(int[] data); static double[] toDouble(long[] data); static float[] copy(float[] data); static double[] copy(double[] data); static double[] flattenDoubleArray(Object doubleArray); static float[] flattenFloatArray(Object floatArray); static int[] arrayShape(Object array); static int[] arrayShape(Object array, boolean allowSize0Dims); static int max(int[] in); static int min(int[] in); static int argMax(int[] in); static int argMin(int[] in); static int argMax(long[] in); static int argMin(long[] in); static int[] buildHalfVector(Random rng, int length); static int[] buildInterleavedVector(Random rng, int length); static long[] buildInterleavedVector(Random rng, long length); static void shuffleWithMap(List<T> objects, int[] map); static int argMinOfMax(int[] first, int[] second); static long argMinOfMax(long[] first, long[] second); static int argMinOfMax(int[]... arrays); static long argMinOfMax(long[]... arrays); static int argMinOfSum(int[] first, int[] second); static Map<K, V> sortMapByValue(Map<K, V> map); static T getRandomElement(List<T> list); static int fromBoolean(boolean bool); static long[] toPrimitives(Long[] array); static int[] toPrimitives(Integer[] array); static short[] toPrimitives(Short[] array); static byte[] toPrimitives(Byte[] array); static float[] toPrimitives(Float[] array); static double[] toPrimitives(Double[] array); static boolean[] toPrimitives(Boolean[] array); static long[][] toPrimitives(Long[][] array); static int[][] toPrimitives(Integer[][] array); static short[][] toPrimitives(Short[][] array); static byte[][] toPrimitives(Byte[][] array); static double[][] toPrimitives(Double[][] array); static float[][] toPrimitives(Float[][] array); static boolean [][] toPrimitives(Boolean[][] array); static long[][][] toPrimitives(Long[][][] array); static int[][][] toPrimitives(Integer[][][] array); static short[][][] toPrimitives(Short[][][] array); static byte[][][] toPrimitives(Byte[][][] array); static double[][][] toPrimitives(Double[][][] array); static float[][][] toPrimitives(Float[][][] array); static boolean[][][] toPrimitives(Boolean[][][] array); static long[][][][] toPrimitives(Long[][][][] array); static int[][][][] toPrimitives(Integer[][][][] array); static short[][][][] toPrimitives(Short[][][][] array); static byte[][][][] toPrimitives(Byte[][][][] array); static double[][][][] toPrimitives(Double[][][][] array); static float[][][][] toPrimitives(Float[][][][] array); static boolean[][][][] toPrimitives(Boolean[][][][] array); static void assertNotRagged(T[] array); static int arrayLength(Object current); static int[] invertPermutation(int... input); static long[] invertPermutation(long... input); static boolean isEmptyShape(long[] shape); static boolean isEmptyShape(int[] shape); static T[] filterNull(T... in); }
ArrayUtil { public static int[] invertPermutation(int... input){ int[] target = new int[input.length]; for(int i = 0 ; i < input.length ; i++){ target[input[i]] = i; } return target; } private  ArrayUtil(); static boolean containsAnyNegative(int[] arr); static boolean containsAnyNegative(long[] arr); static boolean contains(int[] arr, int value); static boolean contains(long[] arr, int value); static boolean anyLargerThan(int[] arrs, int check); static boolean anyLessThan(int[] arrs, int check); static String[] convertToString(int[] arr); static boolean listOfIntsContains(List<int[]> list,int[] target); static int[] nTimes(int n, int toReplicate); static long[] nTimes(long n, long toReplicate); static T[] nTimes(int n, T toReplicate, Class<T> tClass); static boolean allUnique(int[] toTest); static int[] randomPermutation(int size); static short toBFloat16(float data); static short toBFloat16(double data); static short toHalf(float data); static short toHalf(double data); static short[] toHalfs(float[] data); static short[] toHalfs(int[] data); static short[] toHalfs(long[] data); static short[] toBfloats(float[] data); static short[] toBfloats(int[] data); static short[] toBfloats(long[] data); static long[] toLongs(byte[] data); static long[] toLongs(boolean[] data); static long[] toLongs(short[] data); static long[] toLongs(int[] data); static long[] toLongs(float[] data); static long[] toLongs(double[] data); static short[] toHalfs(double[] data); static short fromFloat(float v); static int[] toInts(float[] data); static int[] toInts(double[] data); static byte[] toBytes(int[] array); static byte[] toBytes(float[] array); static byte[] toBytes(double[] array); static byte[] toBytes(long[] array); static int[] toInts(long[] array); static int[] mod(int[] input,int mod); static int offsetFor(int[] stride, int i); static int sum(List<Integer> add); static int sum(int[] add); static long sumLong(long... add); static int prod(List<Integer> mult); static int prod(long... mult); static int prod(int... mult); static long prodLong(List<? extends Number> mult); static long prodLong(int... mult); static long prodLong(long... mult); static boolean equals(float[] data, double[] data2); static int[] consArray(int a, int[] as); static boolean isZero(int[] as); static boolean isZero(long[] as); static boolean anyMore(int[] target, int[] test); static boolean anyLess(int[] target, int[] test); static boolean lessThan(int[] target, int[] test); static boolean greaterThan(int[] target, int[] test); static int calcOffset(List<Integer> shape, List<Integer> offsets, List<Integer> strides); static int calcOffset(int[] shape, int[] offsets, int[] strides); static long calcOffsetLong(List<Integer> shape, List<Integer> offsets, List<Integer> strides); static long calcOffsetLong2(List<Long> shape, List<Long> offsets, List<Long> strides); static long calcOffsetLong(int[] shape, int[] offsets, int[] strides); static int dotProduct(List<Integer> xs, List<Integer> ys); static int dotProduct(int[] xs, int[] ys); static long dotProductLong(List<Integer> xs, List<Integer> ys); static long dotProductLong2(List<Long> xs, List<Long> ys); static long dotProductLong(int[] xs, int[] ys); static int[] empty(); static int[] of(int... arr); static int[] copy(int[] copy); static long[] copy(long[] copy); static double[] doubleCopyOf(float[] data); static float[] floatCopyOf(double[] data); static double[] range(double[] data, int to); static double[] range(double[] data, int to, int stride); static double[] range(double[] data, int to, int stride, int numElementsEachStride); static List<Integer> toList(int... ints); static int[] toArray(List<Integer> list); static long[] toArrayLong(List<Long> list); static double[] toArrayDouble(List<Double> list); static int[] range(int from, int to, int increment); static long[] range(long from, long to, long increment); static int[] range(int from, int to); static long[] range(long from, long to); static double[] toDoubles(int[] ints); static double[] toDoubles(long[] ints); static double[] toDoubles(float[] ints); static float[] toFloats(int[][] ints); static double[] toDoubles(int[][] ints); static short[] toShorts(long[] ints); static short[] toShorts(int[] ints); static short[] toShorts(float[] ints); static short[] toShorts(double[] ints); static float[] toFloats(int[] ints); static float[] toFloats(long[] ints); static float[] toFloats(double[] ints); static int[] cutBelowZero(int[] data); static long[] cutBelowZero(long[] data); static short[] cutBelowZero(short[] data); static byte[] cutBelowZero(byte[] data); static int[] replace(int[] data, int index, int newValue); static int[] keep(int[] data, int... index); static long[] keep(long[] data, int... index); static int[] removeIndex(int[] data, int... index); static long[] removeIndex(long[] data, int... index); static int[][] zip(int[] as, int[] bs); static long[] getTensorMmulShape(long[] aShape, long[] bShape, int[][] axes); static int[] permute(int[] shape, int[] dimensions); static long[] permute(long[] shape, int[] dimensions); static int[] argsort(int[] a); static int[] argsort(final int[] a, final boolean ascending); static int[] convertNegativeIndices(int range, int[] axes); static int[] copyOfRangeFrom(int length, int from, int to); static byte[] toByteArray(double[] doubleArray); static double[] toDoubleArray(byte[] byteArray); static byte[] toByteArray(float[] doubleArray); static long[] toLongArray(int[] intArray); static long[] toLongArray(float[] array); static float[] toFloatArray(byte[] byteArray); static byte[] toByteArray(int[] intArray); static int[] toIntArray(byte[] byteArray); static int[] removeIndex(int[] data, int index); static long[] removeIndex(long[] data, int index); static int[] valueStartingAt(int valueStarting, int[] copy, int idxFrom, int idxAt, int length); static Integer[] removeIndex(Integer[] data, int index); static int[] calcStridesFortran(int[] shape, int startNum); static long[] calcStridesFortran(long[] shape, int startNum); static int[] calcStridesFortran(int[] shape); static long[] calcStridesFortran(long[] shape); static int[] calcStrides(int[] shape, int startValue); static long[] calcStrides(long[] shape, int startValue); static boolean isInverse(int[] first, int[] second); static int[] plus(int[] ints, int mult); static int[] plus(int[] ints, int[] mult); static int[] times(int[] ints, int mult); static int[] times(int[] ints, int[] mult); static int nonOneStride(int[] arr); static int[] calcStrides(int[] shape); static long[] calcStrides(long[] shape); static int[] reverseCopy(int[] e); static long[] reverseCopy(long[] e); static double[] read(int length, DataInputStream dis); static void write(double[] data, DataOutputStream dos); static double[] readDouble(int length, DataInputStream dis); static float[] readFloat(int length, DataInputStream dis); static void write(float[] data, DataOutputStream dos); static void assertSquare(double[]... d); static void multiplyBy(int[] arr, int mult); static void reverse(int[] e); static void reverse(long[] e); static List<double[]> zerosMatrix(long... dimensions); static List<double[]> zerosMatrix(int... dimensions); static float[] reverseCopy(float[] e); static E[] reverseCopy(E[] e); static void reverse(E[] e); static boolean[] flatten(boolean[][] arr); static boolean[] flatten(boolean[][][] arr); static float[] flatten(float[][] arr); static float[] flatten(float[][][] arr); static double[] flatten(double[][][] arr); static int[] flatten(int[][][] arr); static short[] flatten(short[][][] arr); static byte[] flatten(byte[][][] arr); static long[] flatten(long[][][][] arr); static short[] flatten(short[][][][] arr); static byte[] flatten(byte[][][][] arr); static boolean[] flatten(boolean[][][][] arr); static float[] flatten(float[][][][] arr); static double[] flatten(double[][][][] arr); static int[] flatten(int[][][][] arr); static int[] flatten(int[][] arr); static short[] flatten(short[][] arr); static byte[] flatten(byte[][] arr); static long[] flatten(long[][] arr); static long[] flatten(long[][][] arr); static double[] flatten(double[][] arr); static double[] flattenF(double[][] arr); static float[] flattenF(float[][] arr); static int[] flattenF(int[][] arr); static long[] flattenF(long[][] arr); static int[][] reshapeInt(int[] in, int rows, int cols); static int[][][] reshapeInt(int[] in, int d0, int d1, int d2); static double[][] reshapeDouble(double[] in, int rows, int cols); static double[][][] reshapeDouble(double[] in, int d0, int d1, int d2); static long[][] reshapeLong(long[] in, int rows, int cols); static long[][][] reshapeLong(long[] in, int d0, int d1, int d2); static boolean[][] reshapeBoolean(boolean[] in, int rows, int cols); static boolean[][][] reshapeBoolean(boolean[] in, int d0, int d1, int d2); static T[][] reshapeObject(T[] in, int rows, int cols); static T[][][] reshapeObject(T[] in, int d0, int d1, int d2); static double[][] toDouble(int[][] arr); static float[] combineFloat(List<float[]> nums); static float[] combine(List<float[]> nums); static double[] combineDouble(List<double[]> nums); static double[] combine(float[]... ints); static int[] combine(int[]... ints); static long[] combine(long[]... ints); static E[] combine(E[]... arrs); static int[] toOutcomeArray(int outcome, int numOutcomes); static double[] toDouble(int[] data); static double[] toDouble(long[] data); static float[] copy(float[] data); static double[] copy(double[] data); static double[] flattenDoubleArray(Object doubleArray); static float[] flattenFloatArray(Object floatArray); static int[] arrayShape(Object array); static int[] arrayShape(Object array, boolean allowSize0Dims); static int max(int[] in); static int min(int[] in); static int argMax(int[] in); static int argMin(int[] in); static int argMax(long[] in); static int argMin(long[] in); static int[] buildHalfVector(Random rng, int length); static int[] buildInterleavedVector(Random rng, int length); static long[] buildInterleavedVector(Random rng, long length); static void shuffleWithMap(List<T> objects, int[] map); static int argMinOfMax(int[] first, int[] second); static long argMinOfMax(long[] first, long[] second); static int argMinOfMax(int[]... arrays); static long argMinOfMax(long[]... arrays); static int argMinOfSum(int[] first, int[] second); static Map<K, V> sortMapByValue(Map<K, V> map); static T getRandomElement(List<T> list); static int fromBoolean(boolean bool); static long[] toPrimitives(Long[] array); static int[] toPrimitives(Integer[] array); static short[] toPrimitives(Short[] array); static byte[] toPrimitives(Byte[] array); static float[] toPrimitives(Float[] array); static double[] toPrimitives(Double[] array); static boolean[] toPrimitives(Boolean[] array); static long[][] toPrimitives(Long[][] array); static int[][] toPrimitives(Integer[][] array); static short[][] toPrimitives(Short[][] array); static byte[][] toPrimitives(Byte[][] array); static double[][] toPrimitives(Double[][] array); static float[][] toPrimitives(Float[][] array); static boolean [][] toPrimitives(Boolean[][] array); static long[][][] toPrimitives(Long[][][] array); static int[][][] toPrimitives(Integer[][][] array); static short[][][] toPrimitives(Short[][][] array); static byte[][][] toPrimitives(Byte[][][] array); static double[][][] toPrimitives(Double[][][] array); static float[][][] toPrimitives(Float[][][] array); static boolean[][][] toPrimitives(Boolean[][][] array); static long[][][][] toPrimitives(Long[][][][] array); static int[][][][] toPrimitives(Integer[][][][] array); static short[][][][] toPrimitives(Short[][][][] array); static byte[][][][] toPrimitives(Byte[][][][] array); static double[][][][] toPrimitives(Double[][][][] array); static float[][][][] toPrimitives(Float[][][][] array); static boolean[][][][] toPrimitives(Boolean[][][][] array); static void assertNotRagged(T[] array); static int arrayLength(Object current); static int[] invertPermutation(int... input); static long[] invertPermutation(long... input); static boolean isEmptyShape(long[] shape); static boolean isEmptyShape(int[] shape); static T[] filterNull(T... in);  }