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_r410383402
 
 

 ##########
 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]))
+
+    def test_rand_distribution(self):
+        seed = 15
+        shape = (20, 20)
+        min_max = (0, 1)
+
+        m = sds.rand(rows=shape[0], cols=shape[1], pdf="uniform", 
min=min_max[0], max=min_max[1],
+                     seed=seed).compute()
+
+        m_flat = m.flatten('F')
+
+        dist = best_distribution(m_flat)
+        self.assertTrue(dist == 'uniform')
+
+        m1 = sds.rand(rows=shape[0], cols=shape[1], pdf="normal", 
min=min_max[0], max=min_max[1],
+                     seed=seed).compute()
+
+        m1_flat = m1.flatten('F')
+
+        dist = best_distribution(m1_flat)
+        self.assertTrue(dist == 'norm')
+
+
+def best_distribution(data):
 
 Review comment:
   Define what you mean with best distribution in this 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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to