8000 Add specification for the `__binsparse__` protocol by hameerabbasi · Pull Request #912 · data-apis/array-api · GitHub
[go: up one dir, main page]

Skip to content

Add specification for the __binsparse__ protocol #912

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move from_binsparse to sparse submodule.
  • Loading branch information
hameerabbasi committed Apr 3, 2025
commit af51eb5e370ccc6f9b9c26890ec094d17a9a8a6b
4 changes: 2 additions & 2 deletions spec/draft/extensions/sparse_interchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Extension name and usage

If implemented, this extension must be retrievable via::

>>> if hasattr(x, '__dlpack__'):
>>> if hasattr(x, 'sparse'):
>>> # Use the extension

Objects in API
Expand All @@ -28,7 +28,7 @@ functions/methods.
:toctree: generated
:template: method.rst

from_binsparse
sparse.from_binsparse


.. autosummary::
Expand Down
1 change: 1 addition & 0 deletions src/array_api_stubs/_draft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .utility_functions import *
from . import linalg
from . import fft
from . import sparse
from .info import __array_namespace_info__


Expand Down
24 changes: 0 additions & 24 deletions src/array_api_stubs/_draft/creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"empty",
"empty_like",
"eye",
"from_binsparse",
"from_dlpack",
"full",
"full_like",
Expand Down Expand Up @@ -646,26 +645,3 @@ def zeros_like(
out: array
an array having the same shape as ``x`` and filled with zeros.
"""


def from_binsparse(arrays: dict[str, array], descriptor: dict, /) -> array:
"""
Returns a new array containing the data from another (array) object with a ``__binsparse__`` method.

Parameters
----------
arrays: dict[str, array]
input constituent arrays.
descriptor: dict
the parsed binsparse descriptor of the array.

Returns
-------
out: array
an array containing the data in `arrays` with a format specified by `descriptor`.

.. admonition:: Note
:class: note

The returned array may be either a copy or a view. See :ref:`data-interchange` for details.
"""
28 changes: 28 additions & 0 deletions src/array_api_stubs/_draft/sparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

from ._types import array

__all__ = ["from_binsparse"]


def from_binsparse(arrays: dict[str, array], descriptor: dict, /) -> array:
"""
Returns a new array containing the data from another (array) object with a ``__binsparse__`` method.

Parameters
----------
arrays: dict[str, array]
input constituent arrays.
descriptor: dict
The parsed binsparse descriptor of the array.

Returns
-------
out: array
an array containing the data in `arrays` with a format specified by `descriptor`.

.. admonition:: Note
:class: note

The returned array may be either a copy or a view. See :ref:`data-interchange` for details.
"""
0