This is an automated email from the ASF dual-hosted git repository.
estrauss 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 fddedcc2e3 [MINOR] bug fix: infinity loop in rollSparse
fddedcc2e3 is described below
commit fddedcc2e3897d1ad6d861ee483572894df8f402
Author: e-strauss <[email protected]>
AuthorDate: Thu Sep 26 12:21:56 2024 +0200
[MINOR] bug fix: infinity loop in rollSparse
Closes #2124
---
.../sysds/runtime/matrix/data/LibMatrixReorg.java | 26 ++++++++++------------
src/main/python/tests/matrix/test_roll.py | 5 ++++-
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git
a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
index 82defddca8..9c751401cd 100644
--- a/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
+++ b/src/main/java/org/apache/sysds/runtime/matrix/data/LibMatrixReorg.java
@@ -2369,20 +2369,18 @@ public class LibMatrixReorg {
SparseBlock a = in.getSparseBlock();
SparseBlock c = out.getSparseBlock();
- while (copyLen > 0) {
- if (a.isEmpty(inIdx)) continue; // skip empty rows
-
- final int apos = a.pos(inIdx);
- final int alen = a.size(inIdx) + apos;
- final int[] aix = a.indexes(inIdx);
- final double[] avals = a.values(inIdx);
-
- // copy only non-zero elements
- for (int k = apos; k < alen; k++) {
- c.set(outIdx, aix[k], avals[k]);
- }
-
- inIdx++; outIdx++; copyLen--;
+ for (int i = 0; i < copyLen; i++) {
+ if (!a.isEmpty(inIdx)){
+ final int apos = a.pos(inIdx);
+ final int alen = a.size(inIdx) + apos;
+ final int[] aix = a.indexes(inIdx);
+ final double[] avals = a.values(inIdx);
+
+ // copy only non-zero elements
+ for (int k = apos; k < alen; k++)
+ c.set(outIdx, aix[k], avals[k]);
+ }
+ inIdx++; outIdx++;
}
}
diff --git a/src/main/python/tests/matrix/test_roll.py
b/src/main/python/tests/matrix/test_roll.py
index 1355f24082..bd5a0f8616 100644
--- a/src/main/python/tests/matrix/test_roll.py
+++ b/src/main/python/tests/matrix/test_roll.py
@@ -26,14 +26,16 @@ from scipy import sparse
from systemds.context import SystemDSContext
np.random.seed(7)
+random.seed(7)
shape = (random.randrange(1, 25), random.randrange(1, 25))
m = np.random.rand(shape[0], shape[1])
my = np.random.rand(shape[0], 1)
m_empty = np.asarray([[]])
-m_sparse = sparse.random(shape[0], shape[1], density=0.1,
format="csr").toarray()
+m_sparse = sparse.random(shape[0], shape[1], density=0.1, format="csr",
random_state=5).toarray()
m_sparse = np.around(m_sparse, decimals=22)
+
class TestRoll(unittest.TestCase):
sds: SystemDSContext = None
@@ -61,5 +63,6 @@ class TestRoll(unittest.TestCase):
r = self.sds.from_numpy(m_sparse).roll(1).compute()
self.assertTrue(np.allclose(r, np.roll(m_sparse, axis=0, shift=1)))
+
if __name__ == "__main__":
unittest.main(exit=False)