public static void assertEquals(String msg,RealMatrix expected,RealMatrix observed,double tolerance){
  Assert.assertNotNull(msg + "\nObserved should not be null",observed);
  if (expected.getColumnDimension() != observed.getColumnDimension() || expected.getRowDimension() != observed.getRowDimension()) {
    StringBuilder messageBuffer=new StringBuilder(msg);
    messageBuffer.append("\nObserved has incorrect dimensions.");
    messageBuffer.append("\nobserved is " + observed.getRowDimension() + " x "+ observed.getColumnDimension());
    messageBuffer.append("\nexpected " + expected.getRowDimension() + " x "+ expected.getColumnDimension());
    Assert.fail(messageBuffer.toString());
  }
  RealMatrix delta=expected.subtract(observed);
  if (delta.getNorm() >= tolerance) {
    StringBuilder messageBuffer=new StringBuilder(msg);
    messageBuffer.append("\nExpected: " + expected);
    messageBuffer.append("\nObserved: " + observed);
    messageBuffer.append("\nexpected - observed: " + delta);
    Assert.fail(messageBuffer.toString());
  }
}

public static void assertEquals ( String msg , RealMatrix expected , RealMatrix observed , double tolerance ) { Assert . assertNotNull ( msg + "\nObserved should not be null" , observed ) ; if ( expected . getColumnDimension ( ) != observed . getColumnDimension ( ) || expected . getRowDimension ( ) != observed . getRowDimension ( ) ) { StringBuilder messageBuffer = new StringBuilder ( msg ) ; messageBuffer . append ( "\nObserved has incorrect dimensions." ) ; messageBuffer . append ( "\nobserved is " + observed . getRowDimension ( ) + " x " + observed . getColumnDimension ( ) ) ; messageBuffer . append ( "\nexpected " + expected . getRowDimension ( ) + " x " + expected . getColumnDimension ( ) ) ; Assert . fail ( messageBuffer . toString ( ) ) ; } RealMatrix delta = expected . subtract ( observed ) ; if ( delta . getNorm ( ) >= tolerance ) { StringBuilder messageBuffer = new StringBuilder ( msg ) ; messageBuffer . append ( "\nExpected: " + expected ) ; messageBuffer . append ( "\nObserved: " + observed ) ; messageBuffer . append ( "\nexpected - observed: " + delta ) ; Assert . fail ( messageBuffer . toString ( ) ) ; } }
verifies that two matrices are close ( 1 - norm )
