Skip to content

Commit

Permalink
DOC: Add efficiency condition for CSC sparse matrix and remove CSC wa…
Browse files Browse the repository at this point in the history
…rning. (#15846)

Closes gh-11145
  • Loading branch information
v0dro committed Apr 26, 2022
1 parent 895f29d commit 0a2fb1a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
17 changes: 11 additions & 6 deletions scipy/sparse/linalg/_dsolve/linsolve.py
Expand Up @@ -277,7 +277,8 @@ def splu(A, permc_spec=None, diag_pivot_thresh=None,
Parameters
----------
A : sparse matrix
Sparse matrix to factorize. Should be in CSC format.
Sparse matrix to factorize. Most efficient when provided in CSC
format. Other formats will be converted to CSC before factorization.
permc_spec : str, optional
How to permute the columns of the matrix for sparsity preservation.
(default: 'COLAMD')
Expand Down Expand Up @@ -343,7 +344,7 @@ def splu(A, permc_spec=None, diag_pivot_thresh=None,

if not isspmatrix_csc(A):
A = csc_matrix(A)
warn('splu requires CSC matrix format', SparseEfficiencyWarning)
warn('splu converted its input to CSC format', SparseEfficiencyWarning)

# sum duplicates for non-canonical format
A.sum_duplicates()
Expand Down Expand Up @@ -377,7 +378,8 @@ def spilu(A, drop_tol=None, fill_factor=None, drop_rule=None, permc_spec=None,
Parameters
----------
A : (N, N) array_like
Sparse matrix to factorize. Should be in CSC format.
Sparse matrix to factorize. Most efficient when provided in CSC format.
Other formats will be converted to CSC before factorization.
drop_tol : float, optional
Drop tolerance (0 <= tol <= 1) for an incomplete LU decomposition.
(default: 1e-4)
Expand Down Expand Up @@ -432,7 +434,8 @@ def spilu(A, drop_tol=None, fill_factor=None, drop_rule=None, permc_spec=None,

if not isspmatrix_csc(A):
A = csc_matrix(A)
warn('spilu requires CSC matrix format', SparseEfficiencyWarning)
warn('spilu converted its input to CSC format',
SparseEfficiencyWarning)

# sum duplicates for non-canonical format
A.sum_duplicates()
Expand Down Expand Up @@ -465,7 +468,8 @@ def factorized(A):
Parameters
----------
A : (N, N) array_like
Input.
Input. A in CSC format is most efficient. A CSR format matrix will
be converted to CSC before factorization.
Returns
-------
Expand Down Expand Up @@ -494,7 +498,8 @@ def factorized(A):

if not isspmatrix_csc(A):
A = csc_matrix(A)
warn('splu requires CSC matrix format', SparseEfficiencyWarning)
warn('splu converted its input to CSC format',
SparseEfficiencyWarning)

A = A.asfptype() # upcast to a floating point format

Expand Down
3 changes: 2 additions & 1 deletion scipy/sparse/linalg/_isolve/tests/test_iterative.py
Expand Up @@ -570,7 +570,8 @@ def test_leftright_precond(self):
U = spdiags([4*dat, -dat], [0,1], n, n)

with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning, "splu requires CSC matrix format")
sup.filter(SparseEfficiencyWarning,
"splu converted its input to CSC format")
L_solver = splu(L)
U_solver = splu(U)

Expand Down
5 changes: 2 additions & 3 deletions scipy/sparse/linalg/tests/test_expm_multiply.py
Expand Up @@ -114,7 +114,7 @@ def test_sparse_expm_multiply(self):
observed = expm_multiply(A, B)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning,
"splu requires CSC matrix format")
"splu converted its input to CSC format")
sup.filter(SparseEfficiencyWarning,
"spsolve is more efficient when sparse b is in the"
" CSC matrix format")
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_sparse_expm_multiply_interval(self):
num=num, endpoint=endpoint)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning,
"splu requires CSC matrix format")
"splu converted its input to CSC format")
sup.filter(SparseEfficiencyWarning,
"spsolve is more efficient when sparse b is in the CSC matrix format")
for solution, t in zip(X, samples):
Expand Down Expand Up @@ -249,4 +249,3 @@ def _help_test_specific_expm_interval_status(self, target_status):
if not nsuccesses:
msg = 'failed to find a status-' + str(target_status) + ' interval'
raise Exception(msg)

8 changes: 5 additions & 3 deletions scipy/sparse/tests/test_base.py
Expand Up @@ -1113,7 +1113,8 @@ def test_expm(self):
Nexp = scipy.linalg.expm(N)

with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning, "splu requires CSC matrix format")
sup.filter(SparseEfficiencyWarning,
"splu converted its input to CSC format")
sup.filter(SparseEfficiencyWarning,
"spsolve is more efficient when sparse b is in the CSC matrix format")
sup.filter(SparseEfficiencyWarning,
Expand All @@ -1133,7 +1134,7 @@ def check(dtype):
sup.filter(SparseEfficiencyWarning,
"spsolve is more efficient when sparse b is in the CSC matrix format")
sup.filter(SparseEfficiencyWarning,
"splu requires CSC matrix format")
"splu converted its input to CSC format")
sM = self.spmatrix(M, shape=(3,3), dtype=dtype)
sMinv = inv(sM)
assert_array_almost_equal(sMinv.dot(sM).toarray(), np.eye(3))
Expand Down Expand Up @@ -2337,7 +2338,8 @@ def test_solve(self):
A[i+1,i] = conjugate(y[i])
A = self.spmatrix(A)
with suppress_warnings() as sup:
sup.filter(SparseEfficiencyWarning, "splu requires CSC matrix format")
sup.filter(SparseEfficiencyWarning,
"splu converted its input to CSC format")
x = splu(A).solve(r)
assert_almost_equal(A*x,r)

Expand Down

0 comments on commit 0a2fb1a

Please sign in to comment.