def test_spmm_success(self): ref_1, precision_1 = _create_mkl_sparse(self.mat1) ref_2, precision_2 = _create_mkl_sparse(self.mat2) self.assertTrue(precision_1) self.assertTrue(precision_2) ref_3 = _matmul_mkl(ref_1, ref_2) mat3 = _export_mkl(ref_3, precision_1 or precision_2) mat3_sp = self.mat1.dot(self.mat2) mat3_np = np.dot(self.mat1.A, self.mat2.A) npt.assert_array_almost_equal(mat3.A, mat3_sp.A) npt.assert_array_almost_equal(mat3_np, mat3.A)
def test_spmm_success_float32(self): self.mat1.data = self.mat1.data.astype(np.float32) self.mat2.data = self.mat2.data.astype(np.float32) ref_1, precision_1 = _create_mkl_sparse(self.mat1) ref_2, precision_2 = _create_mkl_sparse(self.mat2) self.assertFalse(precision_1) self.assertFalse(precision_2) ref_3 = _matmul_mkl(ref_1, ref_2) mat3 = _export_mkl(ref_3, precision_1 or precision_2, output_type="csr") mat3_sp = self.mat1.dot(self.mat2) mat3_np = np.dot(self.mat1.A, self.mat2.A) npt.assert_array_almost_equal(mat3.A, mat3_sp.A) npt.assert_array_almost_equal(mat3_np, mat3.A)
def test_spmm_error_bad_handle(self): with self.assertRaises(ValueError): _matmul_mkl(sparse_matrix_t(), sparse_matrix_t())
def test_spmm_error_bad_dims(self): ref_1, prec_1 = _create_mkl_sparse(self.mat1.transpose()) ref_2, prec_2 = _create_mkl_sparse(self.mat2) with self.assertRaises(ValueError): _matmul_mkl(ref_1, ref_2)