private static void performBinOuterOperation(MatrixBlock mbLeft,MatrixBlock mbRight,MatrixBlock mbOut,BinaryOperator bOp) throws DMLRuntimeException {
  int rlen=mbLeft.rlen;
  double bv[]=DataConverter.convertToDoubleVector(mbRight);
  if (!mbOut.isAllocated())   mbOut.allocateDenseBlock();
  long lNNZ=0;
  for (int r=0; r < rlen; r++) {
    double value=mbLeft.quickGetValue(r,0);
    int ixPos1=Arrays.binarySearch(bv,value);
    int ixPos2=ixPos1;
    if (ixPos1 >= 0) {
      if (bOp.fn instanceof LessThan || bOp.fn instanceof GreaterThanEquals || bOp.fn instanceof Equals|| bOp.fn instanceof NotEquals)       while (ixPos1 < bv.length && value == bv[ixPos1])       ixPos1++;
      if (bOp.fn instanceof GreaterThan || bOp.fn instanceof LessThanEquals || bOp.fn instanceof Equals|| bOp.fn instanceof NotEquals)       while (ixPos2 > 0 && value == bv[ixPos2 - 1])       --ixPos2;
    }
 else {
      ixPos2=ixPos1=Math.abs(ixPos1) - 1;
    }
    int iStartPos=0, iEndPos=bv.length;
    if (bOp.fn instanceof LessThan)     iStartPos=ixPos1;
 else     if (bOp.fn instanceof LessThanEquals)     iStartPos=ixPos2;
 else     if (bOp.fn instanceof GreaterThan)     iEndPos=ixPos2;
 else     if (bOp.fn instanceof GreaterThanEquals)     iEndPos=ixPos1;
 else     if (bOp.fn instanceof Equals || bOp.fn instanceof NotEquals) {
      iStartPos=ixPos2;
      iEndPos=ixPos1;
    }
    if (iStartPos < iEndPos || bOp.fn instanceof NotEquals) {
      int iOffSet=r * mbRight.getNumColumns();
      if (bOp.fn instanceof LessThan || bOp.fn instanceof GreaterThanEquals || bOp.fn instanceof GreaterThan|| bOp.fn instanceof LessThanEquals|| bOp.fn instanceof Equals) {
        Arrays.fill(mbOut.getDenseBlock(),iOffSet + iStartPos,iOffSet + iEndPos,1.0);
        lNNZ+=(iEndPos - iStartPos);
      }
 else       if (bOp.fn instanceof NotEquals) {
        Arrays.fill(mbOut.getDenseBlock(),iOffSet,iOffSet + iStartPos,1.0);
        Arrays.fill(mbOut.getDenseBlock(),iOffSet + iEndPos,iOffSet + bv.length,1.0);
        lNNZ+=(iStartPos + (bv.length - iEndPos));
      }
    }
  }
  mbOut.setNonZeros(lNNZ);
  mbOut.examSparsity();
}

private static void performBinOuterOperation ( MatrixBlock mbLeft , MatrixBlock mbRight , MatrixBlock mbOut , BinaryOperator bOp ) throws DMLRuntimeException { int rlen = mbLeft . rlen ; double bv [ ] = DataConverter . convertToDoubleVector ( mbRight ) ; if ( ! mbOut . isAllocated ( ) ) mbOut . allocateDenseBlock ( ) ; long lNNZ = 0 ; for ( int r = 0 ; r < rlen ; r ++ ) { double value = mbLeft . quickGetValue ( r , 0 ) ; int ixPos1 = Arrays . binarySearch ( bv , value ) ; int ixPos2 = ixPos1 ; if ( ixPos1 >= 0 ) { if ( bOp . fn instanceof LessThan || bOp . fn instanceof GreaterThanEquals || bOp . fn instanceof Equals || bOp . fn instanceof NotEquals ) while ( ixPos1 < bv . length && value == bv [ ixPos1 ] ) ixPos1 ++ ; if ( bOp . fn instanceof GreaterThan || bOp . fn instanceof LessThanEquals || bOp . fn instanceof Equals || bOp . fn instanceof NotEquals ) while ( ixPos2 > 0 && value == bv [ ixPos2 - 1 ] ) -- ixPos2 ; } else { ixPos2 = ixPos1 = Math . abs ( ixPos1 ) - 1 ; } int iStartPos = 0 , iEndPos = bv . length ; if ( bOp . fn instanceof LessThan ) iStartPos = ixPos1 ; else if ( bOp . fn instanceof LessThanEquals ) iStartPos = ixPos2 ; else if ( bOp . fn instanceof GreaterThan ) iEndPos = ixPos2 ; else if ( bOp . fn instanceof GreaterThanEquals ) iEndPos = ixPos1 ; else if ( bOp . fn instanceof Equals || bOp . fn instanceof NotEquals ) { iStartPos = ixPos2 ; iEndPos = ixPos1 ; } if ( iStartPos < iEndPos || bOp . fn instanceof NotEquals ) { int iOffSet = r * mbRight . getNumColumns ( ) ; if ( bOp . fn instanceof LessThan || bOp . fn instanceof GreaterThanEquals || bOp . fn instanceof GreaterThan || bOp . fn instanceof LessThanEquals || bOp . fn instanceof Equals ) { Arrays . fill ( mbOut . getDenseBlock ( ) , iOffSet + iStartPos , iOffSet + iEndPos , 1.0 ) ; lNNZ += ( iEndPos - iStartPos ) ; } else if ( bOp . fn instanceof NotEquals ) { Arrays . fill ( mbOut . getDenseBlock ( ) , iOffSet , iOffSet + iStartPos , 1.0 ) ; Arrays . fill ( mbOut . getDenseBlock ( ) , iOffSet + iEndPos , iOffSet + bv . length , 1.0 ) ; lNNZ += ( iStartPos + ( bv . length - iEndPos ) ) ; } } } mbOut . setNonZeros ( lNNZ ) ; mbOut . examSparsity ( ) ; }
this will do cell wise operation for < , < = , > , > = , = = and ! = operators .
