Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59e47a0

Browse filesBrowse files
committed
Update with suggestions from @pearu.
1 parent 280ee10 commit 59e47a0
Copy full SHA for 59e47a0

File tree

Expand file treeCollapse file tree

4 files changed

+16
-41
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+16
-41
lines changed

‎sparse/numba_backend/_compressed/compressed.py

Copy file name to clipboardExpand all lines: sparse/numba_backend/_compressed/compressed.py
+5-13Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,8 @@ def isnan(self):
847847
# `GCXS` is a reshaped/transposed `CSR`, but it can't (usually)
848848
# be expressed in the `binsparse` 0.1 language.
849849
# We are missing index maps.
850-
def __binsparse_descriptor__(self) -> dict:
851-
return super().__binsparse_descriptor__()
852-
853-
def __binsparse_dlpack__(self) -> dict[str, np.ndarray]:
854-
return super().__binsparse_dlpack__()
850+
def __binsparse__(self) -> tuple[dict, list[np.ndarray]]:
851+
return super().__binsparse__()
855852

856853

857854
class _Compressed2d(GCXS):
@@ -892,13 +889,13 @@ def from_numpy(cls, x, fill_value=0, idx_dtype=None):
892889
coo = COO.from_numpy(x, fill_value=fill_value, idx_dtype=idx_dtype)
893890
return cls.from_coo(coo, cls.class_compressed_axes, idx_dtype)
894891

895-
def __binsparse_descriptor__(self) -> dict:
892+
def __binsparse__(self) -> tuple[dict, list[np.ndarray]]:
896893
from sparse._version import __version__
897894

898895
data_dt = str(self.data.dtype)
899896
if np.issubdtype(data_dt, np.complexfloating):
900897
data_dt = f"complex[float{self.data.dtype.itemsize // 2}]"
901-
return {
898+
descriptor = {
902899
"binsparse": {
903900
"version": "0.1",
904901
"format": self.format.upper(),
@@ -913,12 +910,7 @@ def __binsparse_descriptor__(self) -> dict:
913910
"original_source": f"`sparse`, version {__version__}",
914911
}
915912

916-
def __binsparse_dlpack__(self) -> dict[str, np.ndarray]:
917-
return {
918-
"pointers_to_1": self.indices,
919-
"indices_1": self.indptr,
920-
"values": self.data,
921-
}
913+
return descriptor, [self.indices, self.indptr, self.data]
922914

923915

924916
class CSR(_Compressed2d):

‎sparse/numba_backend/_coo/core.py

Copy file name to clipboardExpand all lines: sparse/numba_backend/_coo/core.py
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,13 +1537,13 @@ def isnan(self):
15371537
prune=True,
15381538
)
15391539

1540-
def __binsparse_descriptor__(self) -> dict:
1540+
def __binsparse__(self) -> tuple[dict, list[np.ndarray]]:
15411541
from sparse._version import __version__
15421542

15431543
data_dt = str(self.data.dtype)
15441544
if np.issubdtype(data_dt, np.complexfloating):
15451545
data_dt = f"complex[float{self.data.dtype.itemsize // 2}]"
1546-
return {
1546+
descriptor = {
15471547
"binsparse": {
15481548
"version": "0.1",
15491549
"format": {
@@ -1568,12 +1568,7 @@ def __binsparse_descriptor__(self) -> dict:
15681568
"original_source": f"`sparse`, version {__version__}",
15691569
}
15701570

1571-
def __binsparse_dlpack__(self) -> dict[str, np.ndarray]:
1572-
return {
1573-
"pointers_to_1": np.array([0, self.nnz], dtype=np.uint8),
1574-
"indices_1": self.coords,
1575-
"values": self.data,
1576-
}
1571+
return descriptor, [np.array([0, self.nnz], dtype=np.uint8), self.coords, self.data]
15771572

15781573

15791574
def as_coo(x, shape=None, fill_value=None, idx_dtype=None):

‎sparse/numba_backend/_dok.py

Copy file name to clipboardExpand all lines: sparse/numba_backend/_dok.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,8 @@ def reshape(self, shape, order="C"):
548548

549549
return DOK.from_coo(self.to_coo().reshape(shape))
550550

551-
def __binsparse_descriptor__(self) -> dict:
552-
raise RuntimeError("`DOK` doesn't support the `__binsparse_descriptor__` protocol.")
553-
554-
def __binsparse_dlpack__(self) -> dict[str, np.ndarray]:
555-
raise RuntimeError("`DOK` doesn't support the `__binsparse_dlpack__` protocol.")
551+
def __binsparse__(self) -> tuple[dict, list[np.ndarray]]:
552+
raise RuntimeError("`DOK` doesn't support the `__binsparse__` protocol.")
556553

557554

558555
def to_slice(k):

‎sparse/numba_backend/_sparse_array.py

Copy file name to clipboardExpand all lines: sparse/numba_backend/_sparse_array.py
+6-15Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,18 @@ def _str_impl(self, summary):
219219
return summary
220220

221221
@abstractmethod
222-
def __binsparse_descriptor__(self) -> dict:
223-
"""Return a `dict` equivalent to a parsed JSON [`binsparse` descriptor](https://graphblas.org/binsparse-specification/#descriptor)
222+
def __binsparse__(self) -> tuple[dict, list[np.ndarray]]:
223+
"""Return a 2-tuple:
224+
* First element is a `dict` equivalent to a parsed JSON [`binsparse` descriptor](https://graphblas.org/binsparse-specification/#descriptor)
224225
of this array.
226+
* Second element is a `list[np.ndarray]` of the constituent arrays.
225227
226228
Returns
227229
-------
228230
dict
229231
Parsed `binsparse` descriptor.
230-
"""
231-
raise NotImplementedError
232-
233-
@abstractmethod
234-
def __binsparse_dlpack__(self) -> dict[str, np.ndarray]:
235-
"""A `dict` containing the constituent arrays of this sparse array. The keys are compatible with the
236-
[`binsparse`](https://graphblas.org/binsparse-specification/) scheme, and the values are [`__dlpack__`](https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html)
237-
compatible objects.
238-
239-
Returns
240-
-------
241-
dict[str, np.ndarray]
242-
The constituent arrays.
232+
list[np.ndarray]
233+
The constituent arrays
243234
"""
244235
raise NotImplementedError
245236

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.