diff --git a/CHANGELOG.md b/CHANGELOG.md index f58d729..fb25d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Version 0.9.4 + +* Replace deprecated scipy `spmatrix.A` calls with `spmatrix.todense()` + ### Version 0.9.3 * Directly expose service functions `mkl_get_max_threads`, `mkl_set_num_threads`, diff --git a/README.md b/README.md index b72cd89..354e96a 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ If A is sparse, it will return a sparse matrix unless `dense=True` is set. It will also convert a CSC matrix to a CSR matrix if necessary. #### Service Functions +Several service functions are available and can be imported from the base `sparse_dot_mkl` package. + `mkl_get_max_threads()` returns the maximum number of threads used by MKL as an integer `mkl_set_num_threads(n_threads)` will set a maximum number of threads hint for MKL diff --git a/setup.py b/setup.py index 4916c98..ff4a557 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages DISTNAME = 'sparse_dot_mkl' -VERSION = '0.9.3' +VERSION = '0.9.4' DESCRIPTION = "Intel MKL wrapper for sparse matrix multiplication" MAINTAINER = 'Chris Jackson' MAINTAINER_EMAIL = 'cj59@nyu.edu' diff --git a/sparse_dot_mkl/__init__.py b/sparse_dot_mkl/__init__.py index 88fc63a..dbff706 100644 --- a/sparse_dot_mkl/__init__.py +++ b/sparse_dot_mkl/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.9.3' +__version__ = '0.9.4' from sparse_dot_mkl.sparse_dot import ( diff --git a/sparse_dot_mkl/_mkl_interface/__init__.py b/sparse_dot_mkl/_mkl_interface/__init__.py index a8c075f..755ad97 100644 --- a/sparse_dot_mkl/_mkl_interface/__init__.py +++ b/sparse_dot_mkl/_mkl_interface/__init__.py @@ -69,7 +69,13 @@ def _validate_dtype(): test_array = _spsparse.random( 5, 5, density=0.5, format="csc", dtype=_np.float32, random_state=50 ) - test_comparison = test_array.A + test_comparison = test_array.todense() + + # Make sure this is an array and not np.matrix + try: + test_comparison = test_comparison.A + except AttributeError: + pass csc_ref, precision_flag, _ = _create_mkl_sparse(test_array) @@ -84,7 +90,7 @@ def _validate_dtype(): output_type='csr_matrix' ) - if not _np.allclose(test_comparison, final_array.A): + if not _np.allclose(test_comparison, final_array.todense()): raise ValueError("Match failed after matrix conversion") _destroy_mkl_handle(csr_ref) finally: diff --git a/sparse_dot_mkl/tests/test_dense_dense.py b/sparse_dot_mkl/tests/test_dense_dense.py index dd2c3b2..243daec 100644 --- a/sparse_dot_mkl/tests/test_dense_dense.py +++ b/sparse_dot_mkl/tests/test_dense_dense.py @@ -14,7 +14,7 @@ class TestDenseDenseMultiplication(unittest.TestCase): @classmethod def setUpClass(cls): - cls.MATRIX_1, cls.MATRIX_2 = MATRIX_1.copy().A, MATRIX_2.copy().A + cls.MATRIX_1, cls.MATRIX_2 = MATRIX_1.copy().todense(), MATRIX_2.copy().todense() def setUp(self): self.mat1 = self.MATRIX_1.copy() @@ -123,8 +123,8 @@ class _ComplexMixin: @classmethod def setUpClass(cls): cls.MATRIX_1, cls.MATRIX_2 = make_matrixes(200, 100, 300, 0.05, dtype=np.cdouble) - cls.MATRIX_1 = cls.MATRIX_1.A - cls.MATRIX_2 = cls.MATRIX_2.A + cls.MATRIX_1 = cls.MATRIX_1.todense() + cls.MATRIX_2 = cls.MATRIX_2.todense() def test_inherits(self): diff --git a/sparse_dot_mkl/tests/test_mkl.py b/sparse_dot_mkl/tests/test_mkl.py index 737ed6f..581ccc6 100644 --- a/sparse_dot_mkl/tests/test_mkl.py +++ b/sparse_dot_mkl/tests/test_mkl.py @@ -56,13 +56,13 @@ def np_almost_equal(a, b, **kwargs): a = a.toarray() if isinstance(a, np.matrix): - a = a.A + a = a.todense() if _spsparse.issparse(b): b = b.toarray() if isinstance(b, np.matrix): - b = b.A + b = b.todense() return npt.assert_array_almost_equal(a, b, **kwargs) @@ -73,8 +73,8 @@ def setUp(self): self.mat1 = MATRIX_1_EMPTY.copy() self.mat2 = MATRIX_2.copy() - self.mat1_d = np.asarray(MATRIX_1_EMPTY.A, order="C") - self.mat2_d = np.asarray(MATRIX_2.A, order="C") + self.mat1_d = np.asarray(MATRIX_1_EMPTY.todense(), order="C") + self.mat2_d = np.asarray(MATRIX_2.todense(), order="C") self.mat1_zero = np.zeros((0, 300)) @@ -82,7 +82,7 @@ def test_sparse_sparse(self): mat3 = dot_product_mkl(self.mat1, self.mat2) mat3_np = np.dot(self.mat1_d, self.mat2_d) - npt.assert_array_almost_equal(mat3_np, mat3.A) + npt.assert_array_almost_equal(mat3_np, mat3.todense()) def test_sparse_dense(self): mat3 = dot_product_mkl(self.mat1, self.mat2_d) @@ -141,8 +141,8 @@ def test_empty_handle(self): _destroy_mkl_handle(mkl_handle_empty) def test_3d_matrixes(self): - d1 = self.mat1.A.reshape(200, 300, 1) - d2 = self.mat2.A.reshape(300, 100, 1) + d1 = self.mat1.todense().A.reshape(200, 300, 1) + d2 = self.mat2.todense().A.reshape(300, 100, 1) with self.assertRaises(ValueError): dot_product_mkl(d1, d2) @@ -199,7 +199,7 @@ def is_sparse_identical_internal(sparse_1, sparse_2): npt.assert_array_equal(sparse_1.indices, sparse_2.indices) def is_sparse_identical_A(self, sparse_1, sparse_2): - npt.assert_array_almost_equal(sparse_1.A, sparse_2.A) + npt.assert_array_almost_equal(sparse_1.todense(), sparse_2.todense()) def test_create_export(self): mat1 = self.csc_constructor(self.mat1).copy() diff --git a/sparse_dot_mkl/tests/test_qr_solver.py b/sparse_dot_mkl/tests/test_qr_solver.py index 1acdafd..2d36350 100644 --- a/sparse_dot_mkl/tests/test_qr_solver.py +++ b/sparse_dot_mkl/tests/test_qr_solver.py @@ -12,7 +12,7 @@ class TestSparseSolver(unittest.TestCase): def setUpClass(cls): cls.A = _spsparse.diags((MATRIX_1.data[0:100].copy()), format="csr") cls.B = MATRIX_1.data[0:100].copy().reshape(-1, 1) - cls.X = np.linalg.lstsq(cls.A.A, cls.B, rcond=None)[0] + cls.X = np.linalg.lstsq(cls.A.todense(), cls.B, rcond=None)[0] def setUp(self): self.mat1 = self.A.copy() @@ -25,15 +25,26 @@ def test_sparse_solver(self): npt.assert_array_almost_equal(self.mat3, mat3) def test_sparse_solver_single(self): - mat3 = sparse_qr_solve_mkl(self.mat1.astype(np.float32), self.mat2.astype(np.float32)) + mat3 = sparse_qr_solve_mkl( + self.mat1.astype(np.float32), + self.mat2.astype(np.float32) + ) npt.assert_array_almost_equal(self.mat3, mat3) def test_sparse_solver_cast_B(self): - mat3 = sparse_qr_solve_mkl(self.mat1, self.mat2.astype(np.float32), cast=True) + mat3 = sparse_qr_solve_mkl( + self.mat1, + self.mat2.astype(np.float32), + cast=True + ) npt.assert_array_almost_equal(self.mat3, mat3) def test_sparse_solver_cast_A(self): - mat3 = sparse_qr_solve_mkl(self.mat1.astype(np.float32), self.mat2, cast=True) + mat3 = sparse_qr_solve_mkl( + self.mat1.astype(np.float32), + self.mat2, + cast=True + ) npt.assert_array_almost_equal(self.mat3, mat3) def test_sparse_solver_cast_CSC(self):