-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef53f7d
commit 0a0802e
Showing
10 changed files
with
564 additions
and
733 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
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 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,45 @@ | ||
import numpy as np | ||
|
||
from ._dtypes import DType | ||
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) -> type[DType]: | ||
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) -> "Array": | ||
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 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.