This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new b6adccaf00 [MINOR] Fix python neural network tests (race condition 
random.seed)
b6adccaf00 is described below

commit b6adccaf00fdaf18767b8a02b57263862eeb95c3
Author: Matthias Boehm <[email protected]>
AuthorDate: Mon Sep 23 13:45:42 2024 +0200

    [MINOR] Fix python neural network tests (race condition random.seed)
---
 src/main/python/tests/nn/test_neural_network.py    |   5 +-
 .../component/matrix/libMatrixReorg/RollTest.java  | 130 ++++++++++-----------
 2 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/src/main/python/tests/nn/test_neural_network.py 
b/src/main/python/tests/nn/test_neural_network.py
index 1cf3c5dd33..7ff8548795 100644
--- a/src/main/python/tests/nn/test_neural_network.py
+++ b/src/main/python/tests/nn/test_neural_network.py
@@ -25,16 +25,13 @@ from systemds.context import SystemDSContext
 from tests.nn.neural_network import NeuralNetwork
 from systemds.script_building.script import DMLScript
 
-# Seed for the input matrix
-np.random.seed(42)
-
-
 class TestNeuralNetwork(unittest.TestCase):
     sds: SystemDSContext = None
 
     @classmethod
     def setUpClass(cls):
         cls.sds = SystemDSContext()
+        np.random.seed(42)
         cls.X = np.random.rand(6, 1)
         cls.exp_out = np.array([
             -0.37768756, -0.47785831, -0.95870362,
diff --git 
a/src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java
 
b/src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java
index 17ba8fb068..d2ad83597b 100644
--- 
a/src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java
+++ 
b/src/test/java/org/apache/sysds/test/component/matrix/libMatrixReorg/RollTest.java
@@ -42,82 +42,82 @@ import static org.junit.Assert.fail;
  */
 @RunWith(Parameterized.class)
 public class RollTest {
-    private final int shift;
+       private final int shift;
 
-    // Input matrices
-    private MatrixBlock inputSparse;
-    private MatrixBlock inputDense;
+       // Input matrices
+       private MatrixBlock inputSparse;
+       private MatrixBlock inputDense;
 
-    /**
-     * Constructor for parameterized test cases.
-     *
-     * @param rows     Number of rows in the test matrix.
-     * @param cols     Number of columns in the test matrix.
-     * @param sparsity Sparsity level of the test matrix (0.0 to 1.0).
-     * @param shift    Shift value for the roll operation.
-     */
-    public RollTest(int rows, int cols, double sparsity, int shift) {
-        this.shift = shift;
+       /**
+        * Constructor for parameterized test cases.
+        *
+        * @param rows   Number of rows in the test matrix.
+        * @param cols   Number of columns in the test matrix.
+        * @param sparsity Sparsity level of the test matrix (0.0 to 1.0).
+        * @param shift Shift value for the roll operation.
+        */
+       public RollTest(int rows, int cols, double sparsity, int shift) {
+               this.shift = shift;
 
-        // Generate a MatrixBlock with the given parameters
-        inputSparse = TestUtils.generateTestMatrixBlock(rows, cols, 0, 10, 
sparsity, 1);
-        inputSparse.recomputeNonZeros();
+               // Generate a MatrixBlock with the given parameters
+               inputSparse = TestUtils.generateTestMatrixBlock(rows, cols, 0, 
10, sparsity, 1);
+               inputSparse.recomputeNonZeros();
 
-        inputDense = new MatrixBlock(rows, cols, false); // false indicates 
dense
-        inputDense.copy(inputSparse, false); // Copy without maintaining 
sparsity
-        inputDense.recomputeNonZeros();
-    }
+               inputDense = new MatrixBlock(rows, cols, false); // false 
indicates dense
+               inputDense.copy(inputSparse, false); // Copy without 
maintaining sparsity
+               inputDense.recomputeNonZeros();
+       }
 
-    /**
-     * Defines the parameters for the test cases.
-     * Each Object[] contains {rows, cols, sparsity, shift}.
-     *
-     * @return Collection of test parameters.
-     */
-    @Parameters(name = "Rows: {0}, Cols: {1}, Sparsity: {2}, Shift: {3}")
-    public static Collection<Object[]> data() {
-        List<Object[]> tests = new ArrayList<>();
+       /**
+        * Defines the parameters for the test cases.
+        * Each Object[] contains {rows, cols, sparsity, shift}.
+        *
+        * @return Collection of test parameters.
+        */
+       @Parameters(name = "Rows: {0}, Cols: {1}, Sparsity: {2}, Shift: {3}")
+       public static Collection<Object[]> data() {
+               List<Object[]> tests = new ArrayList<>();
 
-        // Define various sizes, sparsity levels, and shift values
-        int[] rows = {1, 19, 1001, 2017};
-        int[] cols = {1, 17, 1001, 2017};
-        double[] sparsities = {0.01, 0.1, 0.7, 1.0};
-        int[] shifts = {0, 1, 5, 10, 15};
+               // Define various sizes, sparsity levels, and shift values
+               int[] rows = {1, 19, 1001, 2017};
+               int[] cols = {1, 17, 1001, 2017};
+               double[] sparsities = {0.01, 0.1, 0.7, 1.0};
+               int[] shifts = {0, 1, 5, 10, 15};
 
-        // Generate all combinations of sizes, sparsities, and shifts
-        for (int row : rows) {
-            for (int col : cols) {
-                for (double sparsity : sparsities) {
-                    for (int shift : shifts) {
-                        tests.add(new Object[]{row, col, sparsity, shift});
-                    }
-                }
-            }
-        }
-        return tests;
-    }
+               // Generate all combinations of sizes, sparsities, and shifts
+               for (int row : rows) {
+                       for (int col : cols) {
+                               for (double sparsity : sparsities) {
+                                       for (int shift : shifts) {
+                                               tests.add(new Object[]{row, 
col, sparsity, shift});
+                                       }
+                               }
+                       }
+               }
+               return tests;
+       }
 
-    /**
-     * The actual test method that performs the roll operation on both
-     * sparse and dense matrices and compares the results.
-     */
-    @Test
-    public void test() {
-        try {
-            IndexFunction op = new RollIndex(shift);
-            MatrixBlock outputDense = inputDense.reorgOperations(
+       /**
+        * The actual test method that performs the roll operation on both
+        * sparse and dense matrices and compares the results.
+        */
+       @Test
+       public void test() {
+               try {
+                       IndexFunction op = new RollIndex(shift);
+                       MatrixBlock outputDense = inputDense.reorgOperations(
                                        new ReorgOperator(op), new 
MatrixBlock(), 0, 0, 0);
-            MatrixBlock outputSparse = inputSparse.reorgOperations(
+                       MatrixBlock outputSparse = inputSparse.reorgOperations(
                                        new ReorgOperator(op), new 
MatrixBlock(), 0, 0, 0);
-            outputSparse.sparseToDense();
+                       outputSparse.sparseToDense();
 
-            // Compare the dense representations of both outputs
-            TestUtils.compareMatrices(outputSparse, outputDense, 1e-9,
+                       // Compare the dense representations of both outputs
+                       TestUtils.compareMatrices(outputSparse, outputDense, 
1e-9,
                                        "Compare Sparse and Dense Roll 
Results");
 
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception occurred during roll function test: " + 
e.getMessage());
-        }
-    }
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       fail("Exception occurred during roll function test: " + 
e.getMessage());
+               }
+       }
 }

Reply via email to