Skip to content

Commit e30e7a4

Browse files
Use normalize_axis_tuple from numpy instead of _check_value_of_axes (#789)
1 parent 02bf7d2 commit e30e7a4

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

dpctl/tensor/_manipulation_functions.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,11 @@
1515
# limitations under the License.
1616

1717

18-
import numpy as np
1918
from numpy.core.numeric import normalize_axis_tuple
2019

2120
import dpctl.tensor as dpt
2221

2322

24-
def _check_value_of_axes(axes):
25-
axes_len = len(axes)
26-
check_array = np.zeros(axes_len)
27-
for i in axes:
28-
ii = i.__index__()
29-
if ii < 0 or ii > axes_len or check_array[ii] != 0:
30-
return False
31-
check_array[ii] = 1
32-
return True
33-
34-
3523
def permute_dims(X, axes):
3624
"""
3725
permute_dims(X: usm_ndarray, axes: tuple or list) -> usm_ndarray
@@ -48,11 +36,7 @@ def permute_dims(X, axes):
4836
"The length of the passed axes does not match "
4937
"to the number of usm_ndarray dimensions."
5038
)
51-
if not _check_value_of_axes(axes):
52-
raise ValueError(
53-
"The values of the axes must be in the range "
54-
f"from 0 to {X.ndim} and have no duplicates."
55-
)
39+
axes = normalize_axis_tuple(axes, X.ndim, "axes")
5640
newstrides = tuple(X.strides[i] for i in axes)
5741
newshape = tuple(X.shape[i] for i in axes)
5842
return dpt.usm_ndarray(

dpctl/tests/test_usm_ndarray_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_permute_dims_0d_1d():
6363
assert_array_equal(dpt.asnumpy(Y_1d), dpt.asnumpy(X_1d))
6464

6565
pytest.raises(ValueError, dpt.permute_dims, X_1d, ())
66-
pytest.raises(IndexError, dpt.permute_dims, X_1d, (1))
66+
pytest.raises(np.AxisError, dpt.permute_dims, X_1d, (1))
6767
pytest.raises(ValueError, dpt.permute_dims, X_1d, (1, 0))
6868
pytest.raises(
6969
ValueError, dpt.permute_dims, dpt.reshape(X_1d, (2, 3)), (1, 1)

0 commit comments

Comments
 (0)