Skip to content

Commit

Permalink
Optimise and remove magic constants
Browse files Browse the repository at this point in the history
Signed-off-by: neNasko1 <nasko119@gmail.com>
  • Loading branch information
neNasko1 committed Jan 7, 2025
1 parent 6bd7b43 commit 3e22b77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ndonnx/_core/_numericimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ def bitwise_or(self, x, y):
@validate_core
def bitwise_right_shift(self, x, y):
# Since we need to perform arithmetic right-shift we have to be a bit more careful
if isinstance(x.dtype, (dtypes.Unsigned, dtypes.NullableUnsigned)):
return binary_op(
x, y, lambda a, b: opx.bit_shift(a, b, direction="RIGHT"), dtypes.uint64
)
MAX_POW = 63
return ndx.where(
y >= 63,
y >= MAX_POW,
ndx.where(x >= 0, 0, -1),
ndx.floor_divide(x, ndx.pow(ndx.asarray(2, ndx.int64), y)),
).astype(x.dtype)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) QuantCo 2023-2024
# Copyright (c) QuantCo 2023-2025
# SPDX-License-Identifier: BSD-3-Clause

from __future__ import annotations
Expand Down

0 comments on commit 3e22b77

Please sign in to comment.