-
Notifications
You must be signed in to change notification settings - Fork 22
Print dpnp array #1279
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
Print dpnp array #1279
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3228470
add __repr__
vtavana 333b4fc
add __str__
vtavana 67d5cb1
reviewer's comments
vtavana 30d3ada
linter changes applied
oleksandr-pavlyk 5018352
Merge branch 'master' into print_dpnp_array
oleksandr-pavlyk 0189d6b
Merge branch 'master' into print_dpnp_array
oleksandr-pavlyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,111 @@ def test_flags_strides(dtype, order, strides): | |
assert numpy_array.flags.c_contiguous == dpnp_array.flags.c_contiguous | ||
assert numpy_array.flags.f_contiguous == dpnp_array.flags.f_contiguous | ||
|
||
def test_print_dpnp_int(): | ||
result = repr(dpnp.array([1, 0, 2, -3, -1, 2, 21, -9], dtype='i4')) | ||
expected = "array([ 1, 0, 2, -3, -1, 2, 21, -9], dtype=int32)" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, 0, 2, -3, -1, 2, 21, -9], dtype='i4')) | ||
expected = "[ 1 0 2 -3 -1 2 21 -9]" | ||
assert(result==expected) | ||
# int32 | ||
result = repr(dpnp.array([1, -1, 21], dtype=dpnp.int32)) | ||
expected = "array([ 1, -1, 21], dtype=int32)" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, -1, 21], dtype=dpnp.int32)) | ||
expected = "[ 1 -1 21]" | ||
assert(result==expected) | ||
# uint8 | ||
result = repr(dpnp.array([1, 0, 3], dtype=numpy.uint8)) | ||
expected = "array([1, 0, 3], dtype=uint8)" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, 0, 3], dtype=numpy.uint8)) | ||
expected = "[1 0 3]" | ||
assert(result==expected) | ||
|
||
def test_print_dpnp_float(): | ||
result = repr(dpnp.array([1, -1, 21], dtype=float)) | ||
expected = "array([ 1., -1., 21.])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, -1, 21], dtype=float)) | ||
expected = "[ 1. -1. 21.]" | ||
assert(result==expected) | ||
# float32 | ||
result = repr(dpnp.array([1, -1, 21], dtype=dpnp.float32)) | ||
expected = "array([ 1., -1., 21.], dtype=float32)" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, -1, 21], dtype=dpnp.float32)) | ||
expected = "[ 1. -1. 21.]" | ||
assert(result==expected) | ||
|
||
def test_print_dpnp_complex(): | ||
result = repr(dpnp.array([1, -1, 21], dtype=complex)) | ||
expected = "array([ 1.+0.j, -1.+0.j, 21.+0.j])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, -1, 21], dtype=complex)) | ||
expected = "[ 1.+0.j -1.+0.j 21.+0.j]" | ||
assert(result==expected) | ||
|
||
def test_print_dpnp_boolean(): | ||
result = repr(dpnp.array([1, 0, 3], dtype=bool)) | ||
expected = "array([ True, False, True])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1, 0, 3], dtype=bool)) | ||
expected = "[ True False True]" | ||
assert(result==expected) | ||
|
||
def test_print_dpnp_special_character(): | ||
# NaN | ||
result = repr(dpnp.array([1., 0., dpnp.nan, 3.])) | ||
expected = "array([ 1., 0., nan, 3.])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1., 0., dpnp.nan, 3.])) | ||
expected = "[ 1. 0. nan 3.]" | ||
assert(result==expected) | ||
# inf | ||
result = repr(dpnp.array([1., 0., numpy.inf, 3.])) | ||
expected = "array([ 1., 0., inf, 3.])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([1., 0., numpy.inf, 3.])) | ||
expected = "[ 1. 0. inf 3.]" | ||
assert(result==expected) | ||
|
||
def test_print_dpnp_nd(): | ||
# 1D | ||
result = repr(dpnp.arange(10000, dtype='float32')) | ||
expected = "array([0.000e+00, 1.000e+00, 2.000e+00, ..., 9.997e+03, 9.998e+03,\n 9.999e+03], dtype=float32)" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.arange(10000, dtype='float32')) | ||
expected = "[0.000e+00 1.000e+00 2.000e+00 ... 9.997e+03 9.998e+03 9.999e+03]" | ||
assert(result==expected) | ||
|
||
# 2D | ||
result = repr(dpnp.array([[1, 2], [3, 4]], dtype=float)) | ||
expected = "array([[1., 2.],\n [3., 4.]])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.array([[1, 2], [3, 4]])) | ||
expected = "[[1 2]\n [3 4]]" | ||
assert(result==expected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably to add also a test case with |
||
# 0 shape | ||
result = repr(dpnp.empty( shape=(0, 0) )) | ||
expected = "array([])" | ||
assert(result==expected) | ||
|
||
result = str(dpnp.empty( shape=(0, 0) )) | ||
expected = "[]" | ||
assert(result==expected) | ||
|
||
@pytest.mark.parametrize("func", [bool, float, int, complex]) | ||
@pytest.mark.parametrize("shape", [tuple(), (1,), (1, 1), (1, 1, 1)]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.