-
Notifications
You must be signed in to change notification settings - Fork 30
Resolve gh-2055 #2058
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
Resolve gh-2055 #2058
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
346eedd
Resolve `dpt.asarray` failed to copy input `numpy.ndarray` #2055
ndgrigorian 5442d79
Adjust docstrings in `_copy_utils`
ndgrigorian d73cddd
Add test for gh-2055 resolution and refactor tests for _copy_utils in…
ndgrigorian eafb644
factor common call out of logic in _asarray_from_numpy_ndarray
ndgrigorian 5b4ae4a
np.ndarray->numpy.ndarray in error text
ndgrigorian 152a3ed
change variable names throughout _copy_utils
ndgrigorian 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Data Parallel Control (dpctl) | ||
# | ||
# Copyright 2020-2025 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import dpctl.tensor as dpt | ||
import dpctl.tensor._copy_utils as cu | ||
from dpctl.tests.helper import get_queue_or_skip | ||
|
||
|
||
def test_copy_utils_empty_like_orderK(): | ||
get_queue_or_skip() | ||
a = dpt.empty((10, 10), dtype=dpt.int32, order="F") | ||
X = cu._empty_like_orderK(a, dpt.int32, a.usm_type, a.device) | ||
assert X.flags["F"] | ||
|
||
|
||
def test_copy_utils_empty_like_orderK_invalid_args(): | ||
get_queue_or_skip() | ||
with pytest.raises(TypeError): | ||
cu._empty_like_orderK([1, 2, 3], dpt.int32, "device", None) | ||
with pytest.raises(TypeError): | ||
cu._empty_like_pair_orderK( | ||
[1, 2, 3], | ||
( | ||
1, | ||
2, | ||
3, | ||
), | ||
dpt.int32, | ||
(3,), | ||
"device", | ||
None, | ||
) | ||
|
||
a = dpt.empty(10, dtype=dpt.int32) | ||
with pytest.raises(TypeError): | ||
cu._empty_like_pair_orderK( | ||
a, | ||
( | ||
1, | ||
2, | ||
3, | ||
), | ||
dpt.int32, | ||
(10,), | ||
"device", | ||
None, | ||
) | ||
|
||
|
||
def test_copy_utils_from_numpy_empty_like_orderK(): | ||
q = get_queue_or_skip() | ||
|
||
a = np.empty((10, 10), dtype=np.int32, order="C") | ||
r0 = cu._from_numpy_empty_like_orderK(a, dpt.int32, "device", q) | ||
assert r0.flags["C"] | ||
|
||
b = np.empty((10, 10), dtype=np.int32, order="F") | ||
r1 = cu._from_numpy_empty_like_orderK(b, dpt.int32, "device", q) | ||
assert r1.flags["F"] | ||
|
||
c = np.empty((2, 3, 4), dtype=np.int32, order="C") | ||
c = np.transpose(c, (1, 0, 2)) | ||
r2 = cu._from_numpy_empty_like_orderK(c, dpt.int32, "device", q) | ||
assert not r2.flags["C"] and not r2.flags["F"] | ||
|
||
|
||
def test_copy_utils_from_numpy_empty_like_orderK_invalid_args(): | ||
with pytest.raises(TypeError): | ||
cu._from_numpy_empty_like_orderK([1, 2, 3], dpt.int32, "device", None) | ||
|
||
|
||
def test_gh_2055(): | ||
""" | ||
Test that `dpt.asarray` works on contiguous NumPy arrays with `order="K"` | ||
when dimensions are permuted. | ||
|
||
See: https://github.com/IntelPython/dpctl/issues/2055 | ||
""" | ||
get_queue_or_skip() | ||
|
||
a = np.ones((2, 3, 4), dtype=dpt.int32) | ||
a_t = np.transpose(a, (2, 0, 1)) | ||
r = dpt.asarray(a_t) | ||
assert not r.flags["C"] and not r.flags["F"] |
Oops, something went wrong.
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.