Skip to content

Commit 0b3184f

Browse files
Change asfarray func and fix tests for it
1 parent d1a90bc commit 0b3184f

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

dpnp/dpnp_iface_manipulation.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
]
7474

7575

76-
def asfarray(x1, dtype=numpy.float64):
76+
def asfarray(x1, dtype=None):
7777
"""
7878
Return an array converted to a float type.
7979
@@ -87,9 +87,10 @@ def asfarray(x1, dtype=numpy.float64):
8787

8888
x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
8989
if x1_desc:
90-
# behavior of original function: int types replaced with float64
91-
if numpy.issubdtype(dtype, numpy.integer):
92-
dtype = numpy.float64
90+
# int types replaced with a floating type by default in DPNP
91+
# depending on device capabilities.
92+
if dtype is None or numpy.issubdtype(dtype, numpy.integer):
93+
dtype = dpnp.default_float_type()
9394

9495
# if type is the same then same object should be returned
9596
if x1_desc.dtype == dtype:

tests/test_arraymanipulation.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
import pytest
2+
from .helper import get_all_dtypes
23

34
import dpnp
45
import numpy
56

67

78
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
8-
@pytest.mark.parametrize("dtype",
9-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
10-
ids=["float64", "float32", "int64", "int32"])
11-
@pytest.mark.parametrize("data",
12-
[[1, 2, 3], [1., 2., 3.]],
13-
ids=["[1, 2, 3]", "[1., 2., 3.]"])
9+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
10+
@pytest.mark.parametrize(
11+
"data", [[1, 2, 3], [1.0, 2.0, 3.0]], ids=["[1, 2, 3]", "[1., 2., 3.]"]
12+
)
1413
def test_asfarray(dtype, data):
1514
expected = numpy.asfarray(data, dtype)
1615
result = dpnp.asfarray(data, dtype)
1716

1817
numpy.testing.assert_array_equal(result, expected)
1918

2019

21-
@pytest.mark.parametrize("dtype",
22-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
23-
ids=["float64", "float32", "int64", "int32"])
24-
@pytest.mark.parametrize("data",
25-
[[1, 2, 3], [1., 2., 3.]],
26-
ids=["[1, 2, 3]", "[1., 2., 3.]"])
20+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
21+
@pytest.mark.parametrize(
22+
"data", [[1, 2, 3], [1.0, 2.0, 3.0]], ids=["[1, 2, 3]", "[1., 2., 3.]"]
23+
)
2724
def test_asfarray2(dtype, data):
2825
expected = numpy.asfarray(numpy.array(data), dtype)
2926
result = dpnp.asfarray(dpnp.array(data), dtype)
@@ -59,7 +56,9 @@ def test_concatenate(self):
5956
numpy.testing.assert_array_equal(dpnp.concatenate((r4, r3)), r4 + r3)
6057
# Mixed sequence types
6158
numpy.testing.assert_array_equal(dpnp.concatenate((tuple(r4), r3)), r4 + r3)
62-
numpy.testing.assert_array_equal(dpnp.concatenate((dpnp.array(r4), r3)), r4 + r3)
59+
numpy.testing.assert_array_equal(
60+
dpnp.concatenate((dpnp.array(r4), r3)), r4 + r3
61+
)
6362
# Explicit axis specification
6463
numpy.testing.assert_array_equal(dpnp.concatenate((r4, r3), 0), r4 + r3)
6564
# Including negative

0 commit comments

Comments
 (0)