From ef0ac77c5fe39934b236c1ff0c847930fb77b859 Mon Sep 17 00:00:00 2001 From: Aditya Goel Date: Wed, 10 Jul 2024 15:17:06 +0200 Subject: [PATCH] truediv --- ndonnx/_core/_impl.py | 4 +++- tests/ndonnx/test_core.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ndonnx/_core/_impl.py b/ndonnx/_core/_impl.py index 39f76ec..1c0dc75 100644 --- a/ndonnx/_core/_impl.py +++ b/ndonnx/_core/_impl.py @@ -112,7 +112,9 @@ def cosh(self, x): return _unary_op(x, opx.cosh, dtypes.float32) def divide(self, x, y): - return _variadic_op([x, y], opx.div, via_dtype=dtypes.float64) + return _variadic_op( + [x, y], opx.div, via_dtype=dtypes.float64, cast_return=False + ) def equal(self, x, y) -> Array: x, y = promote(x, y) diff --git a/tests/ndonnx/test_core.py b/tests/ndonnx/test_core.py index 7cf3fca..ae39a99 100644 --- a/tests/ndonnx/test_core.py +++ b/tests/ndonnx/test_core.py @@ -531,3 +531,11 @@ def test_searchsorted_raises(): b = ndx.array(shape=(3,), dtype=ndx.int64) ndx.searchsorted(a, b, side="middle") # type: ignore[arg-type] + + +def test_truediv(): + x = ndx.asarray([1, 2, 3], dtype=ndx.int64) + y = ndx.asarray([2, 3, 3], dtype=ndx.int64) + z = x / y + assert isinstance(z.dtype, ndx.Floating) + np.testing.assert_array_equal(z.to_numpy(), np.array([0.5, 2 / 3, 1.0]))