Skip to content

Commit 6168aa3

Browse files
authored
change copyto (#487)
1 parent 9699969 commit 6168aa3

File tree

4 files changed

+18
-220
lines changed

4 files changed

+18
-220
lines changed

dpnp/dpnp_algo/dpnp_algo_manipulation.pyx

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -83,52 +83,11 @@ cpdef dparray dpnp_atleast_3d(dparray arr):
8383
return arr
8484

8585

86-
cpdef dparray dpnp_copyto(dparray dst, dparray src, where=True):
87-
cdef dparray_shape_type shape_src = src.shape
86+
cpdef dpnp_copyto(dparray dst, dparray src, where=True):
8887
cdef long size_src = src.size
89-
output_shape = dparray(len(shape_src), dtype=numpy.int64)
90-
for id, shape_ in enumerate(shape_src):
91-
output_shape[id] = shape_
92-
cdef long prod = 1
93-
for i in range(len(output_shape)):
94-
if output_shape[i] != 0:
95-
prod *= output_shape[i]
96-
result_array = [None] * prod
97-
src_shape_offsets = [None] * len(shape_src)
98-
acc = 1
99-
for i in range(len(shape_src)):
100-
ind = len(shape_src) - 1 - i
101-
src_shape_offsets[ind] = acc
102-
acc *= shape_src[ind]
103-
output_shape_offsets = [None] * len(shape_src)
104-
acc = 1
105-
for i in range(len(output_shape)):
106-
ind = len(output_shape) - 1 - i
107-
output_shape_offsets[ind] = acc
108-
acc *= output_shape[ind]
109-
result_offsets = src_shape_offsets[:] # need copy. not a reference
110-
111-
for source_idx in range(size_src):
112-
113-
# reconstruct x,y,z from linear source_idx
114-
xyz = []
115-
remainder = source_idx
116-
for i in src_shape_offsets:
117-
quotient, remainder = divmod(remainder, i)
118-
xyz.append(quotient)
119-
120-
result_indexes = []
121-
for idx, offset in enumerate(xyz):
122-
result_indexes.append(offset)
123-
124-
result_offset = 0
125-
for i, result_indexes_val in enumerate(result_indexes):
126-
result_offset += (output_shape_offsets[i] * result_indexes_val)
127-
128-
src_elem = src.item(source_idx)
129-
dst[source_idx] = src_elem
130-
131-
return dst
88+
89+
for i in range(size_src):
90+
dst[i] = src[i]
13291

13392

13493
cpdef dparray dpnp_expand_dims(dparray in_array, axis):

dpnp/dpnp_iface_manipulation.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,38 +189,21 @@ def copyto(dst, src, casting='same_kind', where=True):
189189
190190
"""
191191

192-
is_input_dparray1 = isinstance(dst, dparray)
193-
is_input_dparray2 = isinstance(src, dparray)
194-
195-
if not use_origin_backend(dst) and is_input_dparray1 and is_input_dparray2:
196-
if casting != 'same_kind':
197-
checker_throw_value_error("copyto", "casting", type(casting), 'same_kind')
198-
199-
if not isinstance(where, bool) and not isinstance(where, dparray):
200-
checker_throw_type_error('copyto', type(where))
201-
202-
if where is not True:
203-
checker_throw_value_error("copyto", "where", where, True)
204-
205-
if dst.shape != src.shape:
206-
raise NotImplemented
207-
208-
result = dpnp_copyto(dst, src, where=where)
209-
210-
return result
211-
212-
input1 = dpnp.asnumpy(dst) if is_input_dparray1 else dst
213-
input2 = dpnp.asnumpy(src) if is_input_dparray2 else src
214-
215-
# TODO need to put dparray memory into NumPy call
216-
result_numpy = numpy.copyto(dst, src, where=where)
217-
result = result_numpy
218-
if isinstance(result, numpy.ndarray):
219-
result = dparray(result_numpy.shape, dtype=result_numpy.dtype)
220-
for i in range(result.size):
221-
result._setitem_scalar(i, result_numpy.item(i))
192+
if not use_origin_backend(dst):
193+
if not isinstance(dst, dparray):
194+
pass
195+
elif not isinstance(src, dparray):
196+
pass
197+
elif casting != 'same_kind':
198+
pass
199+
elif where is not True:
200+
pass
201+
elif dst.shape != src.shape:
202+
pass
203+
else:
204+
return dpnp_copyto(dst, src, where=where)
222205

223-
return result
206+
return call_origin(numpy.copyto, dst, src, casting, where)
224207

225208

226209
def expand_dims(a, axis):

tests/skipped_tests.tbl

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -876,78 +876,6 @@ tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::t
876876
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_array_pyscalar
877877
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_npscalar_array
878878
tests/third_party/cupy/logic_tests/test_comparison.py::TestComparisonOperator::test_binary_pyscalar_array
879-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestBasic::test_copyto_broadcast
880-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestBasic::test_copyto_where
881-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_0_{dst_shape=(), src=3.2}::test_copyto
882-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_0_{dst_shape=(), src=3.2}::test_copyto_where
883-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_10_{dst_shape=(0,), src=-4}::test_copyto
884-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_10_{dst_shape=(0,), src=-4}::test_copyto_where
885-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_11_{dst_shape=(0,), src=True}::test_copyto
886-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_11_{dst_shape=(0,), src=True}::test_copyto_where
887-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_12_{dst_shape=(0,), src=False}::test_copyto
888-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_12_{dst_shape=(0,), src=False}::test_copyto_where
889-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_13_{dst_shape=(0,), src=(1+1j)}::test_copyto
890-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_13_{dst_shape=(0,), src=(1+1j)}::test_copyto_where
891-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_14_{dst_shape=(1,), src=3.2}::test_copyto
892-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_14_{dst_shape=(1,), src=3.2}::test_copyto_where
893-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_15_{dst_shape=(1,), src=0}::test_copyto
894-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_15_{dst_shape=(1,), src=0}::test_copyto_where
895-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_16_{dst_shape=(1,), src=4}::test_copyto
896-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_16_{dst_shape=(1,), src=4}::test_copyto_where
897-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_17_{dst_shape=(1,), src=-4}::test_copyto
898-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_17_{dst_shape=(1,), src=-4}::test_copyto_where
899-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_18_{dst_shape=(1,), src=True}::test_copyto
900-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_18_{dst_shape=(1,), src=True}::test_copyto_where
901-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_19_{dst_shape=(1,), src=False}::test_copyto
902-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_19_{dst_shape=(1,), src=False}::test_copyto_where
903-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_1_{dst_shape=(), src=0}::test_copyto
904-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_1_{dst_shape=(), src=0}::test_copyto_where
905-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_20_{dst_shape=(1,), src=(1+1j)}::test_copyto
906-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_20_{dst_shape=(1,), src=(1+1j)}::test_copyto_where
907-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_21_{dst_shape=(1, 1), src=3.2}::test_copyto
908-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_21_{dst_shape=(1, 1), src=3.2}::test_copyto_where
909-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_22_{dst_shape=(1, 1), src=0}::test_copyto
910-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_22_{dst_shape=(1, 1), src=0}::test_copyto_where
911-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_23_{dst_shape=(1, 1), src=4}::test_copyto
912-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_23_{dst_shape=(1, 1), src=4}::test_copyto_where
913-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_24_{dst_shape=(1, 1), src=-4}::test_copyto
914-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_24_{dst_shape=(1, 1), src=-4}::test_copyto_where
915-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_25_{dst_shape=(1, 1), src=True}::test_copyto
916-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_25_{dst_shape=(1, 1), src=True}::test_copyto_where
917-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_26_{dst_shape=(1, 1), src=False}::test_copyto
918-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_26_{dst_shape=(1, 1), src=False}::test_copyto_where
919-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_27_{dst_shape=(1, 1), src=(1+1j)}::test_copyto
920-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_27_{dst_shape=(1, 1), src=(1+1j)}::test_copyto_where
921-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_28_{dst_shape=(2, 2), src=3.2}::test_copyto
922-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_28_{dst_shape=(2, 2), src=3.2}::test_copyto_where
923-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_29_{dst_shape=(2, 2), src=0}::test_copyto
924-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_29_{dst_shape=(2, 2), src=0}::test_copyto_where
925-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_2_{dst_shape=(), src=4}::test_copyto
926-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_2_{dst_shape=(), src=4}::test_copyto_where
927-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_30_{dst_shape=(2, 2), src=4}::test_copyto
928-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_30_{dst_shape=(2, 2), src=4}::test_copyto_where
929-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_31_{dst_shape=(2, 2), src=-4}::test_copyto
930-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_31_{dst_shape=(2, 2), src=-4}::test_copyto_where
931-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto
932-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_32_{dst_shape=(2, 2), src=True}::test_copyto_where
933-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto
934-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_33_{dst_shape=(2, 2), src=False}::test_copyto_where
935-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto
936-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_34_{dst_shape=(2, 2), src=(1+1j)}::test_copyto_where
937-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_3_{dst_shape=(), src=-4}::test_copyto
938-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_3_{dst_shape=(), src=-4}::test_copyto_where
939-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_4_{dst_shape=(), src=True}::test_copyto
940-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_4_{dst_shape=(), src=True}::test_copyto_where
941-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_5_{dst_shape=(), src=False}::test_copyto
942-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_5_{dst_shape=(), src=False}::test_copyto_where
943-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_6_{dst_shape=(), src=(1+1j)}::test_copyto
944-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_6_{dst_shape=(), src=(1+1j)}::test_copyto_where
945-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_7_{dst_shape=(0,), src=3.2}::test_copyto
946-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_7_{dst_shape=(0,), src=3.2}::test_copyto_where
947-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_8_{dst_shape=(0,), src=0}::test_copyto
948-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_8_{dst_shape=(0,), src=0}::test_copyto_where
949-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_9_{dst_shape=(0,), src=4}::test_copyto
950-
tests/third_party/cupy/manipulation_tests/test_basic.py::TestCopytoFromScalar_param_9_{dst_shape=(0,), src=4}::test_copyto_where
951879
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to
952880
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to_fail
953881
tests/third_party/cupy/manipulation_tests/test_dims.py::TestDims::test_broadcast_to_fail_numpy19

0 commit comments

Comments
 (0)