You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@systemds.apache.org by "min-guk (via GitHub)" <gi...@apache.org> on 2024/09/06 14:06:53 UTC

[PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

min-guk opened a new pull request, #2103:
URL: https://github.com/apache/systemds/pull/2103

   This PR implements a new roll reorg function in CP and provides test scripts using Python.
   
   1. Implementation of roll function for dense and sparse matrices in CP, along with test code
   - Similar to `rev`, dense column vectors are rolled column-wise, while the rest are rolled row-wise.
   
   2. Support for Python test code and additional test cases
   - Since R does not provide a `roll` function, baseline test scripts were written using Python's numpy `roll` function.
   - Added support for executing the test code in Python. Although there is some overlap with the R script execution code, I avoided modifying or refactoring the existing code to minimize changes.
   - However, due to slight differences in the `mtx` format between R and Python, I made the following modifications to the `mtx` file input/output code:
     - `TestUtils::writeTestMatrix()`: The last number in the mtx header should represent the number of non-zero elements in the matrix, but the previous input test matrix was showing the total number of elements, which caused an error in Python. (https://networkrepository.com/mtx-matrix-market-format.html)
     - `TestUtils::readRMatrixFromFS()`: While R writes the mtx header in 2 lines, Python's scipy writes it in 3 lines, including an extra line with just a %. I modified the code to ignore this blank line.
     
   Please feel free to share any feedback or suggestions regarding the implementation direction.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2367314199

   Thank you @mboehm7. I have proceeded with the rebase as requested. 
   
   Once the PR is merged, I will immediately create a PR for the Spark version as well.
   
   Additionally, I have been studying how to implement it using FED, but I’m finding it a bit difficult to grasp. Could you perhaps provide a brief explanation or suggest some reference materials I could look into?
   
   


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066239


##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */

Review Comment:
   I filled in the blanks in the comment.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "Baunsgaard (via GitHub)" <gi...@apache.org>.
Baunsgaard commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1755426352


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   We currently do not actively assign spark instructions through the python API, because we did not expose the flag for it yet. 
   
   The CP test would be sufficient from python and then internally you can set the function test to test the operation with SP enabled for an input that you know the output for. 
   
   Together this would be sufficient. 



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2367516840

   @mboehm7 I apologize for the inconvenience.
   
   It seems I made a mistake due to my inexperience with Git and GitHub. I will make sure to study more to prevent this from happening again in the future.
   
   Also, thank you for recommending the papers. I will take the time to read and study them.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "e-strauss (via GitHub)" <gi...@apache.org>.
e-strauss commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1751308109


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   @min-guk Hi, I have worked recently on the python api, if I can help you lmk 



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1751522317


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   Thank you both for your kind words. I would like to ask a question to confirm one thing.
   
   Should I implement a Python API to make the roll function, which is implemented in Java, callable from Python, and then write Python test code to compare it with NumPy?
   
   And for such examples, should I refer to https://github.com/apache/systemds/pull/2085 and https://github.com/apache/systemds/pull/2097?



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1749559151


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   Since I’m not familiar with the SystemDS Python API, I’ll study it and proceed as you suggested.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "mboehm7 (via GitHub)" <gi...@apache.org>.
mboehm7 commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2367481824

   OK, this was not a `git --pull rebase orign main` but a merge, which meant I had to rebase and resolve these conflicts myself (but that's fine). Thanks for the contribution @min-guk. 
   
   Here are some papers for the federated backend:
   https://mboehm7.github.io/resources/sigmod2021c_exdra.pdf
   https://mboehm7.github.io/resources/cikm2022.pdf


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2335192546

   Hello Sebastian,
   Thank you for the detailed feedback. I've addressed everything except for runPythonScript(), for which I left a comment above and would appreciate your input.
   
   Additionally, the rollTest Python script works fine locally, but there are environment issues on GitHub Actions. I'll resolve this soon by updating the javaTests.yml.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "Baunsgaard (via GitHub)" <gi...@apache.org>.
Baunsgaard commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1749361900


##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */

Review Comment:
   the formatting is off then, here is a correctly formatted one:
   
   ```java
   	/**
   	 * Apply binary row operation on the right side with one extra row evaluating with zeros.
   	 * 
   	 * @param op         The operation to this dictionary
   	 * @param v          The values to use on the right hand side.
   	 * @param colIndexes The column indexes to consider inside v.
   	 * @return A new dictionary containing the updated values.
   	 */
   	public IDictionary binOpRightAndAppend(BinaryOperator op, double[] v, IColIndex colIndexes);
   ```



##########
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:
   Great, it can be further optimized, by minor tweaks such as:
   
   1. Move the inner parts of the for loop to a separate function to enable JIT (the two loops can call the same function with different shift arguments)
   2. Move the shift addition out of the inner inner loop but to a temporary variable
   
   



##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   This is fine to add, however, i would prefer not to.
   
   We have an---unrelated to your PR---problem with the testsysds docker file that would require a larger fix to make it build properly. Therefore, it will take some time before we would run the update and therefore be able to enable the test to call python from inside the system.
   
   Fundamentally this blocks your PR, because your work relies on Python being installed on the machine you want to test on.
   



##########
.github/workflows/javaTests.yml:
##########
@@ -85,6 +85,7 @@ jobs:
           "**.functions.reorg.**,**.functions.rewrite.**,**.functions.ternary.**",
           "**.functions.transform.**","**.functions.unique.**",
           "**.functions.unary.matrix.**,**.functions.linearization.**,**.functions.jmlc.**"
+          "**.functions.reorg.**,**.functions.rewrite.**,**.functions.ternary.**"

Review Comment:
   this looks like a duplicate of line 85, therefore only double the number of times we run the test.
   
   



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2353383756

   I have added the JavaTest as mentioned earlier. I would appreciate it if you could review it. Thank you!


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1749560397


##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */

Review Comment:
   I reformatted all the code written in this PR and the code in `ReorgCPInstruction.java` that didn’t match the comment format using the IDE.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066075


##########
src/main/java/org/apache/sysds/lops/Transform.java:
##########
@@ -111,7 +111,11 @@ private String getOpcode() {
 			case REV:
 				// Transpose a matrix
 				return "rev";
-			
+
+			case ROLL:
+				// Transpose a matrix

Review Comment:
   I deleted it.



##########
src/main/java/org/apache/sysds/runtime/functionobjects/RollIndex.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.runtime.functionobjects;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.sysds.runtime.matrix.data.MatrixIndexes;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.runtime.meta.DataCharacteristics;
+
+/**
+ * This index function is NOT used for actual sorting but just as a reference
+ * in ReorgOperator in order to identify sort operations.
+ *
+ */
+public class RollIndex extends IndexFunction
+{
+	private static final long serialVersionUID = -8446389232078905200L;
+
+	private final int _shift;
+
+	public RollIndex(int shift) {
+		_shift = shift;
+	}
+
+	public int getShift() {
+		return _shift;
+	}
+
+	@Override
+	public boolean computeDimension(int row, int col, CellIndex retDim)  {
+		retDim.set(row, col);
+		return false;
+	}
+
+	@Override
+	public boolean computeDimension(DataCharacteristics in, DataCharacteristics out) {
+		out.set(in.getRows(), in.getCols(), in.getBlocksize(), in.getNonZeros());
+		return false;
+	}
+
+	@Override
+	public void execute(MatrixIndexes in, MatrixIndexes out) {throw new NotImplementedException();

Review Comment:
   Yes, that function should not be called.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748069092


##########
src/test/java/org/apache/sysds/test/AutomatedTestBase.java:
##########
@@ -1263,16 +1267,98 @@ protected void runRScript(boolean newWay) {
 		}
 	}
 
-	private static String buildOutputStringR(String standardOut, String standardError){
+	/**
+	 * Runs an Python script
+	 */
+	protected void runPythonScript() {

Review Comment:
   I have written the `runPythonScript()` function by following the structure of the existing `runRScript()` function to run Python scripts. However, I would like to ask for clarification on how you would like me to proceed with further modifications.
   
   Would you prefer that I refactor the code to combine the `runRScript()` and `runPythonScript()` functions into a single function (e.g., `runBaselineScript()`), and also consolidate class variables such as `rCmd`?



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2343698310

   I have created a Python API and added Python test code for roll function.
   
   I have rolled back the code related to the MTX file reader/writer, which was separated into another PR, as well as the previously modified Java test code and Docker file script.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2361196629

   I fixed an issue where the roll function was not properly invoked due to an incorrect output file setting and the lack of calling recomputeNonZeros in the Java test.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1749558691


##########
.github/workflows/javaTests.yml:
##########
@@ -85,6 +85,7 @@ jobs:
           "**.functions.reorg.**,**.functions.rewrite.**,**.functions.ternary.**",
           "**.functions.transform.**","**.functions.unique.**",
           "**.functions.unary.matrix.**,**.functions.linearization.**,**.functions.jmlc.**"
+          "**.functions.reorg.**,**.functions.rewrite.**,**.functions.ternary.**"

Review Comment:
   Thanks for letting me know.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066283


##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */
+	private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand shift, String opcode, String istr) {
+		super(CPType.Reorg, op, in, out, opcode, istr);
+		_col = new CPOperand();
+		_desc = new CPOperand();
+		_ixret = new CPOperand();
+		_shift = shift;

Review Comment:
   Modified the code to initialize the unused variable to null.



##########
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:
   Modified the code to copy only non-zero elements.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066315


##########
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 modified the code to copy only non-zero elements.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066283


##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */
+	private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand shift, String opcode, String istr) {
+		super(CPType.Reorg, op, in, out, opcode, istr);
+		_col = new CPOperand();
+		_desc = new CPOperand();
+		_ixret = new CPOperand();
+		_shift = shift;

Review Comment:
   I modified the code to initialize the unused variable to null.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2352752972

   Thank you for continuously providing valuable feedback.
   
   As I'm encountering code coverage for the first time, I have some questions. I've summarized the current situation and requests below as I understand them. 
   
   Could you please confirm if this is correct?
   
   - Situation Summary:
     - Java Test Rejection: 
       - Attempted to compare the Java test of the roll function with NumPy, but it was rejected because we cannot install Python packages in the Docker image.
     - Limitations of the Python Test: 
       - Verified correct implementation on dense and sparse matrices through Python tests comparing with NumPy.
       - However, since it uses the statically built Python API, it is not included in code coverage via Codecov.
     - Code Coverage Issue:
       - To improve code coverage, a Java-based test is necessary.
   
   - Request:
     - Add Java Test:
       - Need to write a Java test for the roll function without using NumPy.
       - The test should generate sparse and dense matrices, apply the roll function to each, and verify that the results are identical.
       - The test code should be located at `src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java` (or `src/test/java/org/apache/sysds/test/functions/reorg/FullReverseTest.java`).


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1759713854


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   Thank you for letting me know. I will verify CP by comparing it with numpy in the Python test, and for SP, I will verify it by comparing the output with CP using the Java test.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "mboehm7 (via GitHub)" <gi...@apache.org>.
mboehm7 closed pull request #2103: [SYSTEMDS-3729] Add roll reorg operations in CP, python script test
URL: https://github.com/apache/systemds/pull/2103


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1752000899


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   Thank you for the clarification and the references. I'll take a look and proceed accordingly.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "e-strauss (via GitHub)" <gi...@apache.org>.
e-strauss commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1751681352


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   jep, in the Python test you can compare to numpy, you can take a look at the test in #2085 . (#2097 would be an example for an operator with two matrices as input, but since you got one matrix as input #2085 fits better), 
   so you can extend the https://github.com/apache/systemds/blob/main/src/main/python/systemds/operator/nodes/matrix.py with your operator.
   You can also take a look at the quantile operator there on how to pass scalars to your function call (for your shift paramerter)



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "e-strauss (via GitHub)" <gi...@apache.org>.
e-strauss commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1751681352


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   jep, in the Python test you can compare to numpy, you can take a look at the test in #2085 . (#2097 would be an example for an operator with two matrices as input, but since you got one matrix sa input #2085 fits better), 
   so you can extend the https://github.com/apache/systemds/blob/main/src/main/python/systemds/operator/nodes/matrix.py with your operator.
   You can also take a look at the quantile operator there on how to pass scalars to your function call (for your shift paramerter)



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "Baunsgaard (via GitHub)" <gi...@apache.org>.
Baunsgaard commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1747308038


##########
src/main/java/org/apache/sysds/lops/Transform.java:
##########
@@ -111,7 +111,11 @@ private String getOpcode() {
 			case REV:
 				// Transpose a matrix
 				return "rev";
-			
+
+			case ROLL:
+				// Transpose a matrix

Review Comment:
   remove comment



##########
src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.reorg;
+
+import org.apache.sysds.api.DMLScript;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.instructions.Instruction;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class FullRollTest extends AutomatedTestBase
+{
+	private final static String TEST_NAME1 = "Roll1";
+	private final static String TEST_NAME2 = "Roll2";
+
+	private final static String TEST_DIR = "functions/reorg/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + FullRollTest.class.getSimpleName() + "/";
+
+	private final static int rows1 = 2017;
+	private final static int cols1 = 1001;
+	private final static double sparsity1 = 0.7;
+	private final static double sparsity2 = 0.1;
+
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"B"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"B"}));
+	}
+
+	@Test
+	public void testRollVectorDenseCP() {
+		runRollTest(TEST_NAME1, false, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollVectorSparseCP() {
+		runRollTest(TEST_NAME2, false, true, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixDenseCP() {
+		runRollTest(TEST_NAME2, true, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixSparseCP() {
+		runRollTest(TEST_NAME2, true, true, ExecType.CP);
+	}
+
+	/**
+	 *
+	 * @param sparseM1
+	 * @param sparseM2
+	 * @param instType
+	 */

Review Comment:
   remove docs if empty



##########
src/main/java/org/apache/sysds/runtime/functionobjects/RollIndex.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.runtime.functionobjects;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.sysds.runtime.matrix.data.MatrixIndexes;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.runtime.meta.DataCharacteristics;
+
+/**
+ * This index function is NOT used for actual sorting but just as a reference
+ * in ReorgOperator in order to identify sort operations.
+ *
+ */
+public class RollIndex extends IndexFunction
+{
+	private static final long serialVersionUID = -8446389232078905200L;
+
+	private final int _shift;
+
+	public RollIndex(int shift) {
+		_shift = shift;
+	}
+
+	public int getShift() {
+		return _shift;
+	}
+
+	@Override
+	public boolean computeDimension(int row, int col, CellIndex retDim)  {
+		retDim.set(row, col);
+		return false;
+	}
+
+	@Override
+	public boolean computeDimension(DataCharacteristics in, DataCharacteristics out) {
+		out.set(in.getRows(), in.getCols(), in.getBlocksize(), in.getNonZeros());
+		return false;
+	}
+
+	@Override
+	public void execute(MatrixIndexes in, MatrixIndexes out) {throw new NotImplementedException();

Review Comment:
   missing, but i guess it is intentionally.



##########
src/test/java/org/apache/sysds/test/AutomatedTestBase.java:
##########
@@ -1263,16 +1267,98 @@ protected void runRScript(boolean newWay) {
 		}
 	}
 
-	private static String buildOutputStringR(String standardOut, String standardError){
+	/**
+	 * Runs an Python script
+	 */
+	protected void runPythonScript() {

Review Comment:
   this method looks a bit funky, it could probably be cleaned up a bit.



##########
src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.reorg;
+
+import org.apache.sysds.api.DMLScript;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.instructions.Instruction;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class FullRollTest extends AutomatedTestBase
+{
+	private final static String TEST_NAME1 = "Roll1";
+	private final static String TEST_NAME2 = "Roll2";
+
+	private final static String TEST_DIR = "functions/reorg/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + FullRollTest.class.getSimpleName() + "/";
+
+	private final static int rows1 = 2017;
+	private final static int cols1 = 1001;
+	private final static double sparsity1 = 0.7;
+	private final static double sparsity2 = 0.1;
+
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"B"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"B"}));
+	}
+
+	@Test
+	public void testRollVectorDenseCP() {
+		runRollTest(TEST_NAME1, false, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollVectorSparseCP() {
+		runRollTest(TEST_NAME2, false, true, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixDenseCP() {
+		runRollTest(TEST_NAME2, true, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixSparseCP() {
+		runRollTest(TEST_NAME2, true, true, ExecType.CP);
+	}
+
+	/**
+	 *
+	 * @param sparseM1
+	 * @param sparseM2
+	 * @param instType
+	 */
+	private void runRollTest(String testname, boolean matrix, boolean sparse, ExecType instType)
+	{
+		//rtplatform for MR
+		ExecMode platformOld = rtplatform;
+		switch( instType ){
+			case SPARK: rtplatform = ExecMode.SPARK; break;
+			default: rtplatform = ExecMode.HYBRID; break;
+		}
+		boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
+		if( rtplatform == ExecMode.SPARK )
+			DMLScript.USE_LOCAL_SPARK_CONFIG = true;
+
+		String TEST_NAME = testname;
+
+		try
+		{
+			int cols = matrix ? cols1 : 1;
+			double sparsity = sparse ? sparsity2 : sparsity1;
+			getAndLoadTestConfiguration(TEST_NAME);
+
+			/* This is for running the junit test the new way, i.e., construct the arguments directly */
+			String HOME = SCRIPT_DIR + TEST_DIR;
+			fullDMLScriptName = HOME + TEST_NAME + ".dml";
+			programArgs = new String[]{"-stats","-explain","-args", input("A"), output("B") };
+
+			fullPythonScriptName = HOME + TEST_NAME + ".py";
+			pythonCmd = new String[] { "python3", fullPythonScriptName, inputDir(), expectedDir() };
+
+			//generate actual dataset
+			double[][] A = getRandomMatrix(rows1, cols, -1, 1, sparsity, 7);
+			writeInputMatrixWithMTD("A", A, true);
+
+			runTest(true, false, null, -1);
+			runPythonScript();
+
+			//compare matrices
+			HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir("B");
+			HashMap<CellIndex, Double> pythonfile  = readRMatrixFromExpectedDir("B.mtx");
+
+			TestUtils.compareMatrices(dmlfile, pythonfile, 0, "Stat-DML", "Stat-R");
+
+			//check generated opcode
+			if( instType == ExecType.CP )
+				Assert.assertTrue("Missing opcode: roll", Statistics.getCPHeavyHitterOpCodes().contains("roll"));
+			else if ( instType == ExecType.SPARK )
+				Assert.assertTrue("Missing opcode: "+Instruction.SP_INST_PREFIX+"roll", Statistics.getCPHeavyHitterOpCodes().contains(Instruction.SP_INST_PREFIX+"roll"));
+		}
+		finally
+		{
+			//reset flags
+			rtplatform = platformOld;
+			DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+		}
+	}
+}

Review Comment:
   please format the file for consistantcy, I can see it is not formatted because it for instance is missing a newline in the end.



##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */
+	private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand shift, String opcode, String istr) {
+		super(CPType.Reorg, op, in, out, opcode, istr);
+		_col = new CPOperand();
+		_desc = new CPOperand();
+		_ixret = new CPOperand();
+		_shift = shift;

Review Comment:
   we could consider reusing some of the other ones, 
   however, If you want to keep the structure like this, then assign the other CPOperands to null if you do not use them instead of assigning new object that we will not use.



##########
src/main/java/org/apache/sysds/runtime/instructions/cp/ReorgCPInstruction.java:
##########
@@ -83,6 +85,31 @@ private ReorgCPInstruction(Operator op, CPOperand in, CPOperand out, CPOperand c
 		_col = col;
 		_desc = desc;
 		_ixret = ixret;
+		_shift = new CPOperand();
+	}
+
+	/**
+	 * for opcode roll
+	 *
+	 * @param op
+	 *            operator
+	 * @param in
+	 *            cp input operand
+	 * @param shift
+	 *            ?
+	 * @param out
+	 *            cp output operand
+	 * @param opcode
+	 *            the opcode
+	 * @param istr
+	 *            ?
+	 */

Review Comment:
   remove docs if they are empty like this.



##########
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:
   you can improve the sparse implementation by processing only non zero elements:
   Use something like:
   
   (assuming i is a given row.)
   ```java
   if(a.isEmpty(i))
   	continue;
   final int apos = sb.pos(i);
   final int alen = sb.size(i) + apos;
   final int[] aix = sb.indexes(i);
   final double[] avals = sb.values(i);
   for(int k = apos; k < alen; k++)
       ...
   ```



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2335798499

   The Java tests pass locally but continue to fail in GitHub Actions because the `numpy` package was not installed in the test Docker image.
   
   I have updated the `testsysds.Dockerfile`, so I would appreciate it if you could execute the `Docker Test Image Update` in GitHub Actions after the Pull Request is merged.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066446


##########
src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.reorg;
+
+import org.apache.sysds.api.DMLScript;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.instructions.Instruction;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class FullRollTest extends AutomatedTestBase
+{
+	private final static String TEST_NAME1 = "Roll1";
+	private final static String TEST_NAME2 = "Roll2";
+
+	private final static String TEST_DIR = "functions/reorg/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + FullRollTest.class.getSimpleName() + "/";
+
+	private final static int rows1 = 2017;
+	private final static int cols1 = 1001;
+	private final static double sparsity1 = 0.7;
+	private final static double sparsity2 = 0.1;
+
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"B"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"B"}));
+	}
+
+	@Test
+	public void testRollVectorDenseCP() {
+		runRollTest(TEST_NAME1, false, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollVectorSparseCP() {
+		runRollTest(TEST_NAME2, false, true, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixDenseCP() {
+		runRollTest(TEST_NAME2, true, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixSparseCP() {
+		runRollTest(TEST_NAME2, true, true, ExecType.CP);
+	}
+
+	/**
+	 *
+	 * @param sparseM1
+	 * @param sparseM2
+	 * @param instType
+	 */
+	private void runRollTest(String testname, boolean matrix, boolean sparse, ExecType instType)
+	{
+		//rtplatform for MR
+		ExecMode platformOld = rtplatform;
+		switch( instType ){
+			case SPARK: rtplatform = ExecMode.SPARK; break;
+			default: rtplatform = ExecMode.HYBRID; break;
+		}
+		boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
+		if( rtplatform == ExecMode.SPARK )
+			DMLScript.USE_LOCAL_SPARK_CONFIG = true;
+
+		String TEST_NAME = testname;
+
+		try
+		{
+			int cols = matrix ? cols1 : 1;
+			double sparsity = sparse ? sparsity2 : sparsity1;
+			getAndLoadTestConfiguration(TEST_NAME);
+
+			/* This is for running the junit test the new way, i.e., construct the arguments directly */
+			String HOME = SCRIPT_DIR + TEST_DIR;
+			fullDMLScriptName = HOME + TEST_NAME + ".dml";
+			programArgs = new String[]{"-stats","-explain","-args", input("A"), output("B") };
+
+			fullPythonScriptName = HOME + TEST_NAME + ".py";
+			pythonCmd = new String[] { "python3", fullPythonScriptName, inputDir(), expectedDir() };
+
+			//generate actual dataset
+			double[][] A = getRandomMatrix(rows1, cols, -1, 1, sparsity, 7);
+			writeInputMatrixWithMTD("A", A, true);
+
+			runTest(true, false, null, -1);
+			runPythonScript();
+
+			//compare matrices
+			HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir("B");
+			HashMap<CellIndex, Double> pythonfile  = readRMatrixFromExpectedDir("B.mtx");
+
+			TestUtils.compareMatrices(dmlfile, pythonfile, 0, "Stat-DML", "Stat-R");
+
+			//check generated opcode
+			if( instType == ExecType.CP )
+				Assert.assertTrue("Missing opcode: roll", Statistics.getCPHeavyHitterOpCodes().contains("roll"));
+			else if ( instType == ExecType.SPARK )
+				Assert.assertTrue("Missing opcode: "+Instruction.SP_INST_PREFIX+"roll", Statistics.getCPHeavyHitterOpCodes().contains(Instruction.SP_INST_PREFIX+"roll"));
+		}
+		finally
+		{
+			//reset flags
+			rtplatform = platformOld;
+			DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+		}
+	}
+}

Review Comment:
   I added a newline.



##########
src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.reorg;
+
+import org.apache.sysds.api.DMLScript;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.instructions.Instruction;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class FullRollTest extends AutomatedTestBase
+{
+	private final static String TEST_NAME1 = "Roll1";
+	private final static String TEST_NAME2 = "Roll2";
+
+	private final static String TEST_DIR = "functions/reorg/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + FullRollTest.class.getSimpleName() + "/";
+
+	private final static int rows1 = 2017;
+	private final static int cols1 = 1001;
+	private final static double sparsity1 = 0.7;
+	private final static double sparsity2 = 0.1;
+
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"B"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"B"}));
+	}
+
+	@Test
+	public void testRollVectorDenseCP() {
+		runRollTest(TEST_NAME1, false, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollVectorSparseCP() {
+		runRollTest(TEST_NAME2, false, true, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixDenseCP() {
+		runRollTest(TEST_NAME2, true, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixSparseCP() {
+		runRollTest(TEST_NAME2, true, true, ExecType.CP);
+	}
+
+	/**
+	 *
+	 * @param sparseM1
+	 * @param sparseM2
+	 * @param instType
+	 */

Review Comment:
   I deleted the comment.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1748066375


##########
src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.reorg;
+
+import org.apache.sysds.api.DMLScript;
+import org.apache.sysds.common.Types.ExecMode;
+import org.apache.sysds.common.Types.ExecType;
+import org.apache.sysds.runtime.instructions.Instruction;
+import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.apache.sysds.utils.Statistics;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+
+public class FullRollTest extends AutomatedTestBase
+{
+	private final static String TEST_NAME1 = "Roll1";
+	private final static String TEST_NAME2 = "Roll2";
+
+	private final static String TEST_DIR = "functions/reorg/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + FullRollTest.class.getSimpleName() + "/";
+
+	private final static int rows1 = 2017;
+	private final static int cols1 = 1001;
+	private final static double sparsity1 = 0.7;
+	private final static double sparsity2 = 0.1;
+
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"B"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"B"}));
+	}
+
+	@Test
+	public void testRollVectorDenseCP() {
+		runRollTest(TEST_NAME1, false, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollVectorSparseCP() {
+		runRollTest(TEST_NAME2, false, true, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixDenseCP() {
+		runRollTest(TEST_NAME2, true, false, ExecType.CP);
+	}
+
+	@Test
+	public void testRollMatrixSparseCP() {
+		runRollTest(TEST_NAME2, true, true, ExecType.CP);
+	}
+
+	/**
+	 *
+	 * @param sparseM1
+	 * @param sparseM2
+	 * @param instType
+	 */

Review Comment:
   Deleted the comment.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on code in PR #2103:
URL: https://github.com/apache/systemds/pull/2103#discussion_r1754872514


##########
docker/testsysds.Dockerfile:
##########
@@ -78,6 +78,13 @@ RUN apt-get install -y --no-install-recommends \
 	&& rm -rf installDependencies.R \
 	&& rm -rf /var/lib/apt/lists/*
 
+RUN apt-get install -y --no-install-recommends \
+	python3 python3-pip && \
+	apt-get clean && \
+	python3 -m pip install --upgrade pip && \
+	pip3 install numpy scipy && \
+    echo "Python3 installed"

Review Comment:
   @e-strauss Thanks to your help, I was able to successfully implement and complete the Python API.
   
   If possible, could you share an example of a Python API that calls a Spark function, along with its corresponding test code? It would be really helpful to me.



-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "min-guk (via GitHub)" <gi...@apache.org>.
min-guk commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2350947411

   Previously, the roll function incorrectly handled sparse matrix indices, leading to a test failure, but I have resolved the issue.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2348582419

   ## [Codecov](https://app.codecov.io/gh/apache/systemds/pull/2103?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `6.30631%` with `104 lines` in your changes missing coverage. Please review.
   > Project coverage is 70.58%. Comparing base [(`7daa590`)](https://app.codecov.io/gh/apache/systemds/commit/7daa5908e5c771c35445dc7f434b75dcccc077ab?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`ec6b736`)](https://app.codecov.io/gh/apache/systemds/commit/ec6b736be0f23c9fbc10b04596f0346f1feba64c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 20 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/systemds/pull/2103?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...ache/sysds/runtime/matrix/data/LibMatrixReorg.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fruntime%2Fmatrix%2Fdata%2FLibMatrixReorg.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3J1bnRpbWUvbWF0cml4L2RhdGEvTGliTWF0cml4UmVvcmcuamF2YQ==) | 1.85% | [52 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...ds/runtime/instructions/cp/ReorgCPInstruction.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fruntime%2Finstructions%2Fcp%2FReorgCPInstruction.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3J1bnRpbWUvaW5zdHJ1Y3Rpb25zL2NwL1Jlb3JnQ1BJbnN0cnVjdGlvbi5qYXZh) | 12.50% | [12 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [src/main/java/org/apache/sysds/hops/ReorgOp.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fhops%2FReorgOp.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL2hvcHMvUmVvcmdPcC5qYXZh) | 9.09% | [10 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...pache/sysds/runtime/functionobjects/RollIndex.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fruntime%2Ffunctionobjects%2FRollIndex.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3J1bnRpbWUvZnVuY3Rpb25vYmplY3RzL1JvbGxJbmRleC5qYXZh) | 0.00% | [10 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...apache/sysds/parser/BuiltinFunctionExpression.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fparser%2FBuiltinFunctionExpression.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3BhcnNlci9CdWlsdGluRnVuY3Rpb25FeHByZXNzaW9uLmphdmE=) | 0.00% | [8 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...in/java/org/apache/sysds/parser/DMLTranslator.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fparser%2FDMLTranslator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3BhcnNlci9ETUxUcmFuc2xhdG9yLmphdmE=) | 0.00% | [6 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [src/main/java/org/apache/sysds/lops/Transform.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Flops%2FTransform.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL2xvcHMvVHJhbnNmb3JtLmphdmE=) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../apache/sysds/runtime/matrix/data/MatrixBlock.java](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fsysds%2Fruntime%2Fmatrix%2Fdata%2FMatrixBlock.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3N5c2RzL3J1bnRpbWUvbWF0cml4L2RhdGEvTWF0cml4QmxvY2suamF2YQ==) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/systemds/pull/2103?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #2103      +/-   ##
   ============================================
   + Coverage     70.50%   70.58%   +0.07%     
   - Complexity    42071    42211     +140     
   ============================================
     Files          1441     1442       +1     
     Lines        162297   162525     +228     
     Branches      31626    31672      +46     
   ============================================
   + Hits         114425   114714     +289     
   + Misses        38832    38823       -9     
   + Partials       9040     8988      -52     
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/systemds/pull/2103?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "Baunsgaard (via GitHub)" <gi...@apache.org>.
Baunsgaard commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2352435362

   LGTM the implementation looks solid. 
   However, we are missing code coverage in the test. The python test is great to ensure that we give the same results as numpy, however out code coverage only include internal java tests.
   
   I would suggest to add a component test that just covers the call to LibMatrixReorg,
   where you test sparse inputs and dense inputs.
   It can be inspired by: src/test/java/org/apache/sysds/test/component/matrix/binary/BinaryOpTest.java
   
   


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "Baunsgaard (via GitHub)" <gi...@apache.org>.
Baunsgaard commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2352797328

   > Thank you for continuously providing valuable feedback.
   > 
   > As I'm encountering code coverage for the first time, I have some questions. I've summarized the current situation and requests below as I understand them.
   > 
   > Could you please confirm if this is correct?
   > 
   >     * Situation Summary:
   >       
   >       * Java Test Rejection:
   >         
   >         * Attempted to compare the Java test of the roll function with NumPy, but it was rejected because we cannot install Python packages in the Docker image.
   >       * Limitations of the Python Test:
   >         
   >         * Verified correct implementation on dense and sparse matrices through Python tests comparing with NumPy.
   >         * However, since it uses the statically built Python API, it is not included in code coverage via Codecov.
   >       * Code Coverage Issue:
   >         
   >         * To improve code coverage, a Java-based test is necessary.
   > 
   >     * Request:
   >       
   >       * Add Java Test:
   >         
   >         * Need to write a Java test for the roll function without using NumPy.
   >         * The test should generate sparse and dense matrices, apply the roll function to each, and verify that the results are identical.
   >         * The test code should be located at `src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java` (or `src/test/java/org/apache/sysds/test/functions/reorg/FullRollTest.java`).
   
   Yes this sounds correct.
   
   Therefore:
   
   1. keep the python tests that you made, because they ensure compatibility with numpy,
   2. make internal tests (component tests) that, as you say, verify the roll function without using numpy and verify the results correctly.
   
   
   Thanks.
   


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [SYSTEMDS-3729] Add roll reorg operations in CP, python script test [systemds]

Posted by "mboehm7 (via GitHub)" <gi...@apache.org>.
mboehm7 commented on PR #2103:
URL: https://github.com/apache/systemds/pull/2103#issuecomment-2366844757

   LGTM - @min-guk could you please rebase this PR (there are quite a number of merge conflicts over these many commits) and then I would merge it in.


-- 
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-unsubscribe@systemds.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org