def test_call_with_cast_to_complex_without_umfpack(self): use_solver(useUmfpack=False) solve = factorized(self.A) b = random.rand(4) for t in [np.complex64, np.complex128]: assert_raises_regex(TypeError, "Cannot cast array data", solve, b.astype(t))
def test_bmat(self): A = coo_matrix([[1, 2], [3, 4]]) B = coo_matrix([[5], [6]]) C = coo_matrix([[7]]) D = coo_matrix((0, 0)) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A, B], [None, C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal( construct.bmat([[A, None], [None, C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal( construct.bmat([[None, B], [C, None]]).todense(), expected) expected = matrix(np.empty((0, 0))) assert_equal(construct.bmat([[None, None]]).todense(), expected) assert_equal( construct.bmat([[None, D], [D, None]]).todense(), expected) # test bug reported in gh-5976 expected = matrix([[7]]) assert_equal( construct.bmat([[None, D], [C, None]]).todense(), expected) # test failure cases assert_raises_regex(ValueError, r'Got blocks\[1,0\]\.shape\[1\] == 1, expected 2', construct.bmat, [[A], [B]]) assert_raises_regex(ValueError, r'Got blocks\[0,1\]\.shape\[0\] == 1, expected 2', construct.bmat, [[A, C]])
def test_call_with_incorrectly_sized_matrix_with_umfpack(self): use_solver(useUmfpack=True) solve = factorized(self.A) b = random.rand(4) B = random.rand(4, 3) BB = random.rand(self.n, 3, 9) # does not raise solve(b) assert_raises_regex(ValueError, "object too deep for desired array", solve, B) assert_raises_regex(ValueError, "object too deep for desired array", solve, BB)
def test_splrep_errors(self): # test that both "old" and "new" splrep raise for an n-D ``y`` array # with n > 1 x, y = self.xx, self.yy y2 = np.c_[y, y] msg = "failed in converting 3rd argument `y' of dfitpack.curfit to C/Fortran array" assert_raises_regex(Exception, msg, splrep, x, y2) assert_raises_regex(Exception, msg, _impl.splrep, x, y2) # input below minimum size assert_raises_regex(TypeError, "m > k must hold", splrep, x[:3], y[:3]) assert_raises_regex(TypeError, "m > k must hold", _impl.splrep, x[:3], y[:3])
def test_assume_sorted_indices_flag(self): # a sparse matrix with unsorted indices unsorted_inds = np.array([2, 0, 1, 0]) data = np.array([10, 16, 5, 0.4]) indptr = np.array([0, 1, 2, 4]) A = csc_matrix((data, unsorted_inds, indptr), (3, 3)) b = ones(3) # should raise when incorrectly assuming indices are sorted use_solver(useUmfpack=True, assumeSortedIndices=True) assert_raises_regex(RuntimeError, "UMFPACK_ERROR_invalid_matrix", factorized, A) # should sort indices and succeed when not assuming indices are sorted use_solver(useUmfpack=True, assumeSortedIndices=False) expected = splu(A.copy()).solve(b) assert_equal(A.has_sorted_indices, 0) assert_array_almost_equal(factorized(A)(b), expected) assert_equal(A.has_sorted_indices, 1)
def test_bmat(self): A = coo_matrix([[1,2],[3,4]]) B = coo_matrix([[5],[6]]) C = coo_matrix([[7]]) D = coo_matrix((0,0)) expected = matrix([[1, 2, 5], [3, 4, 6], [0, 0, 7]]) assert_equal(construct.bmat([[A,B],[None,C]]).todense(), expected) expected = matrix([[1, 2, 0], [3, 4, 0], [0, 0, 7]]) assert_equal(construct.bmat([[A,None],[None,C]]).todense(), expected) expected = matrix([[0, 5], [0, 6], [7, 0]]) assert_equal(construct.bmat([[None,B],[C,None]]).todense(), expected) expected = matrix(np.empty((0,0))) assert_equal(construct.bmat([[None,None]]).todense(), expected) assert_equal(construct.bmat([[None,D],[D,None]]).todense(), expected) # test bug reported in gh-5976 expected = matrix([[7]]) assert_equal(construct.bmat([[None,D],[C,None]]).todense(), expected) # test failure cases assert_raises_regex(ValueError, r'Got blocks\[1,0\]\.shape\[1\] == 1, expected 2', construct.bmat, [[A],[B]]) assert_raises_regex(ValueError, r'Got blocks\[0,1\]\.shape\[0\] == 1, expected 2', construct.bmat, [[A,C]])
def test_call_with_incorrectly_sized_matrix_without_umfpack(self): use_solver(useUmfpack=False) solve = factorized(self.A) b = random.rand(4) B = random.rand(4, 3) BB = random.rand(self.n, 3, 9) assert_raises_regex(ValueError, "is of incompatible size", solve, b) assert_raises_regex(ValueError, "is of incompatible size", solve, B) assert_raises_regex(ValueError, "object too deep for desired array", solve, BB)
def test_splprep_errors(self): # test that both "old" and "new" code paths raise for x.ndim > 2 x = np.arange(3*4*5).reshape((3, 4, 5)) assert_raises_regex(ValueError, "too many values to unpack", splprep, x) assert_raises_regex(ValueError, "too many values to unpack", _impl.splprep, x) # input below minimum size x = np.linspace(0, 40, num=3) assert_raises_regex(TypeError, "m > k must hold", splprep, [x]) assert_raises_regex(TypeError, "m > k must hold", _impl.splprep, [x]) # automatically calculated parameters are non-increasing # see gh-7589 x = [-50.49072266, -50.49072266, -54.49072266, -54.49072266] assert_raises_regex(ValueError, "Invalid inputs", splprep, [x]) assert_raises_regex(ValueError, "Invalid inputs", _impl.splprep, [x]) # given non-increasing parameter values u x = [1, 3, 2, 4] u = [0, 0.3, 0.2, 1] assert_raises_regex(ValueError, "Invalid inputs", splprep, *[[x], None, u])
def test_splprep_errors(self): # test that both "old" and "new" code paths raise for x.ndim > 2 x = np.arange(3 * 4 * 5).reshape((3, 4, 5)) assert_raises_regex(ValueError, "too many values to unpack", splprep, x) assert_raises_regex(ValueError, "too many values to unpack", _impl.splprep, x) # input below minimum size x = np.linspace(0, 40, num=3) assert_raises_regex(TypeError, "m > k must hold", splprep, [x]) assert_raises_regex(TypeError, "m > k must hold", _impl.splprep, [x]) # automatically calculated parameters are non-increasing # see gh-7589 x = [-50.49072266, -50.49072266, -54.49072266, -54.49072266] assert_raises_regex(ValueError, "Invalid inputs", splprep, [x]) assert_raises_regex(ValueError, "Invalid inputs", _impl.splprep, [x]) # given non-increasing parameter values u x = [1, 3, 2, 4] u = [0, 0.3, 0.2, 1] assert_raises_regex(ValueError, "Invalid inputs", splprep, *[[x], None, u])
def test_cannot_factorize_nonsquare_matrix_without_umfpack(self): use_solver(useUmfpack=False) assert_raises_regex(ValueError, "can only factor square matrices", factorized, self.A[:,:4])
def test_singular_without_umfpack(self): use_solver(useUmfpack=False) assert_raises_regex(RuntimeError, "Factor is exactly singular", self._check_singular)