From b958f0f2f0716097bb6799d00ca6d7ee2e5e67fa Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 15 Jan 2026 06:04:58 -0800 Subject: [PATCH 1/6] Update dpnp.fix by reusing trunc and align docs with NumPy --- dpnp/dpnp_iface_mathematical.py | 96 +++++++++++++++------------------ 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 3dc5ccb8288..6a14ede2406 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -66,7 +66,6 @@ DPNPBinaryFunc, DPNPBinaryFuncOutKw, DPNPBinaryTwoOutputsFunc, - DPNPFix, DPNPImag, DPNPReal, DPNPRound, @@ -1813,66 +1812,57 @@ def ediff1d(ary, to_end=None, to_begin=None): ) -_FIX_DOCSTRING = """ -Round to nearest integer towards zero. - -Round an array of floats element-wise to nearest integer towards zero. -The rounded values have the same data-type as the input. - -For full documentation refer to :obj:`numpy.fix`. +def fix(x, out=None): + """ + Round to nearest integer towards zero. -Parameters ----------- -x : {dpnp.ndarray, usm_ndarray} - Input array, expected to have a boolean or real-valued data type. -out : {None, dpnp.ndarray, usm_ndarray, tuple of ndarray}, optional - Output array to populate. - Array must have the correct shape and the expected data type. - A tuple (possible only as a keyword argument) must have length equal to the - number of outputs. + Round an array of floats element-wise to nearest integer towards zero. + The rounded values have the same data-type as the input. - Default: ``None``. -order : {None, "C", "F", "A", "K"}, optional - Memory layout of the newly output array, if parameter `out` is ``None``. + For full documentation refer to :obj:`numpy.fix`. - Default: ``"K"``. + Parameters + ---------- + x : {dpnp.ndarray, usm_ndarray} + Input array, expected to have a boolean or real-valued data type. + out : {None, dpnp.ndarray, usm_ndarray, tuple of ndarray}, optional + Output array to populate. + Array must have the correct shape and the expected data type. + A tuple (possible only as a keyword argument) must have length equal to + the number of outputs. -Returns -------- -out : dpnp.ndarray - An array with the same dimensions and data-type as the input. - If `out` is ``None`` then a new array is returned - with the rounded values. - Otherwise the result is stored there and the return value `out` is - a reference to that array. + Default: ``None``. -See Also --------- -:obj:`dpnp.round` : Round to given number of decimals. -:obj:`dpnp.rint` : Round elements of the array to the nearest integer. -:obj:`dpnp.trunc` : Return the truncated value of the input, element-wise. -:obj:`dpnp.floor` : Return the floor of the input, element-wise. -:obj:`dpnp.ceil` : Return the ceiling of the input, element-wise. + Returns + ------- + out : dpnp.ndarray + An array with the same dimensions and data-type as the input. + If `out` is ``None`` then a new array is returned + with the rounded values. + Otherwise the result is stored there and the return value `out` is + a reference to that array. -Examples --------- ->>> import dpnp as np ->>> np.fix(np.array(3.14)) -array(3.) ->>> np.fix(np.array(3)) -array(3.) ->>> a = np.array([2.1, 2.9, -2.1, -2.9]) ->>> np.fix(a) -array([ 2., 2., -2., -2.]) + See Also + -------- + :obj:`dpnp.round` : Round to given number of decimals. + :obj:`dpnp.rint` : Round elements of the array to the nearest integer. + :obj:`dpnp.trunc` : Return the truncated value of the input, element-wise. + :obj:`dpnp.floor` : Return the floor of the input, element-wise. + :obj:`dpnp.ceil` : Return the ceiling of the input, element-wise. -""" + Examples + -------- + >>> import dpnp as np + >>> np.fix(np.array(3.14)) + array(3.) + >>> np.fix(np.array(3)) + array(3.) + >>> a = np.array([2.1, 2.9, -2.1, -2.9]) + >>> np.fix(a) + array([ 2., 2., -2., -2.]) + """ -fix = DPNPFix( - "fix", - ufi._fix_result_type, - ufi._fix, - _FIX_DOCSTRING, -) + return trunc(x, out=out) _FLOAT_POWER_DOCSTRING = """ From 74424d0d3001fbf804698e4a1e9b9d8200c10db9 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 15 Jan 2026 06:06:13 -0800 Subject: [PATCH 2/6] Remove backend implementation of dpnp.fix --- dpnp/backend/extensions/ufunc/CMakeLists.txt | 1 - .../ufunc/elementwise_functions/common.cpp | 2 - .../ufunc/elementwise_functions/fix.cpp | 131 ------------------ .../ufunc/elementwise_functions/fix.hpp | 38 ----- .../kernels/elementwise_functions/fix.hpp | 52 ------- dpnp/dpnp_algo/dpnp_elementwise_common.py | 50 ------- 6 files changed, 274 deletions(-) delete mode 100644 dpnp/backend/extensions/ufunc/elementwise_functions/fix.cpp delete mode 100644 dpnp/backend/extensions/ufunc/elementwise_functions/fix.hpp delete mode 100644 dpnp/backend/kernels/elementwise_functions/fix.hpp diff --git a/dpnp/backend/extensions/ufunc/CMakeLists.txt b/dpnp/backend/extensions/ufunc/CMakeLists.txt index 5609522f58a..b24d5d131cf 100644 --- a/dpnp/backend/extensions/ufunc/CMakeLists.txt +++ b/dpnp/backend/extensions/ufunc/CMakeLists.txt @@ -34,7 +34,6 @@ set(_elementwise_sources ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/divmod.cpp ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/erf_funcs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fabs.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fix.cpp ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/float_power.cpp ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fmax.cpp ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fmin.cpp diff --git a/dpnp/backend/extensions/ufunc/elementwise_functions/common.cpp b/dpnp/backend/extensions/ufunc/elementwise_functions/common.cpp index df409464a5c..9254e87e52c 100644 --- a/dpnp/backend/extensions/ufunc/elementwise_functions/common.cpp +++ b/dpnp/backend/extensions/ufunc/elementwise_functions/common.cpp @@ -33,7 +33,6 @@ #include "divmod.hpp" #include "erf_funcs.hpp" #include "fabs.hpp" -#include "fix.hpp" #include "float_power.hpp" #include "fmax.hpp" #include "fmin.hpp" @@ -67,7 +66,6 @@ void init_elementwise_functions(py::module_ m) init_divmod(m); init_erf_funcs(m); init_fabs(m); - init_fix(m); init_float_power(m); init_fmax(m); init_fmin(m); diff --git a/dpnp/backend/extensions/ufunc/elementwise_functions/fix.cpp b/dpnp/backend/extensions/ufunc/elementwise_functions/fix.cpp deleted file mode 100644 index 6b21245489f..00000000000 --- a/dpnp/backend/extensions/ufunc/elementwise_functions/fix.cpp +++ /dev/null @@ -1,131 +0,0 @@ -//***************************************************************************** -// Copyright (c) 2024, Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// - Neither the name of the copyright holder nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -//***************************************************************************** - -#include -#include - -#include - -#include "dpctl4pybind11.hpp" - -#include "fix.hpp" -#include "kernels/elementwise_functions/fix.hpp" -#include "populate.hpp" - -// include a local copy of elementwise common header from dpctl tensor: -// dpctl/tensor/libtensor/source/elementwise_functions/elementwise_functions.hpp -// TODO: replace by including dpctl header once available -#include "../../elementwise_functions/elementwise_functions.hpp" - -// dpctl tensor headers -#include "kernels/elementwise_functions/common.hpp" -#include "utils/type_dispatch.hpp" - -namespace dpnp::extensions::ufunc -{ -namespace py = pybind11; -namespace py_int = dpnp::extensions::py_internal; - -namespace impl -{ -namespace ew_cmn_ns = dpctl::tensor::kernels::elementwise_common; -namespace td_ns = dpctl::tensor::type_dispatch; - -/** - * @brief A factory to define pairs of supported types for which - * sycl::fix function is available. - * - * @tparam T Type of input vector `a` and of result vector `y`. - */ -template -struct OutputType -{ - using value_type = - typename std::disjunction, - td_ns::TypeMapResultEntry, - td_ns::TypeMapResultEntry, - td_ns::DefaultResultEntry>::result_type; -}; - -using dpnp::kernels::fix::FixFunctor; - -template -using ContigFunctor = ew_cmn_ns::UnaryContigFunctor, - vec_sz, - n_vecs, - enable_sg_loadstore>; - -template -using StridedFunctor = ew_cmn_ns:: - UnaryStridedFunctor>; - -using ew_cmn_ns::unary_contig_impl_fn_ptr_t; -using ew_cmn_ns::unary_strided_impl_fn_ptr_t; - -static unary_contig_impl_fn_ptr_t fix_contig_dispatch_vector[td_ns::num_types]; -static int fix_output_typeid_vector[td_ns::num_types]; -static unary_strided_impl_fn_ptr_t - fix_strided_dispatch_vector[td_ns::num_types]; - -MACRO_POPULATE_DISPATCH_VECTORS(fix); -} // namespace impl - -void init_fix(py::module_ m) -{ - using arrayT = dpctl::tensor::usm_ndarray; - using event_vecT = std::vector; - { - impl::populate_fix_dispatch_vectors(); - using impl::fix_contig_dispatch_vector; - using impl::fix_output_typeid_vector; - using impl::fix_strided_dispatch_vector; - - auto fix_pyapi = [&](const arrayT &src, const arrayT &dst, - sycl::queue &exec_q, - const event_vecT &depends = {}) { - return py_int::py_unary_ufunc( - src, dst, exec_q, depends, fix_output_typeid_vector, - fix_contig_dispatch_vector, fix_strided_dispatch_vector); - }; - m.def("_fix", fix_pyapi, "", py::arg("src"), py::arg("dst"), - py::arg("sycl_queue"), py::arg("depends") = py::list()); - - auto fix_result_type_pyapi = [&](const py::dtype &dtype) { - return py_int::py_unary_ufunc_result_type(dtype, - fix_output_typeid_vector); - }; - m.def("_fix_result_type", fix_result_type_pyapi); - } -} -} // namespace dpnp::extensions::ufunc diff --git a/dpnp/backend/extensions/ufunc/elementwise_functions/fix.hpp b/dpnp/backend/extensions/ufunc/elementwise_functions/fix.hpp deleted file mode 100644 index f9fed62cf81..00000000000 --- a/dpnp/backend/extensions/ufunc/elementwise_functions/fix.hpp +++ /dev/null @@ -1,38 +0,0 @@ -//***************************************************************************** -// Copyright (c) 2024, Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// - Neither the name of the copyright holder nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -//***************************************************************************** - -#pragma once - -#include - -namespace py = pybind11; - -namespace dpnp::extensions::ufunc -{ -void init_fix(py::module_ m); -} // namespace dpnp::extensions::ufunc diff --git a/dpnp/backend/kernels/elementwise_functions/fix.hpp b/dpnp/backend/kernels/elementwise_functions/fix.hpp deleted file mode 100644 index f53bfc17e56..00000000000 --- a/dpnp/backend/kernels/elementwise_functions/fix.hpp +++ /dev/null @@ -1,52 +0,0 @@ -//***************************************************************************** -// Copyright (c) 2024, Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// - Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// - Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// - Neither the name of the copyright holder nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -// THE POSSIBILITY OF SUCH DAMAGE. -//***************************************************************************** - -#pragma once - -#include - -namespace dpnp::kernels::fix -{ -template -struct FixFunctor -{ - // is function constant for given argT - using is_constant = typename std::false_type; - // constant value, if constant - // constexpr resT constant_value = resT{}; - // is function defined for sycl::vec - using supports_vec = typename std::false_type; - // do both argT and resT support subgroup store/load operation - using supports_sg_loadstore = typename std::true_type; - - resT operator()(const argT &x) const - { - return (x >= 0.0) ? sycl::floor(x) : sycl::ceil(x); - } -}; -} // namespace dpnp::kernels::fix diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 60a55acd1f4..c404d71dfbc 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -60,7 +60,6 @@ "DPNPBinaryFunc", "DPNPBinaryFuncOutKw", "DPNPBinaryTwoOutputsFunc", - "DPNPFix", "DPNPImag", "DPNPReal", "DPNPRound", @@ -1188,55 +1187,6 @@ def __call__(self, x, /, deg=False, *, out=None, order="K"): return res -class DPNPFix(DPNPUnaryFunc): - """Class that implements dpnp.fix unary element-wise functions.""" - - def __init__( - self, - name, - result_type_resolver_fn, - unary_dp_impl_fn, - docs, - ): - super().__init__( - name, - result_type_resolver_fn, - unary_dp_impl_fn, - docs, - ) - - def __call__(self, x, /, out=None, *, order="K"): - if not dpnp.is_supported_array_type(x): - pass # pass to raise error in main implementation - elif dpnp.issubdtype(x.dtype, dpnp.inexact): - pass # for inexact types, pass to calculate in the backend - elif not ( - out is None - or isinstance(out, tuple) - or dpnp.is_supported_array_type(out) - ): - pass # pass to raise error in main implementation - elif not ( - out is None or isinstance(out, tuple) or out.dtype == x.dtype - ): - # passing will raise an error but with incorrect needed dtype - raise ValueError( - f"Output array of type {x.dtype} is needed, got {out.dtype}" - ) - else: - # for exact types, return the input - out = self._unpack_out_kw(out) - if out is None: - return dpnp.copy(x, order=order) - - if isinstance(out, dpt.usm_ndarray): - out = dpnp_array._create_from_usm_ndarray(out) - out[...] = x - return out - - return super().__call__(x, out=out, order=order) - - class DPNPI0(DPNPUnaryFunc): """Class that implements dpnp.i0 unary element-wise functions.""" From 58b6368a9c58480768322317f549fb6c973cbb5c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 15 Jan 2026 06:48:02 -0800 Subject: [PATCH 3/6] Add test_out_wrong_tuple_len for rounding functions --- dpnp/tests/test_mathematical.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index 77c65991e9c..193beedce13 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2020,9 +2020,7 @@ def test_out_dtype(self, func): fn(*args, out=out, dtype="f4") @pytest.mark.parametrize("xp", [numpy, dpnp]) - @pytest.mark.parametrize( - "func", ["abs", "fix", "round", "add", "frexp", "divmod"] - ) + @pytest.mark.parametrize("func", ["abs", "round", "add", "frexp", "divmod"]) def test_out_wrong_tuple_len(self, xp, func): if func == "round" and xp is numpy: pytest.skip("numpy.round(x, out=(...)) is not supported") @@ -2607,6 +2605,15 @@ def test_out_usm_ndarray(self, func, dt): assert result.get_array() is usm_out assert_array_equal(result, expected) + @pytest.mark.parametrize("xp", [numpy, dpnp]) + def test_out_wrong_tuple_len(self, xp, func): + a = xp.array([1.1, -2.9, 3.5]) + + out1 = xp.empty_like(a) + out2 = xp.empty_like(a) + + assert_raises(ValueError, getattr(xp, func), a, out=(out1, out2)) + @pytest.mark.parametrize("xp", [numpy, dpnp]) @pytest.mark.parametrize( "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15,)", "(2, 2)"] From 07d2866f57823a9108f04bdda2fed695bbfcb8eb Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 15 Jan 2026 07:04:37 -0800 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bd28a21d19..d16c637b285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum * Unified `dpnp` public API exports by consolidating function exports in `__init__.py` and removing wildcard imports [#2665](https://github.com/IntelPython/dpnp/pull/2665) [#2666](https://github.com/IntelPython/dpnp/pull/2666) * Updated tests to reflect the new scalar conversion rules for non-0D `usm_ndarray` [#2694](https://github.com/IntelPython/dpnp/pull/2694) * Compile indexing extension with `-fno-sycl-id-queries-fit-in-int` to support huge arrays [#2721](https://github.com/IntelPython/dpnp/pull/2721) +* Updated `dpnp.fix` to reuse `dpnp.trunc` internally [#2722](https://github.com/IntelPython/dpnp/pull/2722) ### Deprecated From a83c0d45310de1fd439dc98476009e9bf8a2a27b Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 16 Jan 2026 04:19:34 -0800 Subject: [PATCH 5/6] Keep dpnp.fix ufunc-like using trunc backend --- dpnp/dpnp_iface_mathematical.py | 98 ++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 6a14ede2406..63aee599d9b 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -1812,57 +1812,69 @@ def ediff1d(ary, to_end=None, to_begin=None): ) -def fix(x, out=None): - """ - Round to nearest integer towards zero. +_FIX_DOCSTRING = """ +Round to nearest integer towards zero. - Round an array of floats element-wise to nearest integer towards zero. - The rounded values have the same data-type as the input. +Round an array of floats element-wise to nearest integer towards zero. +The rounded values have the same data-type as the input. - For full documentation refer to :obj:`numpy.fix`. +For full documentation refer to :obj:`numpy.fix`. - Parameters - ---------- - x : {dpnp.ndarray, usm_ndarray} - Input array, expected to have a boolean or real-valued data type. - out : {None, dpnp.ndarray, usm_ndarray, tuple of ndarray}, optional - Output array to populate. - Array must have the correct shape and the expected data type. - A tuple (possible only as a keyword argument) must have length equal to - the number of outputs. +Parameters +---------- +x : {dpnp.ndarray, usm_ndarray} + Input array, expected to have a boolean or real-valued data type. +out : {None, dpnp.ndarray, usm_ndarray, tuple of ndarray}, optional + Output array to populate. + Array must have the correct shape and the expected data type. + A tuple (possible only as a keyword argument) must have length equal to the + number of outputs. - Default: ``None``. + Default: ``None``. +order : {None, "C", "F", "A", "K"}, optional + Memory layout of the newly output array, if parameter `out` is ``None``. - Returns - ------- - out : dpnp.ndarray - An array with the same dimensions and data-type as the input. - If `out` is ``None`` then a new array is returned - with the rounded values. - Otherwise the result is stored there and the return value `out` is - a reference to that array. + Default: ``"K"``. - See Also - -------- - :obj:`dpnp.round` : Round to given number of decimals. - :obj:`dpnp.rint` : Round elements of the array to the nearest integer. - :obj:`dpnp.trunc` : Return the truncated value of the input, element-wise. - :obj:`dpnp.floor` : Return the floor of the input, element-wise. - :obj:`dpnp.ceil` : Return the ceiling of the input, element-wise. +Returns +------- +out : dpnp.ndarray + An array with the same dimensions and data-type as the input. + If `out` is ``None`` then a new array is returned + with the rounded values. + Otherwise the result is stored there and the return value `out` is + a reference to that array. - Examples - -------- - >>> import dpnp as np - >>> np.fix(np.array(3.14)) - array(3.) - >>> np.fix(np.array(3)) - array(3.) - >>> a = np.array([2.1, 2.9, -2.1, -2.9]) - >>> np.fix(a) - array([ 2., 2., -2., -2.]) - """ +See Also +-------- +:obj:`dpnp.round` : Round to given number of decimals. +:obj:`dpnp.rint` : Round elements of the array to the nearest integer. +:obj:`dpnp.trunc` : Return the truncated value of the input, element-wise. +:obj:`dpnp.floor` : Return the floor of the input, element-wise. +:obj:`dpnp.ceil` : Return the ceiling of the input, element-wise. + +Examples +-------- +>>> import dpnp as np +>>> np.fix(np.array(3.14)) +array(3.) +>>> np.fix(np.array(3)) +array(3.) +>>> a = np.array([2.1, 2.9, -2.1, -2.9]) +>>> np.fix(a) +array([ 2., 2., -2., -2.]) + +""" - return trunc(x, out=out) +# reuse trunc backend implementation for fix +fix = DPNPUnaryFunc( + "fix", + ti._trunc_result_type, + ti._trunc, + _FIX_DOCSTRING, + mkl_fn_to_call="_mkl_trunc_to_call", + mkl_impl_fn="_trunc", +) _FLOAT_POWER_DOCSTRING = """ From 88ff017c741db112f59e6c27a355e7bec679a98f Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Fri, 16 Jan 2026 04:23:15 -0800 Subject: [PATCH 6/6] Revert extending rounding tests --- dpnp/tests/test_mathematical.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index 193beedce13..77c65991e9c 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2020,7 +2020,9 @@ def test_out_dtype(self, func): fn(*args, out=out, dtype="f4") @pytest.mark.parametrize("xp", [numpy, dpnp]) - @pytest.mark.parametrize("func", ["abs", "round", "add", "frexp", "divmod"]) + @pytest.mark.parametrize( + "func", ["abs", "fix", "round", "add", "frexp", "divmod"] + ) def test_out_wrong_tuple_len(self, xp, func): if func == "round" and xp is numpy: pytest.skip("numpy.round(x, out=(...)) is not supported") @@ -2605,15 +2607,6 @@ def test_out_usm_ndarray(self, func, dt): assert result.get_array() is usm_out assert_array_equal(result, expected) - @pytest.mark.parametrize("xp", [numpy, dpnp]) - def test_out_wrong_tuple_len(self, xp, func): - a = xp.array([1.1, -2.9, 3.5]) - - out1 = xp.empty_like(a) - out2 = xp.empty_like(a) - - assert_raises(ValueError, getattr(xp, func), a, out=(out1, out2)) - @pytest.mark.parametrize("xp", [numpy, dpnp]) @pytest.mark.parametrize( "shape", [(0,), (15,), (2, 2)], ids=["(0,)", "(15,)", "(2, 2)"]