Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/reference/set.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Boolean operations
:toctree: generated/
:nosignatures:

in1d
intersect1d
isin
setdiff1d
Expand Down
62 changes: 12 additions & 50 deletions dpnp/tests/third_party/cupy/core_tests/test_elementwise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest
from __future__ import annotations

import numpy
import pytest
Expand All @@ -12,7 +12,7 @@
from dpnp.tests.third_party.cupy import testing


class TestElementwise(unittest.TestCase):
class TestElementwise:

def check_copy(self, dtype, src_id, dst_id):
with cuda.Device(src_id):
Expand All @@ -33,7 +33,7 @@ def test_copy(self, dtype):
def test_copy_multigpu_nopeer(self, dtype):
if cuda.runtime.deviceCanAccessPeer(0, 1) == 1:
pytest.skip("peer access is available")
with self.assertRaises(ValueError):
with pytest.raises(ValueError):
self.check_copy(dtype, 0, 1)

@pytest.mark.skip("elementwise_copy() argument isn't supported")
Expand Down Expand Up @@ -74,27 +74,26 @@ def test_copy_orders(self, order):


@pytest.mark.skip("`ElementwiseKernel` isn't supported")
class TestElementwiseInvalidShape(unittest.TestCase):
class TestElementwiseInvalidShape:

def test_invalid_shape(self):
with self.assertRaisesRegex(ValueError, "Out shape is mismatched"):
with pytest.raises(ValueError, match="Out shape is mismatched"):
f = cupy.ElementwiseKernel("T x", "T y", "y += x")
x = cupy.arange(12).reshape(3, 4)
y = cupy.arange(4)
f(x, y)


@pytest.mark.skip("`ElementwiseKernel` isn't supported")
class TestElementwiseInvalidArgument(unittest.TestCase):
class TestElementwiseInvalidArgument:

def test_invalid_kernel_name(self):
with self.assertRaisesRegex(ValueError, "Invalid kernel name"):
with pytest.raises(ValueError, match="Invalid kernel name"):
cupy.ElementwiseKernel("T x", "", "", "1")


class TestElementwiseType(unittest.TestCase):
class TestElementwiseType:

@testing.with_requires("numpy>=2.0")
@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_upper_1(self, xp, dtype):
Expand All @@ -105,14 +104,6 @@ def test_large_int_upper_1(self, xp, dtype):
@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_upper_2(self, xp, dtype):
if numpy_version() < "2.0.0":
flag = dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]
if xp.issubdtype(dtype, xp.unsignedinteger) or flag:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([1], dtype=xp.int8)
b = xp.iinfo(dtype).max - 1
return a + b
Expand All @@ -121,62 +112,38 @@ def test_large_int_upper_2(self, xp, dtype):
@testing.numpy_cupy_array_equal()
def test_large_int_upper_3(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
dtype in (numpy.uint64, numpy.ulonglong)
and not has_support_aspect64()
):
pytest.skip("no fp64 support")

a = xp.array([xp.iinfo(dtype).max], dtype=dtype)
b = numpy.int8(0)
b = xp.int8(0)
return a + b

@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal()
def test_large_int_upper_4(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
dtype in (numpy.uint64, numpy.ulonglong)
and not has_support_aspect64()
):
pytest.skip("no fp64 support")

a = xp.array([xp.iinfo(dtype).max - 1], dtype=dtype)
b = numpy.int8(1)
b = xp.int8(1)
return a + b

@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_lower_1(self, xp, dtype):
if numpy_version() < "2.0.0":
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([0], dtype=xp.int8)
b = xp.iinfo(dtype).min
return a + b

@testing.for_int_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_large_int_lower_2(self, xp, dtype):
if numpy_version() < "2.0.0":
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
pytest.skip("numpy doesn't raise OverflowError")

if dtype in [xp.int8, xp.intc] and is_win_platform():
pytest.skip("numpy promotes dtype differently")

a = xp.array([-1], dtype=xp.int8)
b = xp.iinfo(dtype).min + 1
return a + b
Expand All @@ -185,18 +152,13 @@ def test_large_int_lower_2(self, xp, dtype):
@testing.numpy_cupy_array_equal()
def test_large_int_lower_3(self, xp, dtype):
if (
numpy.issubdtype(dtype, numpy.unsignedinteger)
and numpy_version() < "2.0.0"
):
pytest.skip("numpy promotes dtype differently")
elif (
dtype in (numpy.uint64, numpy.ulonglong)
and not has_support_aspect64()
):
pytest.skip("no fp64 support")

a = xp.array([xp.iinfo(dtype).min], dtype=dtype)
b = numpy.int8(0)
b = xp.int8(0)
return a + b

@testing.for_int_dtypes(no_bool=True)
Expand All @@ -209,5 +171,5 @@ def test_large_int_lower_4(self, xp, dtype):
pytest.skip("no fp64 support")

a = xp.array([xp.iinfo(dtype).min + 1], dtype=dtype)
b = numpy.int8(-1)
b = xp.int8(-1)
return a + b
5 changes: 2 additions & 3 deletions dpnp/tests/third_party/cupy/core_tests/test_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import unittest

import numpy
import pytest

import dpnp as cupy
Expand All @@ -23,7 +22,7 @@ def _compile_func(kernel_name, code):
return mod.get_function(kernel_name)


class TestFunction(unittest.TestCase):
class TestFunction:

def test_python_scalar(self):
code = """
Expand Down
28 changes: 15 additions & 13 deletions dpnp/tests/third_party/cupy/core_tests/test_include.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from unittest import mock

import pytest

Expand Down Expand Up @@ -71,22 +72,23 @@ def test_nvcc(self):
_code_nvcc, options=options, arch=arch
)

def test_nvrtc(self):
def test_nvrtc(self, monkeypatch):
cuda_ver = cupy.cuda.runtime.runtimeGetVersion()
options = self._get_options()
for arch in self._get_cuda_archs():
with mock.patch(
"cupy.cuda.compiler._get_arch_for_options_for_nvrtc",
monkeypatch.setattr(
cupy.cuda.compiler,
"_get_arch_for_options_for_nvrtc",
lambda _: (f"-arch=compute_{arch}", "ptx"),
):
)
cupy.cuda.compiler.compile_using_nvrtc(_code_nvrtc, options=options)

if cuda_ver >= 11010:
monkeypatch.setattr(
cupy.cuda.compiler,
"_get_arch_for_options_for_nvrtc",
lambda _: (f"-arch=sm_{arch}", "cubin"),
)
cupy.cuda.compiler.compile_using_nvrtc(
_code_nvrtc, options=options
)
if cuda_ver >= 11010:
with mock.patch(
"cupy.cuda.compiler._get_arch_for_options_for_nvrtc",
lambda _: (f"-arch=sm_{arch}", "cubin"),
):
cupy.cuda.compiler.compile_using_nvrtc(
_code_nvrtc, options=options
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest
from __future__ import annotations

import numpy
import pytest
Expand All @@ -7,7 +7,7 @@
from dpnp.tests.third_party.cupy import testing


class TestConj(unittest.TestCase):
class TestConj:

@testing.for_all_dtypes()
@testing.numpy_cupy_array_almost_equal()
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_conjugate_pass(self, xp, dtype):
return y


class TestAngle(unittest.TestCase):
class TestAngle:

# For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32
# so type_check=False
Expand All @@ -49,7 +49,7 @@ def test_angle(self, xp, dtype):
return xp.angle(x)


class TestRealImag(unittest.TestCase):
class TestRealImag:

@testing.for_all_dtypes()
@testing.numpy_cupy_array_almost_equal(accept_error=False)
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_imag_inplace(self, dtype):
assert cupy.all(x == expected)


class TestScalarConversion(unittest.TestCase):
class TestScalarConversion:

@testing.for_all_dtypes()
def test_scalar_conversion(self, dtype):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest
from __future__ import annotations

from dpnp.tests.third_party.cupy import testing


class TestArrayContiguity(unittest.TestCase):
class TestArrayContiguity:

def test_is_contiguous(self):
a = testing.shaped_arange((2, 3, 4))
Expand Down
67 changes: 40 additions & 27 deletions dpnp/tests/third_party/cupy/core_tests/test_ndarray_conversion.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,69 @@
from __future__ import annotations

import unittest

import numpy
import pytest

import dpnp as cupy

# from cupy.cuda import runtime
from dpnp.tests.third_party.cupy import testing


@testing.parameterize(
{"shape": ()},
{"shape": (1,)},
{"shape": (1, 1, 1)},
@pytest.mark.parametrize(
"shape",
[
(),
(1,),
(1, 1, 1),
],
)
class TestNdarrayItem(unittest.TestCase):
class TestNdarrayItem:

@testing.for_all_dtypes()
@testing.numpy_cupy_equal()
def test_item(self, xp, dtype):
a = xp.full(self.shape, 3, dtype=dtype)
def test_item(self, xp, dtype, shape):
a = xp.full(shape, 3, dtype=dtype)
return a.item()


@testing.parameterize(
{"shape": (0,)},
{"shape": (2, 3)},
{"shape": (1, 0, 1)},
@pytest.mark.parametrize(
"shape",
[
(0,),
(2, 3),
(1, 0, 1),
],
)
class TestNdarrayItemRaise(unittest.TestCase):
class TestNdarrayItemRaise:

def test_item(self):
def test_item(self, shape):
for xp in (numpy, cupy):
a = testing.shaped_arange(self.shape, xp, xp.float32)
a = testing.shaped_arange(shape, xp, xp.float32)
with pytest.raises(ValueError):
a.item()


@testing.parameterize(
{"shape": ()},
{"shape": (1,)},
{"shape": (2, 3)},
{"shape": (2, 3), "order": "C"},
{"shape": (2, 3), "order": "F"},
@pytest.mark.parametrize(
"shape, order",
[
((), None),
((1,), None),
((2, 3), None),
((2, 3), "C"),
((2, 3), "F"),
],
)
class TestNdarrayToBytes(unittest.TestCase):
class TestNdarrayToBytes:

@testing.for_all_dtypes()
@testing.numpy_cupy_equal()
def test_item(self, xp, dtype):
a = testing.shaped_arange(self.shape, xp, dtype)
if hasattr(self, "order"):
return a.tobytes(self.order)
def test_item(self, xp, dtype, shape, order):
# if runtime.is_hip and (
# shape == (1,) or (shape == (2, 3) and order is None)
# ):
# pytest.xfail("ROCm/HIP may have a bug")
a = testing.shaped_arange(shape, xp, dtype)
if order is not None:
return a.tobytes(order)
else:
return a.tobytes()
Loading
Loading