-
Notifications
You must be signed in to change notification settings - Fork 98
Support of alternative array classes: ndarray-like #305
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b909eb9
Implement NDArrayLike
madsbk a05bdac
small test
madsbk efc8785
removing memtype
madsbk db9a3b0
ensure_ndarray and ensure_contiguous_ndarray to force numpy arrays
madsbk 8d31f9d
Merge branch 'master' into ndarray_like
jakirkham 891a506
Merge branch 'master' of https://github.com/zarr-developers/numcodecs…
madsbk 38d28ff
Adding typing-extensions>=3.7.4 to dependencies
madsbk ceedb3c
Merge branch 'ndarray_like' of github.com:madsbk/numcodecs into ndarr…
madsbk ff671db
Added release note
madsbk 52758d4
Merge branch 'master' into ndarray_like
jakirkham 066f95b
Merge branch 'master' of https://github.com/zarr-developers/numcodecs…
madsbk 9ccfdae
Merge branch 'ndarray_like' of github.com:madsbk/numcodecs into ndarr…
madsbk 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
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,56 @@ | ||
import sys | ||
from typing import Any, Optional, Tuple | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import Protocol, runtime_checkable | ||
else: | ||
from typing_extensions import Protocol, runtime_checkable | ||
madsbk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@runtime_checkable | ||
class DType(Protocol): | ||
itemsize: int | ||
name: str | ||
kind: str | ||
|
||
|
||
@runtime_checkable | ||
class FlagsObj(Protocol): | ||
c_contiguous: bool | ||
f_contiguous: bool | ||
owndata: bool | ||
|
||
|
||
@runtime_checkable | ||
class NDArrayLike(Protocol): | ||
dtype: DType | ||
shape: Tuple[int, ...] | ||
strides: Tuple[int, ...] | ||
ndim: int | ||
size: int | ||
itemsize: int | ||
nbytes: int | ||
flags: FlagsObj | ||
|
||
def __len__(self) -> int: | ||
... | ||
|
||
def __getitem__(self, key) -> Any: | ||
... | ||
|
||
def __setitem__(self, key, value): | ||
... | ||
|
||
def tobytes(self, order: Optional[str] = ...) -> bytes: | ||
... | ||
|
||
def reshape(self, *shape: int, order: str = ...) -> "NDArrayLike": | ||
... | ||
|
||
def view(self, dtype: DType = ...) -> "NDArrayLike": | ||
... | ||
|
||
|
||
def is_ndarray_like(obj: object) -> bool: | ||
"""Return True when `obj` is ndarray-like""" | ||
return isinstance(obj, NDArrayLike) |
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,15 @@ | ||
import pytest | ||
|
||
from numcodecs.ndarray_like import NDArrayLike | ||
|
||
|
||
@pytest.mark.parametrize("module", ["numpy", "cupy"]) | ||
def test_is_ndarray_like(module): | ||
m = pytest.importorskip(module) | ||
a = m.arange(10) | ||
assert isinstance(a, NDArrayLike) | ||
|
||
|
||
def test_is_not_ndarray_like(): | ||
assert not isinstance([1, 2, 3], NDArrayLike) | ||
assert not isinstance(b"1,2,3", NDArrayLike) |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ numpy | |
msgpack | ||
pytest | ||
zfpy | ||
typing-extensions |
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ Cython==0.29.21 | |
msgpack==1.0.2 | ||
numpy==1.21.0 | ||
zfpy==0.5.5 | ||
|
||
|
||
typing-extensions>=3.7.4 |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ mock | |
numpy | ||
cython | ||
zfpy==0.5.5 | ||
typing-extensions |
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
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.