public static ArrayList<IndexedMatrixValue> reshape(IndexedMatrixValue in,long rows1,long cols1,int brlen1,int bclen1,ArrayList<IndexedMatrixValue> out,long rows2,long cols2,int brlen2,int bclen2,boolean rowwise) throws DMLRuntimeException {
  MatrixIndexes ixIn=in.getIndexes();
  MatrixBlock mbIn=(MatrixBlock)in.getValue();
  Collection<MatrixIndexes> rix=computeAllResultBlockIndexes(ixIn,rows1,cols1,brlen1,bclen1,rows2,cols2,brlen2,bclen2,rowwise);
  HashMap<MatrixIndexes,MatrixBlock> rblk=createAllResultBlocks(rix,mbIn.nonZeros,rows1,cols1,brlen1,bclen1,rows2,cols2,brlen2,bclen2,rowwise,out);
  long row_offset=(ixIn.getRowIndex() - 1) * brlen1;
  long col_offset=(ixIn.getColumnIndex() - 1) * bclen1;
  if (mbIn.sparse)   reshapeSparse(mbIn,row_offset,col_offset,rblk,rows1,cols1,rows2,cols2,brlen2,bclen2,rowwise);
 else   reshapeDense(mbIn,row_offset,col_offset,rblk,rows1,cols1,rows2,cols2,brlen2,bclen2,rowwise);
  out=new ArrayList<IndexedMatrixValue>();
  for (  Entry<MatrixIndexes,MatrixBlock> e : rblk.entrySet())   out.add(new IndexedMatrixValue(e.getKey(),e.getValue()));
  return out;
}

public static ArrayList < IndexedMatrixValue > reshape ( IndexedMatrixValue in , long rows1 , long cols1 , int brlen1 , int bclen1 , ArrayList < IndexedMatrixValue > out , long rows2 , long cols2 , int brlen2 , int bclen2 , boolean rowwise ) throws DMLRuntimeException { MatrixIndexes ixIn = in . getIndexes ( ) ; MatrixBlock mbIn = ( MatrixBlock ) in . getValue ( ) ; Collection < MatrixIndexes > rix = computeAllResultBlockIndexes ( ixIn , rows1 , cols1 , brlen1 , bclen1 , rows2 , cols2 , brlen2 , bclen2 , rowwise ) ; HashMap < MatrixIndexes , MatrixBlock > rblk = createAllResultBlocks ( rix , mbIn . nonZeros , rows1 , cols1 , brlen1 , bclen1 , rows2 , cols2 , brlen2 , bclen2 , rowwise , out ) ; long row_offset = ( ixIn . getRowIndex ( ) - 1 ) * brlen1 ; long col_offset = ( ixIn . getColumnIndex ( ) - 1 ) * bclen1 ; if ( mbIn . sparse ) reshapeSparse ( mbIn , row_offset , col_offset , rblk , rows1 , cols1 , rows2 , cols2 , brlen2 , bclen2 , rowwise ) ; else reshapeDense ( mbIn , row_offset , col_offset , rblk , rows1 , cols1 , rows2 , cols2 , brlen2 , bclen2 , rowwise ) ; out = new ArrayList < IndexedMatrixValue > ( ) ; for ( Entry < MatrixIndexes , MatrixBlock > e : rblk . entrySet ( ) ) out . add ( new IndexedMatrixValue ( e . getKey ( ) , e . getValue ( ) ) ) ; return out ; }
mr reshape interface - for reshape we cannot view blocks independently , and hence , there are different cp and mr interfaces .
