Skip to content

Commit

Permalink
Support pydata/sparse 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Oct 26, 2023
1 parent 0585dad commit 6b3b432
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
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

0 comments on commit 6b3b432

Please sign in to comment.