def testSparseCreation(self): s = SparseNDArray(self.s1) self.assertEqual(s.ndim, 2) self.assertIsInstance(s, SparseMatrix) self.assertArrayEqual(s.toarray(), self.s1.A) self.assertArrayEqual(s.todense(), self.s1.A) v = SparseNDArray(self.v1, shape=(3,)) self.assertTrue(s.ndim, 1) self.assertIsInstance(v, SparseVector) self.assertEqual(v.shape, (3,)) self.assertArrayEqual(v.todense(), self.v1_data) self.assertArrayEqual(v.toarray(), self.v1_data) self.assertArrayEqual(v, self.v1_data)
def test_sparse_creation(): s = SparseNDArray(s1_data) assert s.ndim == 2 assert isinstance(s, SparseMatrix) assertArrayEqual(s.toarray(), s1_data.A) assertArrayEqual(s.todense(), s1_data.A) v = SparseNDArray(v1, shape=(3, )) assert s.ndim assert isinstance(v, SparseVector) assert v.shape == (3, ) assertArrayEqual(v.todense(), v1_data) assertArrayEqual(v.toarray(), v1_data) assertArrayEqual(v, v1_data)