Skip to content

Commit 38d42dc

Browse files
patch for shaped_arange func to exclude calls of astype and reshape (#929)
* patch for shaped_arange func to exclude calls of astype and reshape * fix iteration over a 0-d array * skip partition func test with unexpected behaviour
1 parent 33e4bf5 commit 38d42dc

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

dpnp/dpnp_container.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ def container_copy(dst_obj, src_obj, dst_idx = 0):
8989
Copy values to `dst` by iterating element by element in `input_obj`
9090
"""
9191

92-
for elem_value in src_obj:
93-
if isinstance(elem_value, (list, tuple)):
94-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
95-
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
96-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
97-
else:
98-
dst_obj.flat[dst_idx] = elem_value
99-
dst_idx += 1
92+
# zero dimensional arrays are not iterable
93+
if issubclass(type(src_obj), (numpy.ndarray, dparray)) and (src_obj.ndim == 0):
94+
dst_idx = container_copy(dst_obj, (src_obj.item(0),), dst_idx)
95+
else:
96+
for elem_value in src_obj:
97+
if isinstance(elem_value, (list, tuple)):
98+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
99+
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
100+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
101+
else:
102+
dst_obj.flat[dst_idx] = elem_value
103+
dst_idx += 1
100104

101105
return dst_idx

tests/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@
77
numpy.testing.assert_allclose = testing.assert_allclose
88
numpy.testing.assert_array_equal = testing.assert_array_equal
99
numpy.testing.assert_equal = testing.assert_equal
10+
11+
# patch for shaped_arange func to exclude calls of astype and reshape
12+
# necessary because new data container does not support these functions yet
13+
from tests.third_party.cupy import testing as cupy_testing
14+
orig_shaped_arange = cupy_testing.shaped_arange
15+
def _shaped_arange(shape, xp=dpnp, dtype=dpnp.float64, order='C'):
16+
res = xp.array(orig_shaped_arange(shape, xp=numpy, dtype=dtype, order=order), dtype=dtype)
17+
return res
18+
cupy_testing.shaped_arange = _shaped_arange

tests/skipped_tests.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tests/test_linalg.py::test_svd[(16,16)-complex128]
2020
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: (dpnp.asarray([(i, i) for i in x], [("a", int), ("b", int)]).view(dpnp.recarray))]
2121
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([(i, i) for i in x], [("a", object), ("b", dpnp.int32)])]]
2222
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
23+
tests/test_sort.py::test_partition[[[1, 0], [3, 0]]-float32-1]
2324
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and
2425
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_or
2526
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_xor

tests/skipped_tests_gpu.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tests/test_linalg.py::test_svd[(16,16)-complex128]
4545
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: (dpnp.asarray([(i, i) for i in x], [("a", int), ("b", int)]).view(dpnp.recarray))]
4646
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([(i, i) for i in x], [("a", object), ("b", dpnp.int32)])]]
4747
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
48+
tests/test_sort.py::test_partition[[[1, 0], [3, 0]]-float32-1]
4849
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and
4950
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_or
5051
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_xor

0 commit comments

Comments
 (0)