Skip to content

Commit

Permalink
remove a few call signatures from doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapriot committed Sep 24, 2024
1 parent 1c1b8bd commit 8dc1d4e
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions pydiso/mkl_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,10 @@ class PardisoTypeConversionWarning(
PardisoWarning, sp.SparseEfficiencyWarning):
pass


def _ensure_csr(A, sym=False):
if not (sp.isspmatrix_csr(A)):
if sym and sp.isspmatrix_csc(A):
A = A.T
else:
warnings.warn("Converting %s matrix to CSR format."
%A.__class__.__name__, PardisoTypeConversionWarning)
A = A.tocsr()
return A


class MKLPardisoSolver:

def __init__(self, A, matrix_type=None, factor=True, verbose=False):
'''ParidsoSolver(A, matrix_type=None, factor=True, verbose=False)
An interface to the intel MKL pardiso sparse matrix solver.
'''An interface to the Intel MKL pardiso sparse matrix solver.
This is a solver class for a scipy sparse matrix using the Pardiso sparse
solver in the Intel Math Kernel Library.
Expand All @@ -68,7 +55,7 @@ def __init__(self, A, matrix_type=None, factor=True, verbose=False):
A : scipy.sparse.spmatrix
A sparse matrix preferably in a CSR format.
matrix_type : str, int, or None, optional
A string describing the matrix type, or it's corresponding int code.
A string describing the matrix type, or its corresponding integer code.
If None, then assumed to be nonsymmetric matrix.
factor : bool, optional
Whether to perform the factorization stage upon instantiation of the class.
Expand Down Expand Up @@ -157,7 +144,7 @@ def __init__(self, A, matrix_type=None, factor=True, verbose=False):
self.matrix_type = matrix_type

indptr = np.asarray(A.indptr) # double check it's a numpy array
mkl_int_size= get_mkl_int_size()
mkl_int_size = get_mkl_int_size()
mkl_int64_size = get_mkl_int64_size()

target_int_size = mkl_int_size if indptr.itemsize <= mkl_int_size else mkl_int64_size
Expand All @@ -180,14 +167,11 @@ def __init__(self, A, matrix_type=None, factor=True, verbose=False):
self._factor()

def refactor(self, A):
"""solver.refactor(A)
re-use a symbolic factorization with a new `A` matrix.
"""Reuse a symbolic factorization with a new matrix.
Note
----
Must have the same non-zero pattern as the initial `A` matrix.
If `full_refactor=False`, the initial factorization is used as a
preconditioner to a Krylov subspace solver in the solve step.
Parameters
----------
Expand All @@ -212,14 +196,7 @@ def __call__(self, b):
return self.solve(b)

Check warning on line 196 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L196

Added line #L196 was not covered by tests

def solve(self, b, x=None, transpose=False):
"""solve(self, b, x=None, transpose=False)
Solves the equation AX=B using the factored A matrix
Note
----
The data will be copied if not contiguous in all cases. If multiple rhs
are given, the input arrays will be copied if not in a contiguous
Fortran order.
"""Solves the equation AX=B using the factored A matrix
Parameters
----------
Expand All @@ -234,12 +211,15 @@ def solve(self, b, x=None, transpose=False):
Returns
-------
numpy array
numpy.ndarray
array containing the solution (in Fortran ordering)
"""
if(not self._factored):
raise PardisoError("Cannot solve without a previous factorization.")
Notes
-----
The data will be copied if not contiguous in all cases. If multiple rhs
are given, the input arrays will be copied if not in a contiguous
Fortran order.
"""
if b.dtype != self._data_dtype:
warnings.warn("rhs does not have the same data type as A",

Check warning on line 224 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L224

Added line #L224 was not covered by tests
PardisoTypeConversionWarning)
Expand Down Expand Up @@ -279,6 +259,9 @@ def solve(self, b, x=None, transpose=False):
if x is b or (x.base is not None and (x.base is b.base)):
raise ValueError("x and b cannot point to the same memory")

Check warning on line 260 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L260

Added line #L260 was not covered by tests

if not self._factored:
self._factor()

Check warning on line 263 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L263

Added line #L263 was not covered by tests

self._handle.set_iparm(11, 2 if transpose else 0)

phase = 33
Expand Down Expand Up @@ -308,7 +291,11 @@ def _validate_matrix(self, mat):
if sp.isspmatrix_csc(mat):
mat = mat.T # Transpose to get a CSR matrix since it's symmetric

Check warning on line 292 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L292

Added line #L292 was not covered by tests
mat = sp.triu(mat, format='csr')
mat = _ensure_csr(mat)

if not (sp.isspmatrix_csr(mat)):
warnings.warn("Converting %s matrix to CSR format."

Check warning on line 296 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L296

Added line #L296 was not covered by tests
% mat.__class__.__name__, PardisoTypeConversionWarning)
mat = mat.tocsr()

Check warning on line 298 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L298

Added line #L298 was not covered by tests
mat.sort_indices()
mat.sum_duplicates()

Expand All @@ -335,15 +322,15 @@ def nnz(self):

def _analyze(self):
phase = 11
xb_dummy = np.empty([1,1], dtype=self._data_dtype)
xb_dummy = np.empty([1, 1], dtype=self._data_dtype)
error = self._handle.call_pardiso(phase, self._data, self._indptr, self._indices, xb_dummy, xb_dummy)
if error:
raise PardisoError("Analysis step error, "+_err_messages[error])

Check warning on line 328 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L328

Added line #L328 was not covered by tests

def _factor(self):
phase = 22
self._factored = False
xb_dummy = np.empty([1,1], dtype=self._data_dtype)
xb_dummy = np.empty([1, 1], dtype=self._data_dtype)
error = self._handle.call_pardiso(phase, self._data, self._indptr, self._indices, xb_dummy, xb_dummy)

if error:
Expand Down

0 comments on commit 8dc1d4e

Please sign in to comment.