Skip to content

Commit 48d36a4

Browse files
author
Vahid Tavanashad
committed
update dpnp.fix docstring
1 parent eb8ebf8 commit 48d36a4

File tree

5 files changed

+33
-43
lines changed

5 files changed

+33
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* Allowed input array of `uint64` dtype in `dpnp.bincount` [#2361](https://github.com/IntelPython/dpnp/pull/2361)
2020
* The vector norms `ord={None, 1, 2, inf}` and the matrix norms `ord={None, 1, 2, inf, "fro", "nuc"}` now consistently return zero for empty arrays, which are arrays with at least one axis of size zero. This change affects `dpnp.linalg.norm`, `dpnp.linalg.vector_norm`, and `dpnp.linalg.matrix_norm`. Previously, dpnp would either raise errors or return zero depending on the parameters provided [#2371](https://github.com/IntelPython/dpnp/pull/2371)
2121
* Improved performance of `dpnp.nansum`, `dpnp.nanprod`, `dpnp.nancumsum`, and `dpnp.nancumprod` by reusing `dpnp.nan_to_num` function in implementation of the functions [#2339](https://github.com/IntelPython/dpnp/pull/2339)
22+
* Updated `dpnp.fix` docstring to indicate that the output data-type will be a floating point dtype but not necessarily the default floating point dtype [#2392](https://github.com/IntelPython/dpnp/pull/2392)
2223

2324
### Fixed
2425

dpnp/dpnp_iface_mathematical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,8 +1750,8 @@ def ediff1d(ary, to_end=None, to_begin=None):
17501750
-------
17511751
out : dpnp.ndarray
17521752
An array with the rounded values and with the same dimensions as the input.
1753-
The returned array will have the default floating point data type for the
1754-
device where `a` is allocated.
1753+
The returned array will have a floating point data type that input can cast
1754+
to it safely considering device capabilities.
17551755
If `out` is ``None`` then a float array is returned with the rounded values.
17561756
Otherwise the result is stored there and the return value `out` is
17571757
a reference to that array.

dpnp/dpnp_iface_statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ def cov(
797797
Default: ``None``.
798798
dtype : {None, str, dtype object}, optional
799799
Data-type of the result. By default, the return data-type will have
800-
at least floating point type based on the capabilities of the device on
801-
which the input arrays reside.
800+
the default floating point data-type of the device on which the input
801+
arrays reside.
802802
803803
Default: ``None``.
804804

dpnp/tests/test_binary_ufuncs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ def test_float_nan(self, dt):
684684
expected = numpy.nextafter(numpy.nan, a)
685685
assert_equal(result, expected)
686686

687+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
687688
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
688689
def test_f16_strides(self, val):
689690
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
@@ -702,6 +703,7 @@ def test_f16_strides(self, val):
702703
expected = numpy.nextafter(a[1:], -hinf)
703704
assert_equal(result, expected)
704705

706+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
705707
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
706708
def test_f16_array_inf(self, val):
707709
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
@@ -716,6 +718,7 @@ def test_f16_array_inf(self, val):
716718
expected = numpy.nextafter(-hinf, a)
717719
assert_equal(result, expected)
718720

721+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
719722
@pytest.mark.parametrize(
720723
"sign1, sign2",
721724
[
@@ -734,6 +737,7 @@ def test_f16_inf(self, sign1, sign2):
734737
expected = numpy.nextafter(hinf1, hinf2)
735738
assert_equal(result, expected)
736739

740+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
737741
@pytest.mark.parametrize("val", [0x7C00, 0x8000], ids=["val1", "val2"])
738742
def test_f16_array_nan(self, val):
739743
a = numpy.arange(val, dtype=numpy.uint16).astype(numpy.float16)
@@ -748,6 +752,7 @@ def test_f16_array_nan(self, val):
748752
expected = numpy.nextafter(nan, a)
749753
assert_equal(result, expected)
750754

755+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
751756
@pytest.mark.parametrize(
752757
"val1, val2",
753758
[
@@ -765,6 +770,7 @@ def test_f16_inf_nan(self, val1, val2):
765770
expected = numpy.nextafter(v1, v2)
766771
assert_equal(result, expected)
767772

773+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
768774
@pytest.mark.parametrize(
769775
"val, scalar",
770776
[

dpnp/tests/test_mathematical.py

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,6 @@
3636
from .third_party.cupy import testing
3737

3838

39-
def _get_output_data_type(dtype):
40-
"""Return a data type specified by input `dtype` and device capabilities."""
41-
dtype_float16 = any(
42-
dpnp.issubdtype(dtype, t) for t in (dpnp.bool, dpnp.int8, dpnp.uint8)
43-
)
44-
dtype_float32 = any(
45-
dpnp.issubdtype(dtype, t) for t in (dpnp.int16, dpnp.uint16)
46-
)
47-
if dtype_float16:
48-
out_dtype = dpnp.float16 if has_support_aspect16() else dpnp.float32
49-
elif dtype_float32:
50-
out_dtype = dpnp.float32
51-
elif dpnp.issubdtype(dtype, dpnp.complexfloating):
52-
out_dtype = dpnp.complex64
53-
if has_support_aspect64() and dtype != dpnp.complex64:
54-
out_dtype = dpnp.complex128
55-
else:
56-
out_dtype = dpnp.float32
57-
if has_support_aspect64() and dtype != dpnp.float32:
58-
out_dtype = dpnp.float64
59-
60-
return out_dtype
61-
62-
6339
@pytest.mark.parametrize("deg", [True, False])
6440
class TestAngle:
6541
def test_angle_bool(self, deg):
@@ -775,6 +751,16 @@ def test_errors(self):
775751

776752

777753
class TestFix:
754+
def get_numpy_output_dtype(self, dtype):
755+
# this is used to determine the output dtype of numpy array
756+
# which is on cpu so no need for checking has_support_aspect64
757+
if has_support_aspect16() and dpnp.can_cast(dtype, dpnp.float16):
758+
return dpnp.float16
759+
if dpnp.can_cast(dtype, dpnp.float32):
760+
return dpnp.float32
761+
if dpnp.can_cast(dtype, dpnp.float64):
762+
return dpnp.float64
763+
778764
@pytest.mark.parametrize(
779765
"dt", get_all_dtypes(no_none=True, no_complex=True)
780766
)
@@ -794,28 +780,25 @@ def test_complex(self, xp, dt):
794780
xp.fix(a)
795781

796782
@pytest.mark.parametrize(
797-
"a_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
783+
"dt", get_all_dtypes(no_none=True, no_complex=True)
798784
)
799-
def test_out(self, a_dt):
800-
a = get_abs_array(
801-
[[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]], a_dt
802-
)
803-
ia = dpnp.array(a)
804-
805-
out_dt = _get_output_data_type(a.dtype)
806-
out = numpy.zeros_like(a, dtype=out_dt)
807-
iout = dpnp.array(out)
785+
def test_out(self, dt):
786+
data = [[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]
787+
a = get_abs_array(data, dtype=dt)
788+
# numpy output has the same dtype as input
789+
# dpnp output always has a floating point dtype
790+
dt_out = self.get_numpy_output_dtype(a.dtype)
791+
out = numpy.zeros_like(a, dtype=dt_out)
792+
ia, iout = dpnp.array(a), dpnp.array(out)
808793

809794
result = dpnp.fix(ia, out=iout)
810795
expected = numpy.fix(a, out=out)
811796
assert_array_equal(result, expected)
812797

813798
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
814-
@pytest.mark.parametrize("dt", [bool, numpy.float16])
815-
def test_out_float16(self, dt):
816-
a = numpy.array(
817-
[[1.0, 1.1], [1.5, 1.8], [-1.0, -1.1], [-1.5, -1.8]], dtype=dt
818-
)
799+
def test_out_float16(self):
800+
data = [[1.0, 1.1], [1.5, 1.8], [-1.0, -1.1], [-1.5, -1.8]]
801+
a = numpy.array(data, dtype=numpy.float16)
819802
out = numpy.zeros_like(a, dtype=numpy.float16)
820803
ia, iout = dpnp.array(a), dpnp.array(out)
821804

0 commit comments

Comments
 (0)