DMatrixRMaj L = A.createLike();
@Test public void updateHessian() { DMatrixRMaj J = RandomMatrices_DDRM.rectangle(30,6,rand); DMatrixRMaj H = new DMatrixRMaj(1,1); CommonOps_DDRM.multTransA(J,J,H); ((HessianLeastSquares)alg).updateHessian(convert(J)); DMatrixRMaj expected = new DMatrixRMaj(6,1); DMatrixRMaj found = expected.createLike(); alg.extractDiagonals(found); CommonOps_DDRM.extractDiag(H,expected); assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); } }
@Test public void solve() { DMatrixRMaj M = RandomMatrices_DDRM.symmetricPosDef(10,rand); DMatrixRMaj v = RandomMatrices_DDRM.rectangle(10,1,rand); DMatrixRMaj origv = v.copy(); DMatrixRMaj expected = v.createLike(); CommonOps_DDRM.solve(M,v,expected); DMatrixRMaj found = v.createLike(); alg.init(M.numCols); setHessian(alg,M); assertTrue(alg.initializeSolver()); assertTrue(alg.solve(v,found)); // make sure it didn't modify the input assertTrue(MatrixFeatures_DDRM.isIdentical(origv,origv,UtilEjml.TEST_F64)); // check the solution assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); // run it again, if nothing was modified it should produce the same solution assertTrue(alg.initializeSolver()); assertTrue(alg.solve(v,found)); assertTrue(MatrixFeatures_DDRM.isIdentical(expected,found,UtilEjml.TEST_F64)); }