/** * Assert equals with a relative error */ public static void assertRelativeEquals(DMatrix A , DMatrix B , double tol ) { assertShape(A,B); for( int i = 0; i < A.getNumRows(); i++ ){ for( int j = 0; j < A.getNumCols(); j++ ) { double valA = A.get(i,j); double valB = B.get(i,j); if( (Double.isNaN(valA) != Double.isNaN(valB)) || (Double.isInfinite(valA) != Double.isInfinite(valB))) { throw new AssertionError("At ("+i+","+j+") A = "+valA+" B = "+valB); } double max = Math.max(Math.abs(valA), Math.abs(valB)); double error = Math.abs(valA - valB) / max; if( error > tol ) { System.out.println("------------ A -----------"); A.print(); System.out.println("\n------------ B -----------"); B.print(); throw new AssertionError("At (" + i + "," + j + ") A = " + valA + " B = " + valB + " error = " + error); } } } }
found.print(); System.out.println("-----------------------------"); System.out.println("Numerical");
found.print(); System.out.println("-----------------------------"); System.out.println("Numerical");
found.print(); System.out.println("-----------------------------"); System.out.println("Numerical");
found.print(); System.out.println("-----------------------------"); System.out.println("Numerical");