protected void mergeWithComp(MatrixBlock out,MatrixBlock in,double[][] compare) throws DMLRuntimeException {
  if (in.isInSparseFormat()) {
    int rows=in.getNumRows();
    int cols=in.getNumColumns();
    for (int i=0; i < rows; i++)     for (int j=0; j < cols; j++) {
      double value=in.getValueSparseUnsafe(i,j);
      if ((value != compare[i][j] && !Double.isNaN(value)) || Double.isNaN(value) != Double.isNaN(compare[i][j])) {
        out.quickSetValue(i,j,value);
      }
    }
  }
 else {
    int rows=in.getNumRows();
    int cols=in.getNumColumns();
    for (int i=0; i < rows; i++)     for (int j=0; j < cols; j++) {
      double value=in.getValueDenseUnsafe(i,j);
      if ((value != compare[i][j] && !Double.isNaN(value)) || Double.isNaN(value) != Double.isNaN(compare[i][j])) {
        out.quickSetValue(i,j,value);
      }
    }
  }
}

protected void mergeWithComp ( MatrixBlock out , MatrixBlock in , double [ ] [ ] compare ) throws DMLRuntimeException { if ( in . isInSparseFormat ( ) ) { int rows = in . getNumRows ( ) ; int cols = in . getNumColumns ( ) ; for ( int i = 0 ; i < rows ; i ++ ) for ( int j = 0 ; j < cols ; j ++ ) { double value = in . getValueSparseUnsafe ( i , j ) ; if ( ( value != compare [ i ] [ j ] && ! Double . isNaN ( value ) ) || Double . isNaN ( value ) != Double . isNaN ( compare [ i ] [ j ] ) ) { out . quickSetValue ( i , j , value ) ; } } } else { int rows = in . getNumRows ( ) ; int cols = in . getNumColumns ( ) ; for ( int i = 0 ; i < rows ; i ++ ) for ( int j = 0 ; j < cols ; j ++ ) { double value = in . getValueDenseUnsafe ( i , j ) ; if ( ( value != compare [ i ] [ j ] && ! Double . isNaN ( value ) ) || Double . isNaN ( value ) != Double . isNaN ( compare [ i ] [ j ] ) ) { out . quickSetValue ( i , j , value ) ; } } } }
note : append only not applicable for wiht compare because output must be populated with initial state of matrix - with append , this would result in duplicates .
