for( int y = 0; y < expected.numRows; y++ ) { for( int x = 0; x < expected.numCols; x++ ) { double diff = Math.abs(found.unsafe_get(y,x)-expected.unsafe_get(y,x)); if( diff > tol ) {
public static void convert(DMatrix input , ZMatrix output ) { if( input.getNumRows() != output.getNumRows() ) throw new IllegalArgumentException("Number of rows do not match"); if( input.getNumCols() != output.getNumCols() ) throw new IllegalArgumentException("Number of columns do not match"); for( int i = 0; i < input.getNumRows(); i++ ) { for( int j = 0; j < input.getNumCols(); j++ ) { output.set(i,j, input.unsafe_get(i,j), 0); } } }
public static void convert(DMatrix input , CMatrix output ) { if( input.getNumRows() != output.getNumRows() ) throw new IllegalArgumentException("Number of rows do not match"); if( input.getNumCols() != output.getNumCols() ) throw new IllegalArgumentException("Number of columns do not match"); for( int i = 0; i < input.getNumRows(); i++ ) { for( int j = 0; j < input.getNumCols(); j++ ) { output.set(i,j, (float)input.unsafe_get(i,j), 0); } } }
for( int y = 0; y < expected.numRows; y++ ) { for( int x = 0; x < expected.numCols; x++ ) { double diff = Math.abs(found.unsafe_get(y,x)-expected.unsafe_get(y,x)); if( diff > tol ) {
/** * <p> * Checks to see if each element in the two matrices are equal: * a<sub>ij</sub> == b<sub>ij</sub> * <p> * * <p> * NOTE: If any of the elements are NaN then false is returned. If two corresponding * elements are both positive or negative infinity then they are equal. * </p> * * @param a A matrix. Not modified. * @param b A matrix. Not modified. * @return true if identical and false otherwise. */ public static boolean isEquals(DMatrix a, DMatrix b ) { if( a.getNumRows() != b.getNumRows() || a.getNumCols() != b.getNumCols() ) return false; final int numRows = a.getNumRows(); final int numCols = a.getNumCols(); for (int row = 0; row < numRows; row++) { for (int col = 0; col < numCols; col++) { if( !(a.unsafe_get(row,col) == b.unsafe_get(row,col))) return false; } } return true; }
/** * Generic, but slow, conversion function. * * @param input Input matrix. * @param output Output matrix. */ public static void convert(DMatrix input , FMatrix output ) { if( input.getNumRows() != output.getNumRows() ) throw new IllegalArgumentException("Number of rows do not match"); if( input.getNumCols() != output.getNumCols() ) throw new IllegalArgumentException("Number of columns do not match"); for( int i = 0; i < input.getNumRows(); i++ ) { for( int j = 0; j < input.getNumCols(); j++ ) { output.unsafe_set(i,j, (float)input.unsafe_get(i,j)); } } }
if( !UtilEjml.isIdentical(a.unsafe_get(row,col),b.unsafe_get(row,col), tol)) return false;
/** * Generic, but slow, conversion function. * * @param input Input matrix. * @param output Output matrix. */ public static void convert(DMatrix input , DMatrix output ) { if( output instanceof ReshapeMatrix ) { ((ReshapeMatrix)output).reshape(input.getNumRows(),input.getNumCols()); } else { if (input.getNumRows() != output.getNumRows()) throw new IllegalArgumentException("Number of rows do not match"); if (input.getNumCols() != output.getNumCols()) throw new IllegalArgumentException("Number of columns do not match"); } for( int i = 0; i < input.getNumRows(); i++ ) { for( int j = 0; j < input.getNumCols(); j++ ) { output.unsafe_set(i,j,input.unsafe_get(i,j)); } } }
public static DMatrixSparseTriplet convert(DMatrix src , DMatrixSparseTriplet dst , double tol ) { if( dst == null ) dst = new DMatrixSparseTriplet(src.getNumRows(), src.getNumCols(), 1); else dst.reshape(src.getNumRows(), src.getNumCols()); for (int row = 0; row < src.getNumRows(); row++) { for (int col = 0; col < src.getNumCols(); col++) { double value = src.unsafe_get(row,col); if( Math.abs(value) > tol ) dst.addItem(row,col,value); } } return dst; }