public static void rexpand(IndexedMatrixValue data,double max,boolean rows,boolean cast,boolean ignore,long brlen,long bclen,ArrayList<IndexedMatrixValue> outList) throws DMLRuntimeException {
  MatrixIndexes ix=data.getIndexes();
  MatrixBlock in=(MatrixBlock)data.getValue();
  MatrixBlock tmp=rexpand(in,new MatrixBlock(),max,rows,cast,ignore);
  if (rows) {
    for (int rl=0; rl < tmp.getNumRows(); rl+=brlen) {
      MatrixBlock mb=tmp.sliceOperations(rl,(int)(Math.min(rl + brlen,tmp.getNumRows()) - 1),0,tmp.getNumColumns() - 1,new MatrixBlock());
      outList.add(new IndexedMatrixValue(new MatrixIndexes(rl / brlen + 1,ix.getRowIndex()),mb));
    }
  }
 else {
    for (int cl=0; cl < tmp.getNumColumns(); cl+=bclen) {
      MatrixBlock mb=tmp.sliceOperations(0,tmp.getNumRows() - 1,cl,(int)(Math.min(cl + bclen,tmp.getNumColumns()) - 1),new MatrixBlock());
      outList.add(new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex(),cl / bclen + 1),mb));
    }
  }
}

public static void rexpand ( IndexedMatrixValue data , double max , boolean rows , boolean cast , boolean ignore , long brlen , long bclen , ArrayList < IndexedMatrixValue > outList ) throws DMLRuntimeException { MatrixIndexes ix = data . getIndexes ( ) ; MatrixBlock in = ( MatrixBlock ) data . getValue ( ) ; MatrixBlock tmp = rexpand ( in , new MatrixBlock ( ) , max , rows , cast , ignore ) ; if ( rows ) { for ( int rl = 0 ; rl < tmp . getNumRows ( ) ; rl += brlen ) { MatrixBlock mb = tmp . sliceOperations ( rl , ( int ) ( Math . min ( rl + brlen , tmp . getNumRows ( ) ) - 1 ) , 0 , tmp . getNumColumns ( ) - 1 , new MatrixBlock ( ) ) ; outList . add ( new IndexedMatrixValue ( new MatrixIndexes ( rl / brlen + 1 , ix . getRowIndex ( ) ) , mb ) ) ; } } else { for ( int cl = 0 ; cl < tmp . getNumColumns ( ) ; cl += bclen ) { MatrixBlock mb = tmp . sliceOperations ( 0 , tmp . getNumRows ( ) - 1 , cl , ( int ) ( Math . min ( cl + bclen , tmp . getNumColumns ( ) ) - 1 ) , new MatrixBlock ( ) ) ; outList . add ( new IndexedMatrixValue ( new MatrixIndexes ( ix . getRowIndex ( ) , cl / bclen + 1 ) , mb ) ) ; } } }
mr / spark rexpand operation ( single input , multiple outputs incl empty blocks )
