-
Notifications
You must be signed in to change notification settings - Fork 22
Get rid of fallback on numpy in dpnp.asfarray #1542
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d655c69
SAT-6118 Get rid of fallback on numpy in dpnp.asfarray
npolina4 3a9292b
Added nore test for dpnp.asfarray() function.
npolina4 950bbcb
Merge branch 'master' into update_asfarray
npolina4 ce9375b
Fixed example for asfarray function.
npolina4 9949915
Update dpnp/dpnp_iface_manipulation.py
npolina4 c0a895c
Merge branch 'master' into update_asfarray
npolina4 ca93f92
Update tests/third_party/cupy/manipulation_tests/test_kind.py
npolina4 3ca9530
Update test_kind.py
npolina4 94b4ec6
Merge branch 'master' into update_asfarray
antonwolfy 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
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
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import unittest | ||
|
||
import numpy | ||
import pytest | ||
|
||
import dpnp as cupy | ||
from tests.helper import has_support_aspect64 | ||
from tests.third_party.cupy import testing | ||
|
||
|
||
class TestKind(unittest.TestCase): | ||
@pytest.mark.skip("dpnp.asarray_chkfinite() is not implemented yet") | ||
@testing.for_orders("CFAK") | ||
@testing.for_all_dtypes() | ||
@testing.numpy_cupy_array_equal() | ||
def test_asarray_chkfinite(self, xp, dtype, order): | ||
a = [0, 4, 0, 5] | ||
return xp.asarray_chkfinite(a, dtype=dtype, order=order) | ||
|
||
@pytest.mark.skip("dpnp.asarray_chkfinite() is not implemented yet") | ||
@testing.for_orders("CFAK") | ||
@testing.for_all_dtypes(no_bool=True) | ||
def test_asarray_chkfinite_non_finite_vals(self, dtype, order): | ||
a = [-numpy.inf, 0.0, numpy.inf, numpy.nan] | ||
for xp in (numpy, cupy): | ||
if xp.issubdtype(dtype, xp.integer): | ||
error = OverflowError | ||
else: | ||
error = ValueError | ||
with pytest.raises(error): | ||
xp.asarray_chkfinite(a, dtype=dtype, order=order) | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfarray(self, dtype): | ||
a = cupy.asarray([1, 2, 3]) | ||
a_gpu = cupy.asfarray(a, dtype) | ||
a_cpu = numpy.asfarray(a, dtype) | ||
if ( | ||
has_support_aspect64() | ||
or cupy.issubdtype(dtype, cupy.complexfloating) | ||
or cupy.issubdtype(dtype, cupy.floating) | ||
): | ||
assert a_cpu.dtype == a_gpu.dtype | ||
else: | ||
assert a_cpu.dtype == cupy.float64 | ||
assert a_gpu.dtype == cupy.float32 | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfortranarray1(self, dtype): | ||
def func(xp): | ||
x = xp.zeros((2, 3), dtype=dtype) | ||
ret = xp.asfortranarray(x) | ||
assert x.flags.c_contiguous | ||
assert ret.flags.f_contiguous | ||
|
||
assert func(numpy) == func(cupy) | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfortranarray2(self, dtype): | ||
def func(xp): | ||
x = xp.zeros((2, 3, 4), dtype=dtype) | ||
ret = xp.asfortranarray(x) | ||
assert x.flags.c_contiguous | ||
assert ret.flags.f_contiguous | ||
|
||
assert func(numpy) == func(cupy) | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfortranarray3(self, dtype): | ||
def func(xp): | ||
x = xp.zeros((2, 3, 4), dtype=dtype) | ||
ret = xp.asfortranarray(xp.asfortranarray(x)) | ||
assert x.flags.c_contiguous | ||
assert ret.flags.f_contiguous | ||
|
||
assert func(numpy) == func(cupy) | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfortranarray4(self, dtype): | ||
def func(xp): | ||
x = xp.zeros((2, 3), dtype=dtype) | ||
x = xp.transpose(x, (1, 0)) | ||
ret = xp.asfortranarray(x) | ||
assert ret.flags.f_contiguous | ||
|
||
assert func(numpy) == func(cupy) | ||
|
||
@testing.for_all_dtypes() | ||
def test_asfortranarray5(self, dtype): | ||
def func(xp): | ||
x = testing.shaped_arange((2, 3), xp, dtype) | ||
ret = xp.asfortranarray(x) | ||
assert x.flags.c_contiguous | ||
assert ret.flags.f_contiguous | ||
|
||
assert func(numpy) == func(cupy) | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_flag_check(self, dtype): | ||
possible_flags = [["C_CONTIGUOUS"], ["F_CONTIGUOUS"]] | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
for flags in possible_flags: | ||
arr = cupy.require(x, dtype, flags) | ||
for parameter in flags: | ||
assert arr.flags[parameter] | ||
assert arr.dtype == dtype | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_owndata(self, dtype): | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
arr = x.view() | ||
arr = cupy.require(arr, dtype, ["O"]) | ||
assert arr.flags["OWNDATA"] | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_C_and_F_flags(self, dtype): | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
with pytest.raises(ValueError): | ||
cupy.require(x, dtype, ["C", "F"]) | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_incorrect_requirments(self, dtype): | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
with pytest.raises(ValueError): | ||
cupy.require(x, dtype, ["W"]) | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_incorrect_dtype(self, dtype): | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
with pytest.raises(ValueError): | ||
cupy.require(x, "random", "C") | ||
|
||
@pytest.mark.skip("dpnp.require() is not implemented yet") | ||
@testing.for_all_dtypes() | ||
def test_require_empty_requirements(self, dtype): | ||
x = cupy.zeros((2, 3, 4), dtype=dtype) | ||
x = cupy.require(x, dtype, []) | ||
assert x.flags["C_CONTIGUOUS"] |
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.