Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.13 #19

Merged
merged 6 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: False
matrix:
os: [ubuntu-latest, macos-12, windows-latest]
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
mkl-version: ['2023', '2024']
include:
- os: ubuntu-latest
Expand All @@ -39,7 +39,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
channels: defaults
channels: conda-forge, defaults
channel-priority: true
activate-environment: dev

Expand Down
31 changes: 19 additions & 12 deletions pydiso/mkl_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,16 @@

self.matrix_type = matrix_type

indptr = np.asarray(A.indptr) # double check it's a numpy array
A = self._validate_csr_matrix(A)

max_a_ind_itemsize = max(A.indptr.itemsize, A.indices.itemsize)
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
target_int_size = mkl_int_size if max_a_ind_itemsize <= mkl_int_size else mkl_int64_size
self._ind_dtype = np.dtype(f"i{target_int_size}")

data, indptr, indices = self._validate_matrix(A)
data, indptr, indices = self._validate_matrix_dtypes(A)
self._data = data
self._indptr = indptr
self._indices = indices
Expand Down Expand Up @@ -185,7 +187,9 @@
raise TypeError("A is not a sparse matrix.")
if A.shape != self.shape:
raise ValueError("A is not the same size as the previous matrix.")
data, indptr, indices = self._validate_matrix(A)

A = self._validate_csr_matrix(A)
data, indptr, indices = self._validate_matrix_dtypes(A)

Check warning on line 192 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L191-L192

Added lines #L191 - L192 were not covered by tests
if len(data) != len(self._data):
raise ValueError("new A matrix does not have the same number of non zeros.")

Expand Down Expand Up @@ -284,21 +288,24 @@
"""
return np.array(self._handle.iparm)

def _validate_matrix(self, mat):

def _validate_csr_matrix(self, mat):
if self.matrix_type in [-2, 2, -4, 4, 6]:
# Symmetric matrices must have only the upper triangle
if sp.isspmatrix_csc(mat):
mat = mat.T # Transpose to get a CSR matrix since it's symmetric
# only grab the upper triangle.
mat = sp.triu(mat, format='csr')

if not (sp.isspmatrix_csr(mat)):
warnings.warn("Converting %s matrix to CSR format."
% mat.__class__.__name__, PardisoTypeConversionWarning)
if mat.format != 'csr':
warnings.warn(

Check warning on line 297 in pydiso/mkl_solver.py

View check run for this annotation

Codecov / codecov/patch

pydiso/mkl_solver.py#L297

Added line #L297 was not covered by tests
"Converting %s matrix to CSR format."% A.__class__.__name__,
PardisoTypeConversionWarning,
stacklevel=3
)
mat = mat.tocsr()

mat.sort_indices()
mat.sum_duplicates()
return mat

def _validate_matrix_dtypes(self, mat):
data = np.require(mat.data, self._data_dtype, requirements="C")
indptr = np.require(mat.indptr, self._ind_dtype, requirements="C")
indices = np.require(mat.indices, self._ind_dtype, requirements="C")
Expand Down
Loading