-
-
Notifications
You must be signed in to change notification settings - Fork 132
Format specification API #792
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1a20262
Add format generation from levels.
hameerabbasi 07216a9
Add SciPy conversions.
hameerabbasi 93f8ef7
Make certain methods private.
hameerabbasi e9fcedb
Adjust public API, tests, and format definition language.
hameerabbasi 0027e00
Try to fix `numpy<2`.
hameerabbasi 09316d5
Simplify `_from_scipy` function.
hameerabbasi 62b71c8
Simplify `Array.copy`.
hameerabbasi 261c7d8
Test copy.
hameerabbasi 0d48a5e
Remove unsupported/untested code.
hameerabbasi 1f72797
Fix bug with `copy=False`.
hameerabbasi 63a5817
Refactor memory ownership out of the public API.
hameerabbasi a5b692e
Rename `Array._get_storage_format`.
hameerabbasi 4ad635b
Simplify and type hint `to_numpy` and `to_scipy`.
hameerabbasi 7bbf1b7
Merge remote-tracking branch 'origin/main' into format-refactor
hameerabbasi 018c567
Simplify and type hint `to_numpy` and `to_scipy` even more.
hameerabbasi f7162f8
Address review comments by @mtsokol.
hameerabbasi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,17 @@ | ||
| try: | ||
| import mlir # noqa: F401 | ||
|
|
||
| del mlir | ||
| except ModuleNotFoundError as e: | ||
| raise ImportError( | ||
| "MLIR Python bindings not installed. Run " | ||
| "`conda install conda-forge::mlir-python-bindings` " | ||
| "to enable MLIR backend." | ||
| ) from e | ||
|
|
||
| from ._constructors import ( | ||
| PackedArgumentTuple, | ||
| asarray, | ||
| ) | ||
| from ._dtypes import ( | ||
| asdtype, | ||
| ) | ||
| from ._ops import ( | ||
| add, | ||
| broadcast_to, | ||
| reshape, | ||
| ) | ||
| from . import levels | ||
| from ._conversions import asarray, from_constituent_arrays, to_numpy, to_scipy | ||
| from ._dtypes import asdtype | ||
| from ._ops import add | ||
|
|
||
| __all__ = [ | ||
| "add", | ||
| "broadcast_to", | ||
| "asarray", | ||
| "asdtype", | ||
| "reshape", | ||
| "PackedArgumentTuple", | ||
| ] | ||
| __all__ = ["add", "asarray", "asdtype", "to_numpy", "to_scipy", "levels", "from_constituent_arrays"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import numpy as np | ||
|
|
||
| from .levels import StorageFormat | ||
|
|
||
|
|
||
| class Array: | ||
| def __init__(self, *, storage, shape: tuple[int, ...]) -> None: | ||
| storage_rank = storage.get_storage_format().rank | ||
| if len(shape) != storage_rank: | ||
| raise ValueError(f"Mismatched rank, `{storage_rank=}`, `{shape=}`") | ||
|
|
||
| self._storage = storage | ||
| self._shape = shape | ||
|
|
||
| @property | ||
| def shape(self) -> tuple[int, ...]: | ||
| return self._shape | ||
|
|
||
| @property | ||
| def ndim(self) -> int: | ||
| return len(self.shape) | ||
|
|
||
| @property | ||
| def dtype(self): | ||
| return self._storage.get_storage_format().dtype | ||
|
|
||
| @property | ||
| def format(self) -> StorageFormat: | ||
| return self._storage.get_storage_format() | ||
|
|
||
| def _get_mlir_type(self): | ||
| return self.format._get_mlir_type(shape=self.shape) | ||
|
|
||
| def _to_module_arg(self): | ||
| return self._storage.to_module_arg() | ||
|
|
||
| def copy(self): | ||
hameerabbasi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from ._conversions import from_constituent_arrays | ||
|
|
||
| arrs = tuple(arr.copy() for arr in self.get_constituent_arrays()) | ||
| return from_constituent_arrays(format=self.format, arrays=arrs, shape=self.shape) | ||
|
|
||
| def get_constituent_arrays(self) -> tuple[np.ndarray, ...]: | ||
| return self._storage.get_constituent_arrays() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.