Baunsgaard commented on a change in pull request #892: Extend Python API (rand, 
lm, matrix multiplication)
URL: https://github.com/apache/systemml/pull/892#discussion_r410381855
 
 

 ##########
 File path: src/main/python/tests/test_matrix_aggregations.py
 ##########
 @@ -84,6 +86,63 @@ def test_var2(self):
     def test_var3(self):
         self.assertTrue(np.allclose(sds.matrix(m1).var(axis=1).compute(), 
m1.var(axis=1, ddof=1).reshape(dim, 1)))
 
+    def test_rand_basic(self):
+        seed = 15
+        shape = (20, 20)
+        min_max = (0, 1)
+        sparsity = 0.2
+
+        m = sds.rand(rows=shape[0], cols=shape[1], pdf="uniform", 
min=min_max[0], max=min_max[1],
+                     seed=seed, sparsity=sparsity).compute()
+
+        self.assertTrue(m.shape == shape)
+        self.assertTrue((m.min() >= min_max[0]) and (m.max() <= min_max[1]))
+
+        # sparsity
+        m_flat = m.flatten('F')
+        count, bins, patches = plt.hist(m_flat)
+
+        non_zero_value_percent = sum(count[1:]) * 100 / count[0]
+        e = 0.05
+        self.assertTrue((non_zero_value_percent >= (sparsity - e) * 100)
+                        and (non_zero_value_percent <= (sparsity + e) * 100))
+        self.assertTrue(sum(count) == (shape[0] * shape[1]))
 
 Review comment:
   Good practice is to only assert one thing in each test.
   This is sometimes hard, to correlate with not duplicating code or repeating 
steps, but possible if some thought is put into it.
   (Low Priority)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to