Skip to content

Commit dae58ad

Browse files
The flatten func impl (#1009)
1 parent d6890b7 commit dae58ad

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

dpnp/dpnp_array.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,37 @@ def flat(self):
407407

408408
return dpnp.flatiter(self)
409409

410-
# 'flatten',
410+
def flatten(self, order='C'):
411+
"""
412+
Return a copy of the array collapsed into one dimension.
413+
414+
Parameters
415+
----------
416+
order: {'C', 'F', 'A', 'K'}, optional
417+
'C' means to flatten in row-major (C-style) order.
418+
'F' means to flatten in column-major (Fortran- style) order.
419+
'A' means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise.
420+
'K' means to flatten a in the order the elements occur in memory. The default is 'C'.
421+
422+
Returns
423+
-------
424+
out: ndarray
425+
A copy of the input array, flattened to one dimension.
426+
427+
See Also
428+
--------
429+
:obj:`dpnp.ravel`, :obj:`dpnp.flat`
430+
431+
"""
432+
433+
new_arr = dpnp.ndarray(self.shape, self.dtype)
434+
435+
if self.size > 0:
436+
dpctl.tensor._copy_utils.copy_from_usm_ndarray_to_usm_ndarray(new_arr._array_obj, self._array_obj)
437+
new_arr._array_obj = dpctl.tensor.reshape(new_arr._array_obj, (self.size, ))
438+
439+
return new_arr
440+
411441
# 'getfield',
412442
# 'imag',
413443
# 'item',

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -339,27 +339,6 @@ tests/test_dparray.py::test_astype[[]-complex-int32]
339339
tests/test_dparray.py::test_astype[[]-complex-bool]
340340
tests/test_dparray.py::test_astype[[]-complex-bool_]
341341
tests/test_dparray.py::test_astype[[]-complex-complex]
342-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-float64]
343-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-float32]
344-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-int64]
345-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-int32]
346-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-bool]
347-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-bool_]
348-
tests/test_dparray.py::test_flatten[[-2, -1, 0, 1, 2]-complex]
349-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-float64]
350-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-float32]
351-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-int64]
352-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-int32]
353-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-bool]
354-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-bool_]
355-
tests/test_dparray.py::test_flatten[[[-2, -1], [1, 2]]-complex]
356-
tests/test_dparray.py::test_flatten[[]-float64]
357-
tests/test_dparray.py::test_flatten[[]-float32]
358-
tests/test_dparray.py::test_flatten[[]-int64]
359-
tests/test_dparray.py::test_flatten[[]-int32]
360-
tests/test_dparray.py::test_flatten[[]-bool]
361-
tests/test_dparray.py::test_flatten[[]-bool_]
362-
tests/test_dparray.py::test_flatten[[]-complex]
363342
tests/test_fft.py::test_fft[float32]
364343
tests/test_fft.py::test_fft[float64]
365344
tests/test_fft.py::test_fft[int32]

0 commit comments

Comments
 (0)