public static <D extends DMatrix> FunctionNtoMxN<D> jacobianForwards(FunctionNtoM func, Class<D> type ) { if( type == DMatrixRMaj.class ) { return (FunctionNtoMxN)new NumericalJacobianForward_DDRM(func); } else if( type == DMatrixSparseCSC.class ) { return (FunctionNtoMxN)new NumericalJacobianForward_DSCC(func); } else { throw new RuntimeException("Matrix type unknown/not supported. "+type.getSimpleName()); } }
@Test public void simple() { // give it a function where one variable does not effect the output // to make the test more interesting SimpleFunction f = new SimpleFunction(); NumericalJacobianForward_DSCC alg = new NumericalJacobianForward_DSCC(f); DMatrixSparseCSC output = alg.declareMatrixMxN(); alg.process(new double[]{2,3,7},output); // one element should be zero assertEquals(5, output.nz_length); assertEquals(3, output.get(0,0), tol); assertEquals(-36, output.get(0,1), tol); assertEquals(0, output.get(0,2), tol); assertEquals(3, output.get(1,0), tol); assertEquals(2, output.get(1,1), tol); assertEquals(1, output.get(1,2), tol); }
public static <D extends DMatrix> FunctionNtoMxN<D> jacobianForwards(FunctionNtoM func, Class<D> type ) { if( type == DMatrixRMaj.class ) { return (FunctionNtoMxN)new NumericalJacobianForward_DDRM(func); } else if( type == DMatrixSparseCSC.class ) { return (FunctionNtoMxN)new NumericalJacobianForward_DSCC(func); } else { throw new RuntimeException("Matrix type unknown/not supported. "+type.getSimpleName()); } }