Skip to content

Commit 694d234

Browse files
authored
add flat (#84)
1 parent be68075 commit 694d234

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

dpnp/dparray.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ cdef class dparray:
393393
# -------------------------------------------------------------------------
394394
# Shape manipulation
395395
# -------------------------------------------------------------------------
396+
397+
@property
398+
def flat(self):
399+
return self
400+
396401
def flatten(self, order='C'):
397402
"""
398403
Return a copy of the array collapsed into one dimension.

tests/test_flat.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
import dpnp as inp
4+
5+
import numpy
6+
7+
8+
@pytest.mark.parametrize("type",
9+
[numpy.int64],
10+
ids=['int64'])
11+
def test_flat(type):
12+
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
13+
ia = inp.array(a)
14+
15+
result = ia.flat[0]
16+
expected = a.flat[0]
17+
numpy.testing.assert_array_equal(expected, result)
18+
19+
20+
@pytest.mark.parametrize("type",
21+
[numpy.int64],
22+
ids=['int64'])
23+
def test_flat2(type):
24+
a = numpy.arange(1, 7).reshape(2, 3)
25+
ia = inp.array(a)
26+
27+
result = ia.flat[3]
28+
expected = a.flat[3]
29+
numpy.testing.assert_array_equal(expected, result)
30+
31+
32+
@pytest.mark.parametrize("type",
33+
[numpy.int64],
34+
ids=['int64'])
35+
def test_flat3(type):
36+
a = numpy.arange(1, 7).reshape(2, 3).T
37+
ia = inp.array(a)
38+
39+
result = ia.flat[3]
40+
expected = a.flat[3]
41+
numpy.testing.assert_array_equal(expected, result)

0 commit comments

Comments
 (0)