Skip to content

Commit 7b73f74

Browse files
Refactor dpnp.fix() to reuse dpnp.trunc internally (#2722)
This PR rewrites `dpnp.fix` to reuse `dpnp.trunc` internally removing the backend implementation of `dpnp.fix`
1 parent 96bb408 commit 7b73f74

File tree

8 files changed

+7
-278
lines changed

8 files changed

+7
-278
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Also, that release drops support for Python 3.9, making Python 3.10 the minimum
4242
* 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)
4343
* Updated tests to reflect the new scalar conversion rules for non-0D `usm_ndarray` [#2694](https://github.com/IntelPython/dpnp/pull/2694)
4444
* Compile indexing extension with `-fno-sycl-id-queries-fit-in-int` to support huge arrays [#2721](https://github.com/IntelPython/dpnp/pull/2721)
45+
* Updated `dpnp.fix` to reuse `dpnp.trunc` internally [#2722](https://github.com/IntelPython/dpnp/pull/2722)
4546

4647
### Deprecated
4748

dpnp/backend/extensions/ufunc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ set(_elementwise_sources
3434
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/divmod.cpp
3535
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/erf_funcs.cpp
3636
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fabs.cpp
37-
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fix.cpp
3837
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/float_power.cpp
3938
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fmax.cpp
4039
${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/fmin.cpp

dpnp/backend/extensions/ufunc/elementwise_functions/common.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "divmod.hpp"
3434
#include "erf_funcs.hpp"
3535
#include "fabs.hpp"
36-
#include "fix.hpp"
3736
#include "float_power.hpp"
3837
#include "fmax.hpp"
3938
#include "fmin.hpp"
@@ -67,7 +66,6 @@ void init_elementwise_functions(py::module_ m)
6766
init_divmod(m);
6867
init_erf_funcs(m);
6968
init_fabs(m);
70-
init_fix(m);
7169
init_float_power(m);
7270
init_fmax(m);
7371
init_fmin(m);

dpnp/backend/extensions/ufunc/elementwise_functions/fix.cpp

Lines changed: 0 additions & 131 deletions
This file was deleted.

dpnp/backend/extensions/ufunc/elementwise_functions/fix.hpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

dpnp/backend/kernels/elementwise_functions/fix.hpp

Lines changed: 0 additions & 52 deletions
This file was deleted.

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"DPNPBinaryFunc",
6161
"DPNPBinaryFuncOutKw",
6262
"DPNPBinaryTwoOutputsFunc",
63-
"DPNPFix",
6463
"DPNPImag",
6564
"DPNPReal",
6665
"DPNPRound",
@@ -1188,55 +1187,6 @@ def __call__(self, x, /, deg=False, *, out=None, order="K"):
11881187
return res
11891188

11901189

1191-
class DPNPFix(DPNPUnaryFunc):
1192-
"""Class that implements dpnp.fix unary element-wise functions."""
1193-
1194-
def __init__(
1195-
self,
1196-
name,
1197-
result_type_resolver_fn,
1198-
unary_dp_impl_fn,
1199-
docs,
1200-
):
1201-
super().__init__(
1202-
name,
1203-
result_type_resolver_fn,
1204-
unary_dp_impl_fn,
1205-
docs,
1206-
)
1207-
1208-
def __call__(self, x, /, out=None, *, order="K"):
1209-
if not dpnp.is_supported_array_type(x):
1210-
pass # pass to raise error in main implementation
1211-
elif dpnp.issubdtype(x.dtype, dpnp.inexact):
1212-
pass # for inexact types, pass to calculate in the backend
1213-
elif not (
1214-
out is None
1215-
or isinstance(out, tuple)
1216-
or dpnp.is_supported_array_type(out)
1217-
):
1218-
pass # pass to raise error in main implementation
1219-
elif not (
1220-
out is None or isinstance(out, tuple) or out.dtype == x.dtype
1221-
):
1222-
# passing will raise an error but with incorrect needed dtype
1223-
raise ValueError(
1224-
f"Output array of type {x.dtype} is needed, got {out.dtype}"
1225-
)
1226-
else:
1227-
# for exact types, return the input
1228-
out = self._unpack_out_kw(out)
1229-
if out is None:
1230-
return dpnp.copy(x, order=order)
1231-
1232-
if isinstance(out, dpt.usm_ndarray):
1233-
out = dpnp_array._create_from_usm_ndarray(out)
1234-
out[...] = x
1235-
return out
1236-
1237-
return super().__call__(x, out=out, order=order)
1238-
1239-
12401190
class DPNPI0(DPNPUnaryFunc):
12411191
"""Class that implements dpnp.i0 unary element-wise functions."""
12421192

dpnp/dpnp_iface_mathematical.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
DPNPBinaryFunc,
6767
DPNPBinaryFuncOutKw,
6868
DPNPBinaryTwoOutputsFunc,
69-
DPNPFix,
7069
DPNPImag,
7170
DPNPReal,
7271
DPNPRound,
@@ -1867,11 +1866,14 @@ def ediff1d(ary, to_end=None, to_begin=None):
18671866
18681867
"""
18691868

1870-
fix = DPNPFix(
1869+
# reuse trunc backend implementation for fix
1870+
fix = DPNPUnaryFunc(
18711871
"fix",
1872-
ufi._fix_result_type,
1873-
ufi._fix,
1872+
ti._trunc_result_type,
1873+
ti._trunc,
18741874
_FIX_DOCSTRING,
1875+
mkl_fn_to_call="_mkl_trunc_to_call",
1876+
mkl_impl_fn="_trunc",
18751877
)
18761878

18771879

0 commit comments

Comments
 (0)