FunctionUtils { public static int toTensorIndex(final int[] indices, final int[] dimensions) { Validate.notNull(indices, "indices"); Validate.notNull(dimensions, "dimensions"); final int dim = indices.length; Validate.isTrue(dim == dimensions.length); int sum = 0; int product = 1; for (int i = 0; i < dim; i++) { Validate.isTrue(indices[i] < dimensions[i], "index out of bounds"); sum += indices[i] * product; product *= dimensions[i]; } return sum; } private  FunctionUtils(); static double square(final double x); static double cube(final double x); static int toTensorIndex(final int[] indices, final int[] dimensions); static int[] fromTensorIndex(final int index, final int[] dimensions); static double[] unique(final double[] in); static int[] unique(final int[] in); static int getLowerBoundIndex(final double[] set, final double value);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullIndices() { FunctionUtils.toTensorIndex(null, new int[] {1, 2, 3 }); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDimensions1() { FunctionUtils.toTensorIndex(new int[] {1, 2, 3 }, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongLength() { FunctionUtils.toTensorIndex(new int[] {1, 2 }, new int[] {1, 2, 3 }); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOutOfBounds() { final int[] indices = new int[] {2, 7, 1 }; final int[] dimensions = new int[] {5, 7, 3 }; toTensorIndex(indices, dimensions); }