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

Support pydata/sparse 0.13 on Python 3.7 #8

Merged
merged 2 commits into from
Oct 26, 2023
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
24 changes: 11 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ jobs:
- name: Test minimums
run: pytest

- name: Install SciPy
# --only-binary disables compiling the package from source if a binary wheel is not available, such as PyPy
run: pip install --only-binary ":all:" scipy || true

- name: Install python-graphblas
if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for PyPy or old Python
run: |
pip install suitesparse-graphblas==7.4.4.1a1
pip install python-graphblas

- name: Install pydata sparse
if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for PyPy or old Python
- name: Install optional dependencies
# --only-binary disables compiling the package from source if a binary wheel is not available, such as old Python or PyPy
run: |
pip install sparse
echo ""
echo "=== Install SciPy ============================="
pip install --only-binary ":all:" scipy || true
echo ""
echo "=== Install python-graphblas =================="
pip install --only-binary ":all:" python-graphblas || true
echo ""
echo "=== Install PyData/Sparse ====================="
pip install --only-binary ":all:" sparse || true

- name: Test without Jupyter
run: pytest
Expand Down
5 changes: 4 additions & 1 deletion matspy/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np


def describe(shape: tuple = None, nnz: int = None, nz_type=None, notes: str = None) -> str:
def describe(shape: tuple = None, nnz: int = None, nz_type=None, layout: str = None, notes: str = None) -> str:
"""
Create a simple description string from potentially interesting pieces of metadata.
"""
Expand All @@ -27,6 +27,9 @@ def describe(shape: tuple = None, nnz: int = None, nz_type=None, notes: str = No
elif nz_type is not None:
parts.append(f"'{str(nz_type)}' elements")

if layout is not None:
parts.append(str(layout))

if notes:
parts.append(notes)

Expand Down
5 changes: 1 addition & 4 deletions matspy/adapters/graphblas_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ def get_format(self, is_transposed=False):
def describe(self) -> str:
parts = [f"gb.{type(self.mat).__name__}", f"'{self.mat.dtype}'"]

fmt = self.get_format()
if fmt:
parts.append(fmt)

return describe(shape=self.mat.shape,
nnz=self.mat.nvals,
layout=self.get_format(),
notes=", ".join(parts))

def get_spy(self, spy_shape: tuple) -> np.array:
Expand Down
5 changes: 1 addition & 4 deletions matspy/adapters/numpy_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def get_shape(self) -> tuple:
return self.arr.shape

def describe(self) -> str:
format_name = "array"

return describe(shape=self.arr.shape, nz_type=self.arr.dtype,
notes=f"{format_name}")
return describe(shape=self.arr.shape, nz_type=self.arr.dtype, layout="array")

def get_spy(self, spy_shape: tuple) -> np.array:
precision = self.get_option("precision", None)
Expand Down
4 changes: 1 addition & 3 deletions matspy/adapters/scipy_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ def get_shape(self) -> tuple:
return self.mat.shape

def describe(self) -> str:
format_name = self.mat.getformat()

return describe(shape=self.mat.shape, nnz=self.mat.nnz, nz_type=self.mat.dtype,
notes=f"{format_name}")
layout=self.mat.getformat())

def get_spy(self, spy_shape: tuple) -> np.array:
# construct a triple product that will scale the matrix
Expand Down
9 changes: 5 additions & 4 deletions matspy/adapters/sparse_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ def get_shape(self) -> tuple:
return self.mat.shape

def describe(self) -> str:
parts = [
self.mat.format,
]
try:
fmt = self.mat.format
except AttributeError:
fmt = self.mat.__class__.__name__

return describe(shape=self.mat.shape,
nnz=self.mat.nnz, nz_type=self.mat.dtype,
notes=", ".join(parts))
layout=fmt)

def get_spy(self, spy_shape: tuple) -> np.array:
if isinstance(self.mat, sparse.DOK):
Expand Down