/** * <p> * Checks to see if A and B have the same shape. * </p> * * @param A Matrix * @param B Matrix */ public static void assertShape( SimpleMatrix A , SimpleMatrix B ) { EjmlUnitTests.assertShape(A.getMatrix(), B.getMatrix()); }
public static void assertEquals( RealMatrix32F A , RealMatrix32F B , float tol ) { assertShape(A,B); for( int i = 0; i < A.getNumRows(); i++ ){ for( int j = 0; j < A.getNumCols(); j++ ) { float valA = A.get(i,j); float valB = B.get(i,j); assertTrue(!Float.isNaN(valA) && !Float.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Float.isInfinite(valA) && !Float.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(i,j); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(i,j); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if the transpose of B is equal to A and countable: * </p> * * <p> * |a<sub>ij</sub> - b<sub>ji</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEqualsTrans( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B.numCols,B.numRows); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(j,i); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); } } }
public static void assertEquals( ComplexMatrix64F A , ComplexMatrix64F B , double tol ) { assertShape(A,B); Complex64F a = new Complex64F(); Complex64F b = new Complex64F(); for( int i = 0; i < A.getNumRows(); i++ ){ for( int j = 0; j < A.getNumCols(); j++ ) { A.get(i, j, a); B.get(i, j, b); assertTrue(!Double.isNaN(a.real) && !Double.isNaN(b.real) ,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(!Double.isInfinite(a.real) && !Double.isInfinite(b.real) ,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(Math.abs( a.real-b.real) <= tol,"Real At ("+i+","+j+") A = "+a.real+" B = "+b.real); assertTrue(!Double.isNaN(a.imaginary) && !Double.isNaN(b.imaginary) ,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); assertTrue(!Double.isInfinite(a.imaginary) && !Double.isInfinite(b.imaginary) ,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); assertTrue(Math.abs( a.imaginary-b.imaginary) <= tol,"Img At ("+i+","+j+") A = "+a.imaginary+" B = "+b.imaginary); } } }
/** * <p> * Checks to see if the transpose of B is equal to A and countable: * </p> * * <p> * |a<sub>ij</sub> - b<sub>ji</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEqualsTrans( ReshapeMatrix64F A , ReshapeMatrix64F B , double tol ) { assertShape(A,B.numCols,B.numRows); for( int i = 0; i < A.numRows; i++ ){ for( int j = 0; j < A.numCols; j++ ) { double valA = A.get(i,j); double valB = B.get(j,i); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); } } }
/** * <p> * Checks to see if each element in the matrices are within tolerance of each other and countable: * </p> * * <p> * The two matrices are identical with in tolerance if:<br> * |a<sub>ij</sub> - b<sub>ij</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEquals( RealMatrix64F A , RealMatrix64F 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); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"At ("+i+","+j+") A = "+valA+" B = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"At ("+i+","+j+") A = "+valA+" B = "+valB); } } }
/** * <p> * Checks to see if the transpose of B is equal to A and countable: * </p> * * <p> * |a<sub>ij</sub> - b<sub>ji</sub>| ≤ tol * </p> * * <p> * The test will fail if any element in either matrix is NaN or infinite. * </p> * * @param A Matrix A * @param B Matrix B * @param tol Tolerance */ public static void assertEqualsTrans( RealMatrix64F A , RealMatrix64F B , double tol ) { assertShape(A,B.getNumCols(),B.getNumRows()); 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(j,i); assertTrue(!Double.isNaN(valA) && !Double.isNaN(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(!Double.isInfinite(valA) && !Double.isInfinite(valB) ,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); assertTrue(Math.abs( valA-valB) <= tol,"A("+i+","+j+") = "+valA+") B("+j+","+i+") = "+valB); } } }