@Test(expectedExceptions = IllegalArgumentException.class) public void testOutOfBounds() { final int[] indices = new int[] {2, 7, 1 }; final int[] dimensions = new int[] {5, 7, 3 }; FunctionUtils.toTensorIndex(indices, dimensions); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongLength() { FunctionUtils.toTensorIndex(new int[] {1, 2 }, 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 testNullIndices() { FunctionUtils.toTensorIndex(null, new int[] {1, 2, 3 }); }
@Test public void testTensorIndexTest2() { final int[] indices = new int[] {2, 3 }; final int[] dimensions = new int[] {5, 7 }; final int index = FunctionUtils.toTensorIndex(indices, dimensions); final int[] res = FunctionUtils.fromTensorIndex(index, dimensions); assertEquals(indices[0], res[0], 0); assertEquals(indices[1], res[1], 0); }
@Test public void testTensorIndexTest1() { final int[] indices = new int[] {2 }; final int[] dimensions = new int[] {5 }; final int index = FunctionUtils.toTensorIndex(indices, dimensions); assertEquals(indices[0], index, 0); final int[] res = FunctionUtils.fromTensorIndex(index, dimensions); assertEquals(indices[0], res[0], 0); }
@Test public void testTwoD() { BasisFunctionKnots knots1 = BasisFunctionKnots.fromInternalKnots(KNOTS, 2); BasisFunctionKnots knots2 = BasisFunctionKnots.fromInternalKnots(KNOTS, 3); List<Function<double[], Double>> set = GENERATOR.generateSet(new BasisFunctionKnots[] {knots1, knots2 }); //pick of one of the basis functions for testing int index = FunctionUtils.toTensorIndex(new int[] {3, 3 }, new int[] {knots1.getNumSplines(), knots2.getNumSplines() }); Function<double[], Double> func = set.get(index); assertEquals(1. / 3., func.apply(new double[] {2.0, 2.0 }), 0.0); assertEquals(1. / 2., func.apply(new double[] {2.5, 2.0 }), 0.0); assertEquals(1. / 8. / 48., func.apply(new double[] {1.5, 3.5 }), 0.0); assertEquals(0.0, func.apply(new double[] {4.0, 2.5 }), 0.0); }
@Test public void testTensorIndexTest3() { final int[] indices = new int[] {2, 3, 1 }; final int[] dimensions = new int[] {5, 7, 3 }; final int index = FunctionUtils.toTensorIndex(indices, dimensions); final int[] res = FunctionUtils.fromTensorIndex(index, dimensions); assertEquals(indices[0], res[0], 0); assertEquals(indices[1], res[1], 0); assertEquals(indices[2], res[2], 0); }
@Test public void testThreeD() { BasisFunctionKnots knots1 = BasisFunctionKnots.fromInternalKnots(KNOTS, 2); BasisFunctionKnots knots2 = BasisFunctionKnots.fromInternalKnots(KNOTS, 3); BasisFunctionKnots knots3 = BasisFunctionKnots.fromInternalKnots(KNOTS, 1); List<Function<double[], Double>> set = GENERATOR.generateSet(new BasisFunctionKnots[] {knots1, knots2, knots3 }); //pick of one of the basis functions for testing int index = FunctionUtils.toTensorIndex(new int[] {3, 3, 3 }, new int[] {knots1.getNumSplines(), knots2.getNumSplines(), knots3.getNumSplines() }); Function<double[], Double> func = set.get(index); assertEquals(1. / 3., func.apply(new double[] {2.0, 2.0, 3.0 }), 0.0); }