-
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.
Merge remote-tracking branch 'origin/main' into update-api-tests-with…
…out-complex
- Loading branch information
Showing
21 changed files
with
693 additions
and
161 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
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,58 @@ | ||
# 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 ._shapeimpl import UniformShapeOperations | ||
from ._utils import validate_core | ||
|
||
if TYPE_CHECKING: | ||
from ndonnx._array import Array | ||
from ndonnx._data_types import Dtype | ||
|
||
|
||
class CoreOperationsImpl(UniformShapeOperations): | ||
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)), | ||
) | ||
|
||
@validate_core | ||
def where(self, condition, x, y): | ||
if x.dtype != y.dtype: | ||
target_dtype = ndx.result_type(x, y) | ||
x = ndx.astype(x, target_dtype) | ||
y = ndx.astype(y, target_dtype) | ||
return super().where(condition, x, y) |
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,37 @@ | ||
# 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 ._shapeimpl import UniformShapeOperations | ||
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): | ||
|
||
class NullableOperationsImpl(UniformShapeOperations): | ||
@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 | ||
|
||
@validate_core | ||
def where(self, condition, x, y): | ||
if x.dtype != y.dtype: | ||
target_dtype = ndx.result_type(x, y) | ||
x = ndx.astype(x, target_dtype) | ||
y = ndx.astype(y, target_dtype) | ||
return super().where(condition, x, y) |
Oops, something went wrong.