-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nstarman <[email protected]>
- Loading branch information
Showing
8 changed files
with
184 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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 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 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,17 @@ | ||
"""Minimal definition of the Array API.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any, Protocol | ||
|
||
|
||
class HasArrayNameSpace(Protocol): | ||
"""Minimal defintion of the Array API.""" | ||
|
||
def __array_namespace__(self) -> Any: ... | ||
|
||
|
||
class Array(HasArrayNameSpace, Protocol): | ||
"""Minimal defintion of the Array API.""" | ||
|
||
def __pow__(self, other: Any) -> Array: ... |
This file contains 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,24 @@ | ||
"""Minimal definition of the Quantity API.""" | ||
|
||
__all__ = ["Quantity", "ArrayQuantity", "Unit"] | ||
|
||
from typing import Protocol, runtime_checkable | ||
|
||
from astropy.units import UnitBase as Unit | ||
|
||
from ._array_api import Array | ||
|
||
|
||
@runtime_checkable | ||
class Quantity(Protocol): | ||
"""Minimal definition of the Quantity API.""" | ||
|
||
value: Array | ||
unit: Unit | ||
|
||
|
||
@runtime_checkable | ||
class ArrayQuantity(Quantity, Array, Protocol): | ||
"""An array-valued Quantity.""" | ||
|
||
... |
Empty file.
This file contains 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 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,13 @@ | ||
"""Utility functions for the quantity package.""" | ||
|
||
from typing import Any, TypeGuard | ||
|
||
import array_api_compat | ||
|
||
|
||
def has_array_namespace(arg: object) -> bool: | ||
def has_array_namespace(arg: Any) -> TypeGuard[Array]: | ||
try: | ||
array_api_compat.array_namespace(arg) | ||
except TypeError: | ||
return False | ||
else: | ||
return True | ||
return True |
This file contains 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