min-guk commented on code in PR #2103: URL: https://github.com/apache/systemds/pull/2103#discussion_r1749560760
########## src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java: ########## @@ -2243,7 +2271,70 @@ private static void reverseSparse(MatrixBlock in, MatrixBlock out) { if( !a.isEmpty(i) ) c.set(m-1-i, a.get(i), true); } - + + private static void rollDense(MatrixBlock in, MatrixBlock out, int shift) { + final int m = in.rlen; + final int n = in.clen; + + //set basic meta data and allocate output + out.sparse = false; + out.nonZeros = in.nonZeros; + out.allocateDenseBlock(false); + + //copy all rows into target positions + if( n == 1 ) { //column vector + double[] a = in.getDenseBlockValues(); + double[] c = out.getDenseBlockValues(); + + // roll matrix with axis=none + shift %= (m != 0 ? m : 1); + + System.arraycopy(a, 0, c, shift, m - shift); + System.arraycopy(a, m - shift, c, 0, shift); + } else { //general matrix case + DenseBlock a = in.getDenseBlock(); + DenseBlock c = out.getDenseBlock(); + + // roll matrix with axis=0 + shift %= (m != 0 ? m : 1); + + for( int i=0; i< m-shift; i++ ) { + System.arraycopy(a.values(i), a.pos(i), c.values(i + shift), c.pos(i + shift), n); + } + + for( int i=m-shift; i<m; i++ ) { + System.arraycopy(a.values(i), a.pos(i), c.values(i + shift -m), c.pos(i + shift -m), n); + } + } + } + + private static void rollSparse(MatrixBlock in, MatrixBlock out, int shift) { + final int m = in.rlen; + + //set basic meta data and allocate output + out.sparse = true; + out.nonZeros = in.nonZeros; + out.allocateSparseRowsBlock(false); + + //copy all rows into target positions + SparseBlock a = in.getSparseBlock(); + SparseBlock c = out.getSparseBlock(); + + // roll matrix with axis=0 + shift %= (m != 0 ? m : 1); + + for( int i=0; i<m-shift; i++ ) { Review Comment: I appreciate you pointing out the optimization points I hadn’t considered, and I’ve reflected those in the revisions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@systemds.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org