-
Notifications
You must be signed in to change notification settings - Fork 5
✨start ArrayNamespace #56
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
nstarman
wants to merge
9
commits into
data-apis:main
Choose a base branch
from
nstarman:array-namespace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3cb0930
💄rearrange protocols in Array
nstarman 377b4b5
✨ HasDevice
nstarman ce758bd
✨ HasMatrixTranspose
nstarman c6b28ad
✨ HasNDim
nstarman b99cb83
✨ HasShape
nstarman 697883d
✨ HasSize
nstarman c65c5d5
✨ HasTranspose
nstarman 466b4f7
✨ start ArrayNamespace protocol
nstarman a17798c
✨: AsType functions
nstarman 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,12 +1,35 @@ | ||
"""Static typing support for the array API standard.""" | ||
|
||
__all__ = ( | ||
__all__ = ( # noqa: RUF022 | ||
# ================== | ||
# Array | ||
"Array", | ||
"HasArrayNamespace", | ||
"HasDType", | ||
"HasMatrixTranspose", | ||
"HasNDim", | ||
"HasShape", | ||
"HasSize", | ||
"HasTranspose", | ||
# ================== | ||
# Namespace | ||
"ArrayNamespace", | ||
"DoesAsType", | ||
"HasAsType", | ||
# ================== | ||
"__version__", | ||
"__version_tuple__", | ||
) | ||
|
||
from ._array import Array, HasArrayNamespace, HasDType | ||
from ._array import ( | ||
Array, | ||
HasArrayNamespace, | ||
HasDType, | ||
HasMatrixTranspose, | ||
HasNDim, | ||
HasShape, | ||
HasSize, | ||
HasTranspose, | ||
) | ||
from ._namespace import ArrayNamespace, DoesAsType, HasAsType | ||
from ._version import version as __version__, version_tuple as __version_tuple__ |
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
Empty file.
Empty file.
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,112 @@ | ||
from typing import Protocol, TypeVar | ||
|
||
from ._array import HasDType | ||
|
||
__all__ = ( | ||
"ArrayNamespace", | ||
# Data Type Functions | ||
"DoesAsType", | ||
"HasAsType", | ||
) | ||
|
||
DTypeT = TypeVar("DTypeT") | ||
ToDTypeT = TypeVar("ToDTypeT") | ||
|
||
# =================================================================== | ||
# Creation Functions | ||
# TODO: arange, asarray, empty, empty_like, eye, from_dlpack, full, full_like, | ||
# linspace, meshgrid, ones, ones_like, tril, triu, zeros, zeros_like | ||
|
||
# =================================================================== | ||
# Data Type Functions | ||
# TODO: broadcast_arrays, broadcast_to, can_cast, finfo, iinfo, | ||
# result_type | ||
|
||
|
||
class DoesAsType(Protocol): | ||
"""Copies an array to a specified data type irrespective of Type Promotion Rules rules. | ||
|
||
Note: | ||
Casting floating-point ``NaN`` and ``infinity`` values to integral data | ||
types is not specified and is implementation-dependent. | ||
|
||
Note: | ||
When casting a boolean input array to a numeric data type, a value of | ||
`True` must cast to a numeric value equal to ``1``, and a value of | ||
`False` must cast to a numeric value equal to ``0``. | ||
|
||
When casting a numeric input array to bool, a value of ``0`` must cast | ||
to `False`, and a non-zero value must cast to `True`. | ||
|
||
Args: | ||
x: The array to cast. | ||
dtype: desired data type. | ||
copy: specifies whether to copy an array when the specified `dtype` | ||
matches the data type of the input array `x`. If `True`, a newly | ||
allocated array must always be returned. If `False` and the | ||
specified `dtype` matches the data type of the input array, the | ||
input array must be returned; otherwise, a newly allocated must be | ||
returned. Default: `True`. | ||
|
||
""" # noqa: E501 | ||
|
||
def __call__( | ||
self, x: HasDType[DTypeT], dtype: ToDTypeT, /, *, copy: bool = True | ||
) -> HasDType[ToDTypeT]: ... | ||
|
||
|
||
class HasAsType(Protocol): | ||
"""Protocol for namespaces that have an ``astype`` function.""" | ||
|
||
astype: DoesAsType | ||
|
||
|
||
# =================================================================== | ||
# Element-wise Functions | ||
# TODO: abs, acos, acosh, add, asin, asinh, atan, atan2, atanh, bitwise_and, | ||
# bitwise_invert, bitwise_left_shift, bitwise_or, bitwise_right_shift, | ||
# bitwise_xor, ceil, cos, cosh, divide, equal, exp, exp2, expm1, floor, | ||
# floor_divide, greater, greater_equal, isfinite, isinf, isnan, less, | ||
# less_equal, log, log1p, log2, log10, logical_and, logical_not, logical_or, | ||
# logical_xor, multiply, negative, not_equal, positive, pow, remainder, round, | ||
# sign, sin, sinh, square, sqrt, subtract, tan, tanh, trunc | ||
|
||
|
||
# =================================================================== | ||
# Linear Algebra Functions | ||
# TODO: matmul, matrix_transpose, tensordot, vecdot | ||
|
||
# =================================================================== | ||
# Manipulation Functions | ||
# TODO: concat, expand_dims, flip, permute_dims, reshape, roll, squeeze, stack | ||
|
||
# =================================================================== | ||
# Searching Functions | ||
# TODO: argmax, argmin, nonzero, where | ||
|
||
# =================================================================== | ||
# Set Functions | ||
# TODO: unique_all, unique_counts, unique_inverse, unique_values | ||
|
||
# =================================================================== | ||
# Sorting Functions | ||
# TODO: argsort, sort | ||
|
||
# =================================================================== | ||
# Statistical Functions | ||
# TODO: max, mean, min, prod, std, sum, var | ||
|
||
# =================================================================== | ||
# Utility Functions | ||
# TODO: all, any | ||
|
||
# =================================================================== | ||
# Full Namespace | ||
|
||
|
||
class ArrayNamespace( | ||
# Data Type Functions | ||
HasAsType, | ||
Protocol, | ||
): | ||
"""Protocol for an Array API-compatible namespace.""" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These empty files snuck in. I'll remove when rebasing after #34 is in.