-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User driven getitem and construction (#60)
- Loading branch information
1 parent
6d74551
commit 60c3bd2
Showing
13 changed files
with
352 additions
and
74 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
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,50 @@ | ||
# Copyright (c) QuantCo 2023-2024 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
from spox import Tensor, argument | ||
|
||
import ndonnx as ndx | ||
import ndonnx._data_types as dtypes | ||
import ndonnx.additional as nda | ||
from ndonnx._corearray import _CoreArray | ||
|
||
from ._interface import OperationsBlock | ||
from ._utils import validate_core | ||
|
||
if TYPE_CHECKING: | ||
from ndonnx._array import Array | ||
from ndonnx._data_types import Dtype | ||
|
||
|
||
class CoreOperationsImpl(OperationsBlock): | ||
def make_array( | ||
self, | ||
shape: tuple[int | None | str, ...], | ||
dtype: Dtype, | ||
eager_value: np.ndarray | None = None, | ||
) -> Array: | ||
if not isinstance(dtype, dtypes.CoreType): | ||
return NotImplemented | ||
return ndx.Array._from_fields( | ||
dtype, | ||
data=_CoreArray( | ||
dtype._parse_input(eager_value)["data"] | ||
if eager_value is not None | ||
else argument(Tensor(dtype.to_numpy_dtype(), shape)) | ||
), | ||
) | ||
|
||
@validate_core | ||
def make_nullable(self, x: Array, null: Array) -> Array: | ||
if null.dtype != ndx.bool: | ||
raise TypeError("'null' must be a boolean array") | ||
|
||
return ndx.Array._from_fields( | ||
dtypes.into_nullable(x.dtype), | ||
values=x.copy(), | ||
null=ndx.broadcast_to(null, nda.shape(x)), | ||
) |
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,16 +1,29 @@ | ||
# Copyright (c) QuantCo 2023-2024 | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Union | ||
|
||
import ndonnx as ndx | ||
|
||
from ._interface import OperationsBlock | ||
from ._utils import validate_core | ||
|
||
if TYPE_CHECKING: | ||
from ndonnx._array import Array | ||
from ndonnx._data_types import CoreType, StructType | ||
|
||
Dtype = Union[CoreType, StructType] | ||
|
||
|
||
class NullableOperationsImpl(OperationsBlock): | ||
@validate_core | ||
def fill_null(self, x, value): | ||
def fill_null(self, x: Array, value) -> Array: | ||
value = ndx.asarray(value) | ||
if value.dtype != x.values.dtype: | ||
value = value.astype(x.values.dtype) | ||
return ndx.where(x.null, value, x.values) | ||
|
||
@validate_core | ||
def make_nullable(self, x: Array, null: Array) -> Array: | ||
return NotImplemented |
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.