From 43e596044daf71712af9c0ab06f0ec683df7e6e2 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Fri, 19 Jun 2026 13:31:26 +0200 Subject: [PATCH] Add gitattribute to make all line endings LF --- .gitattributes | 6 + dpnp/dpnp_iface_utils.py | 148 +++++----- dpnp/tests/test_array_utils.py | 78 +++--- .../cupy/logic_tests/test_type_test.py | 256 +++++++++--------- .../cupy/misc_tests/test_byte_bounds.py | 150 +++++----- 5 files changed, 322 insertions(+), 316 deletions(-) diff --git a/.gitattributes b/.gitattributes index 065d07a5be84..190152250e33 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,7 @@ +# Normalize all text files to use LF (\n) line endings. +# More specific rules below this line may override this default, +# for example: +# *.bat text eol=crlf +* text=auto eol=lf + dpnp/_version.py export-subst diff --git a/dpnp/dpnp_iface_utils.py b/dpnp/dpnp_iface_utils.py index 8cd1196ee6d9..1296ac484264 100644 --- a/dpnp/dpnp_iface_utils.py +++ b/dpnp/dpnp_iface_utils.py @@ -1,74 +1,74 @@ -# ***************************************************************************** -# Copyright (c) 2024, Intel Corporation -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# - Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# - Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -# THE POSSIBILITY OF SUCH DAMAGE. -# ***************************************************************************** - -""" -Interface of the utils function of the DPNP - -Notes ------ -This module is a face or public interface file for the library - -""" - -import dpnp - - -def byte_bounds(a): - """ - Returns a 2-tuple with pointers to the end-points of the array. - - For full documentation refer to :obj:`numpy.lib.array_utils.byte_bounds`. - - Parameters - ---------- - a : {dpnp.ndarray, usm_ndarray} - Input array - - Returns - ------- - (low, high) : tuple of 2 integers - The first integer is the first byte of the array, the second integer is - just past the last byte of the array. If `a` is not contiguous it will - not use every byte between the (`low`, `high`) values. - - Examples - -------- - >>> import dpnp as np - >>> I = np.eye(2, dtype=np.complex64); - >>> low, high = np.byte_bounds(I) - >>> high - low == I.size*I.itemsize - True - >>> I = np.eye(2); - >>> low, high = np.byte_bounds(I) - >>> high - low == I.size*I.itemsize - True - - """ - - # pylint: disable=protected-access - return dpnp.get_usm_ndarray(a)._byte_bounds +# ***************************************************************************** +# Copyright (c) 2024, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + +""" +Interface of the utils function of the DPNP + +Notes +----- +This module is a face or public interface file for the library + +""" + +import dpnp + + +def byte_bounds(a): + """ + Returns a 2-tuple with pointers to the end-points of the array. + + For full documentation refer to :obj:`numpy.lib.array_utils.byte_bounds`. + + Parameters + ---------- + a : {dpnp.ndarray, usm_ndarray} + Input array + + Returns + ------- + (low, high) : tuple of 2 integers + The first integer is the first byte of the array, the second integer is + just past the last byte of the array. If `a` is not contiguous it will + not use every byte between the (`low`, `high`) values. + + Examples + -------- + >>> import dpnp as np + >>> I = np.eye(2, dtype=np.complex64); + >>> low, high = np.byte_bounds(I) + >>> high - low == I.size*I.itemsize + True + >>> I = np.eye(2); + >>> low, high = np.byte_bounds(I) + >>> high - low == I.size*I.itemsize + True + + """ + + # pylint: disable=protected-access + return dpnp.get_usm_ndarray(a)._byte_bounds diff --git a/dpnp/tests/test_array_utils.py b/dpnp/tests/test_array_utils.py index eebbb03de8ca..14938632fc50 100644 --- a/dpnp/tests/test_array_utils.py +++ b/dpnp/tests/test_array_utils.py @@ -1,39 +1,39 @@ -import dpnp - - -def test_byte_bounds(): - a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") - values = dpnp.arange(12, dtype="int64") - for i in range(3): - a[i, :] = values[i * 4 : (i + 1) * 4] - low, high = dpnp.byte_bounds(a) - assert (high - low) == (a.size * a.itemsize) - - -def test_unusual_order_positive_stride(): - a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") - values = dpnp.arange(12, dtype="int64") - for i in range(3): - a[i, :] = values[i * 4 : (i + 1) * 4] - b = a.T - low, high = dpnp.byte_bounds(b) - assert (high - low) == (b.size * b.itemsize) - - -def test_unusual_order_negative_stride(): - a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") - values = dpnp.arange(12, dtype="int64") - for i in range(3): - a[i, :] = values[i * 4 : (i + 1) * 4] - b = a.T[::-1] - low, high = dpnp.byte_bounds(b) - assert (high - low) == (b.size * b.itemsize) - - -def test_strided(): - a = dpnp.zeros(12, dtype=dpnp.int64, usm_type="shared") - a[:] = dpnp.arange(12, dtype="int64") - b = a[::2] - low, high = dpnp.byte_bounds(b) - expected_byte_diff = b.size * 2 * b.itemsize - b.itemsize - assert (high - low) == expected_byte_diff +import dpnp + + +def test_byte_bounds(): + a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") + values = dpnp.arange(12, dtype="int64") + for i in range(3): + a[i, :] = values[i * 4 : (i + 1) * 4] + low, high = dpnp.byte_bounds(a) + assert (high - low) == (a.size * a.itemsize) + + +def test_unusual_order_positive_stride(): + a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") + values = dpnp.arange(12, dtype="int64") + for i in range(3): + a[i, :] = values[i * 4 : (i + 1) * 4] + b = a.T + low, high = dpnp.byte_bounds(b) + assert (high - low) == (b.size * b.itemsize) + + +def test_unusual_order_negative_stride(): + a = dpnp.zeros((3, 4), dtype=dpnp.int64, usm_type="shared") + values = dpnp.arange(12, dtype="int64") + for i in range(3): + a[i, :] = values[i * 4 : (i + 1) * 4] + b = a.T[::-1] + low, high = dpnp.byte_bounds(b) + assert (high - low) == (b.size * b.itemsize) + + +def test_strided(): + a = dpnp.zeros(12, dtype=dpnp.int64, usm_type="shared") + a[:] = dpnp.arange(12, dtype="int64") + b = a[::2] + low, high = dpnp.byte_bounds(b) + expected_byte_diff = b.size * 2 * b.itemsize - b.itemsize + assert (high - low) == expected_byte_diff diff --git a/dpnp/tests/third_party/cupy/logic_tests/test_type_test.py b/dpnp/tests/third_party/cupy/logic_tests/test_type_test.py index f4261a890f4c..73ea6f1ea564 100644 --- a/dpnp/tests/third_party/cupy/logic_tests/test_type_test.py +++ b/dpnp/tests/third_party/cupy/logic_tests/test_type_test.py @@ -1,128 +1,128 @@ -from __future__ import annotations - -import unittest - -import numpy -import pytest - -from dpnp.tests.third_party.cupy import testing - - -class TestIsScalar(testing.NumpyAliasBasicTestBase): - - func = "isscalar" - - @testing.with_requires("numpy>=1.18") - def test_argspec(self): - super().test_argspec() - - -@testing.parameterize( - *testing.product( - { - "value": [ - 0, - 0.0, - True, - numpy.int32(1), - numpy.array([1, 2], numpy.int32), - numpy.complex128(1), - numpy.complex128(1j), - numpy.complex128(1 + 1j), - None, - "abc", - "", - int, - numpy.int32, - ] - } - ) -) -class TestIsScalarValues(testing.NumpyAliasValuesTestBase): - - func = "isscalar" - - def setUp(self): - self.args = (self.value,) - - -class TestIsScalarValues2(testing.NumpyAliasValuesTestBase): - - func = "isscalar" - - def setUp(self): - value = object() - self.args = (value,) - - -@testing.parameterize( - *testing.product( - { - "value": [ - # C and F - numpy.ones(24, order="C"), - # C and not F - numpy.ones((4, 6), order="C"), - # not C and F - numpy.ones((4, 6), order="F"), - # not C and not F - numpy.ones((4, 6), order="C")[1:3][1:3], - ] - } - ) -) -class TestIsFortran(unittest.TestCase): - - @testing.numpy_cupy_equal() - def test(self, xp): - return xp.isfortran(xp.asarray(self.value)) - - -@testing.parameterize( - {"func": "iscomplex"}, - {"func": "isreal"}, -) -class TestTypeTestingFunctions(unittest.TestCase): - - @testing.for_all_dtypes() - @testing.numpy_cupy_array_equal() - def test(self, xp, dtype): - return getattr(xp, self.func)(xp.ones(5, dtype=dtype)) - - @pytest.mark.skip("Scalar input is not supported") - @testing.for_all_dtypes() - @testing.numpy_cupy_equal() - def test_scalar(self, xp, dtype): - return getattr(xp, self.func)(dtype(3)) - - @pytest.mark.skip("List input is not supported") - @testing.for_all_dtypes() - @testing.numpy_cupy_array_equal() - def test_list(self, xp, dtype): - return getattr(xp, self.func)( - testing.shaped_arange((2, 3), xp, dtype).tolist() - ) - - -@testing.parameterize( - {"func": "iscomplexobj"}, - {"func": "isrealobj"}, -) -class TestTypeTestingObjFunctions(unittest.TestCase): - - @testing.for_all_dtypes() - @testing.numpy_cupy_equal() - def test(self, xp, dtype): - return getattr(xp, self.func)(xp.ones(5, dtype=dtype)) - - @testing.for_all_dtypes() - @testing.numpy_cupy_equal() - def test_scalar(self, xp, dtype): - return getattr(xp, self.func)(dtype(3)) - - @testing.for_all_dtypes() - @testing.numpy_cupy_equal() - def test_list(self, xp, dtype): - return getattr(xp, self.func)( - testing.shaped_arange((2, 3), xp, dtype).tolist() - ) +from __future__ import annotations + +import unittest + +import numpy +import pytest + +from dpnp.tests.third_party.cupy import testing + + +class TestIsScalar(testing.NumpyAliasBasicTestBase): + + func = "isscalar" + + @testing.with_requires("numpy>=1.18") + def test_argspec(self): + super().test_argspec() + + +@testing.parameterize( + *testing.product( + { + "value": [ + 0, + 0.0, + True, + numpy.int32(1), + numpy.array([1, 2], numpy.int32), + numpy.complex128(1), + numpy.complex128(1j), + numpy.complex128(1 + 1j), + None, + "abc", + "", + int, + numpy.int32, + ] + } + ) +) +class TestIsScalarValues(testing.NumpyAliasValuesTestBase): + + func = "isscalar" + + def setUp(self): + self.args = (self.value,) + + +class TestIsScalarValues2(testing.NumpyAliasValuesTestBase): + + func = "isscalar" + + def setUp(self): + value = object() + self.args = (value,) + + +@testing.parameterize( + *testing.product( + { + "value": [ + # C and F + numpy.ones(24, order="C"), + # C and not F + numpy.ones((4, 6), order="C"), + # not C and F + numpy.ones((4, 6), order="F"), + # not C and not F + numpy.ones((4, 6), order="C")[1:3][1:3], + ] + } + ) +) +class TestIsFortran(unittest.TestCase): + + @testing.numpy_cupy_equal() + def test(self, xp): + return xp.isfortran(xp.asarray(self.value)) + + +@testing.parameterize( + {"func": "iscomplex"}, + {"func": "isreal"}, +) +class TestTypeTestingFunctions(unittest.TestCase): + + @testing.for_all_dtypes() + @testing.numpy_cupy_array_equal() + def test(self, xp, dtype): + return getattr(xp, self.func)(xp.ones(5, dtype=dtype)) + + @pytest.mark.skip("Scalar input is not supported") + @testing.for_all_dtypes() + @testing.numpy_cupy_equal() + def test_scalar(self, xp, dtype): + return getattr(xp, self.func)(dtype(3)) + + @pytest.mark.skip("List input is not supported") + @testing.for_all_dtypes() + @testing.numpy_cupy_array_equal() + def test_list(self, xp, dtype): + return getattr(xp, self.func)( + testing.shaped_arange((2, 3), xp, dtype).tolist() + ) + + +@testing.parameterize( + {"func": "iscomplexobj"}, + {"func": "isrealobj"}, +) +class TestTypeTestingObjFunctions(unittest.TestCase): + + @testing.for_all_dtypes() + @testing.numpy_cupy_equal() + def test(self, xp, dtype): + return getattr(xp, self.func)(xp.ones(5, dtype=dtype)) + + @testing.for_all_dtypes() + @testing.numpy_cupy_equal() + def test_scalar(self, xp, dtype): + return getattr(xp, self.func)(dtype(3)) + + @testing.for_all_dtypes() + @testing.numpy_cupy_equal() + def test_list(self, xp, dtype): + return getattr(xp, self.func)( + testing.shaped_arange((2, 3), xp, dtype).tolist() + ) diff --git a/dpnp/tests/third_party/cupy/misc_tests/test_byte_bounds.py b/dpnp/tests/third_party/cupy/misc_tests/test_byte_bounds.py index 9e1158c8e871..bf006cbaf9d1 100644 --- a/dpnp/tests/third_party/cupy/misc_tests/test_byte_bounds.py +++ b/dpnp/tests/third_party/cupy/misc_tests/test_byte_bounds.py @@ -1,75 +1,75 @@ -import dpnp as cupy -from dpnp.tests.third_party.cupy import testing - - -class TestByteBounds: - - @testing.for_all_dtypes() - def test_1d_contiguous(self, dtype): - a = cupy.zeros(12, dtype=dtype) - itemsize = a.itemsize - a_low = a.data.ptr - a_high = a.data.ptr + 12 * itemsize - assert cupy.byte_bounds(a) == (a_low, a_high) - - @testing.for_all_dtypes() - def test_2d_contiguous(self, dtype): - a = cupy.zeros((4, 7), dtype=dtype) - itemsize = a.itemsize - a_low = a.data.ptr - a_high = a.data.ptr + 4 * 7 * itemsize - assert cupy.byte_bounds(a) == (a_low, a_high) - - @testing.for_all_dtypes() - def test_1d_noncontiguous_pos_stride(self, dtype): - a = cupy.zeros(12, dtype=dtype) - itemsize = a.itemsize - b = a[::2] - b_low = b.data.ptr - b_high = b.data.ptr + 11 * itemsize # a[10] - assert cupy.byte_bounds(b) == (b_low, b_high) - - @testing.for_all_dtypes() - def test_2d_noncontiguous_pos_stride(self, dtype): - a = cupy.zeros((4, 7), dtype=dtype) - b = a[::2, ::2] - itemsize = b.itemsize - b_low = a.data.ptr - b_high = b.data.ptr + 3 * 7 * itemsize # a[2][6] - assert cupy.byte_bounds(b) == (b_low, b_high) - - @testing.for_all_dtypes() - def test_1d_contiguous_neg_stride(self, dtype): - a = cupy.zeros(12, dtype=dtype) - b = a[::-1] - itemsize = b.itemsize - b_low = b.data.ptr - 11 * itemsize - b_high = b.data.ptr + 1 * itemsize - assert cupy.byte_bounds(b) == (b_low, b_high) - - @testing.for_all_dtypes() - def test_2d_noncontiguous_neg_stride(self, dtype): - a = cupy.zeros((4, 7), dtype=dtype) - b = a[::-2, ::-2] # strides = (-56, -8), shape = (2, 4) - itemsize = b.itemsize - b_low = b.data.ptr - 2 * 7 * itemsize * (2 - 1) - 2 * itemsize * (4 - 1) - b_high = b.data.ptr + 1 * itemsize - assert cupy.byte_bounds(b) == (b_low, b_high) - - @testing.for_all_dtypes() - def test_2d_noncontiguous_posneg_stride_1(self, dtype): - a = cupy.zeros((4, 7), dtype=dtype) - b = a[::1, ::-1] # strides = (28, -4), shape=(4, 7) - itemsize = b.itemsize - b_low = b.data.ptr - itemsize * (7 - 1) - b_high = b.data.ptr + 1 * itemsize + 7 * itemsize * (4 - 1) - assert cupy.byte_bounds(b) == (b_low, b_high) - - @testing.for_all_dtypes() - def test_2d_noncontiguous_posneg_stride_2(self, dtype): - a = cupy.zeros((4, 7), dtype=dtype) - b = a[::2, ::-2] # strides = (56, -8), shape=(2, 4) - itemsize = b.itemsize - b_low = b.data.ptr - 2 * itemsize * (4 - 1) - b_high = b.data.ptr + 1 * itemsize + 2 * 7 * itemsize * (2 - 1) - assert cupy.byte_bounds(b) == (b_low, b_high) +import dpnp as cupy +from dpnp.tests.third_party.cupy import testing + + +class TestByteBounds: + + @testing.for_all_dtypes() + def test_1d_contiguous(self, dtype): + a = cupy.zeros(12, dtype=dtype) + itemsize = a.itemsize + a_low = a.data.ptr + a_high = a.data.ptr + 12 * itemsize + assert cupy.byte_bounds(a) == (a_low, a_high) + + @testing.for_all_dtypes() + def test_2d_contiguous(self, dtype): + a = cupy.zeros((4, 7), dtype=dtype) + itemsize = a.itemsize + a_low = a.data.ptr + a_high = a.data.ptr + 4 * 7 * itemsize + assert cupy.byte_bounds(a) == (a_low, a_high) + + @testing.for_all_dtypes() + def test_1d_noncontiguous_pos_stride(self, dtype): + a = cupy.zeros(12, dtype=dtype) + itemsize = a.itemsize + b = a[::2] + b_low = b.data.ptr + b_high = b.data.ptr + 11 * itemsize # a[10] + assert cupy.byte_bounds(b) == (b_low, b_high) + + @testing.for_all_dtypes() + def test_2d_noncontiguous_pos_stride(self, dtype): + a = cupy.zeros((4, 7), dtype=dtype) + b = a[::2, ::2] + itemsize = b.itemsize + b_low = a.data.ptr + b_high = b.data.ptr + 3 * 7 * itemsize # a[2][6] + assert cupy.byte_bounds(b) == (b_low, b_high) + + @testing.for_all_dtypes() + def test_1d_contiguous_neg_stride(self, dtype): + a = cupy.zeros(12, dtype=dtype) + b = a[::-1] + itemsize = b.itemsize + b_low = b.data.ptr - 11 * itemsize + b_high = b.data.ptr + 1 * itemsize + assert cupy.byte_bounds(b) == (b_low, b_high) + + @testing.for_all_dtypes() + def test_2d_noncontiguous_neg_stride(self, dtype): + a = cupy.zeros((4, 7), dtype=dtype) + b = a[::-2, ::-2] # strides = (-56, -8), shape = (2, 4) + itemsize = b.itemsize + b_low = b.data.ptr - 2 * 7 * itemsize * (2 - 1) - 2 * itemsize * (4 - 1) + b_high = b.data.ptr + 1 * itemsize + assert cupy.byte_bounds(b) == (b_low, b_high) + + @testing.for_all_dtypes() + def test_2d_noncontiguous_posneg_stride_1(self, dtype): + a = cupy.zeros((4, 7), dtype=dtype) + b = a[::1, ::-1] # strides = (28, -4), shape=(4, 7) + itemsize = b.itemsize + b_low = b.data.ptr - itemsize * (7 - 1) + b_high = b.data.ptr + 1 * itemsize + 7 * itemsize * (4 - 1) + assert cupy.byte_bounds(b) == (b_low, b_high) + + @testing.for_all_dtypes() + def test_2d_noncontiguous_posneg_stride_2(self, dtype): + a = cupy.zeros((4, 7), dtype=dtype) + b = a[::2, ::-2] # strides = (56, -8), shape=(2, 4) + itemsize = b.itemsize + b_low = b.data.ptr - 2 * itemsize * (4 - 1) + b_high = b.data.ptr + 1 * itemsize + 2 * 7 * itemsize * (2 - 1) + assert cupy.byte_bounds(b) == (b_low, b_high)