Skip to content

Flat #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2020
Merged

Flat #84

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dpnp/dparray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ cdef class dparray:
# -------------------------------------------------------------------------
# Shape manipulation
# -------------------------------------------------------------------------

@property
def flat(self):
return self

def flatten(self, order='C'):
"""
Return a copy of the array collapsed into one dimension.
Expand Down
41 changes: 41 additions & 0 deletions tests/test_flat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

import dpnp as inp

import numpy


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
ia = inp.array(a)

result = ia.flat[0]
expected = a.flat[0]
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat2(type):
a = numpy.arange(1, 7).reshape(2, 3)
ia = inp.array(a)

result = ia.flat[3]
expected = a.flat[3]
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat3(type):
a = numpy.arange(1, 7).reshape(2, 3).T
ia = inp.array(a)

result = ia.flat[3]
expected = a.flat[3]
numpy.testing.assert_array_equal(expected, result)