Repository: scipy/scipy
Pull request: DOC: Add efficiency condition for CSC sparse matrix and remove CSC warning.
Closes gh-11145. Remove warnings for efficiency when using CSC matrices.

Problem statement:
unexpected SparseEfficiencyWarning at scipy.sparse.linalg.splu
Hey
I get a warning for using CSR format in splu. This is a bit 
confusing because in the documentation it a permissible format. 

"Sparse matrix to factorize. Should be in CSR or CSC format."

#### Reproducing code example:
```
from scipy.sparse import csr_matrix
from scipy.sparse.linalg import splu
A = csr_matrix(([1,1,1],([0,1,2],[0,1,2])))
splu(A)
```

#### Error message:

SparseEfficiencyWarning: splu requires CSC matrix format
warn('splu requires CSC matrix format', SparseEfficiencyWarning)

#### Scipy/Numpy/Python version information:
Python 3.6.9
Scipy 1.33

Hints from issue discussion:
Agreed, if CSC is preferred then it needs a doc update. Alternatively, the warning isn't justified and needs to be removed.

Commit message: add warning for sparse efficiency format

Patch to review:
diff --git a/scipy/sparse/linalg/_dsolve/linsolve.py b/scipy/sparse/linalg/_dsolve/linsolve.py
index b661d53941ad..4019450c989e 100644
--- a/scipy/sparse/linalg/_dsolve/linsolve.py
+++ b/scipy/sparse/linalg/_dsolve/linsolve.py
@@ -265,7 +265,9 @@ def splu(A, permc_spec=None, diag_pivot_thresh=None,
     Parameters
     ----------
     A : sparse matrix
-        Sparse matrix to factorize. Should be in CSR or CSC format.
+        Sparse matrix to factorize. Should be in CSR or CSC format. The CSC
+        format is generally more efficient than CSR. If a CSR matrix is provided,
+        splu() will convert the matrix to CSC before factorization.
     permc_spec : str, optional
         How to permute the columns of the matrix for sparsity preservation.
         (default: 'COLAMD')
@@ -331,7 +333,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()
@@ -365,7 +367,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
+        Sparse matrix to factorize. Matrix A in CSC format is most efficient.
+        CSR format input will be converted to CSC before factorization.
     drop_tol : float, optional
         Drop tolerance (0 <= tol <= 1) for an incomplete LU decomposition.
         (default: 1e-4)
@@ -420,7 +423,7 @@ 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('splu requires CSC matrix format', SparseEfficiencyWarning)
+        warn('spilu() converted its input to CSC format', SparseEfficiencyWarning)
 
     # sum duplicates for non-canonical format
     A.sum_duplicates()
@@ -453,7 +456,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
     -------
@@ -482,7 +486,7 @@ def factorized(A):
 
         if not isspmatrix_csc(A):
             A = csc_matrix(A)
-            warn('splu requires CSC matrix format', SparseEfficiencyWarning)
+            warn('factorized() converted its input to CSC format', SparseEfficiencyWarning)
 
         A = A.asfptype()  # upcast to a floating point format
 


Code review comments:
diff_hunk: @@ -265,7 +265,9 @@ def splu(A, permc_spec=None, diag_pivot_thresh=None,
     Parameters
     ----------
     A : sparse matrix
-        Sparse matrix to factorize. Should be in CSR or CSC format.
+        Sparse matrix to factorize. Should be in CSR or CSC format. The CSC
+        format is generally more efficient than CSR. If a CSR matrix is provided,
path: scipy/sparse/linalg/_dsolve/linsolve.py
text: @user1:
Instead of saying "If a CSR matrix...", let's be more general and say "If a different sparse format is provided..."

@author:
It says in the previous sentence that it should be a CSC or CSR matrix (which existed before this PR). Should I remove that too?

@user1:
How about this:

Sparse matrix to factorize. Most efficient when provided in CSC format. Other formats will be converted to CSC before factorization.