Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import unittest

from dpnp.tests.third_party.cupy import testing


class TestElementwise(unittest.TestCase):
class TestElementwise:

@testing.for_int_dtypes()
@testing.numpy_cupy_array_equal()
Expand Down
4 changes: 2 additions & 2 deletions dpnp/tests/third_party/cupy/binary_tests/test_packing.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 @@ -11,7 +11,7 @@
)


class TestPacking(unittest.TestCase):
class TestPacking:

@testing.for_int_dtypes()
@testing.numpy_cupy_array_equal()
Expand Down
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 @@ -11,7 +11,7 @@
)


class TestArrayFunction(unittest.TestCase):
class TestArrayFunction:

@testing.with_requires("numpy>=1.17.0")
def test_array_function(self):
Expand Down
9 changes: 6 additions & 3 deletions dpnp/tests/third_party/cupy/core_tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
from __future__ import annotations

import sys
import unittest

import numpy
import pytest

import dpnp as cupy

# from cupy._core import core
from dpnp.tests.third_party.cupy import testing
from dpnp.tests.third_party.cupy.testing._protocol_helpers import (
DummyObjectWithCudaArrayInterface,
DummyObjectWithCuPyGetNDArray,
)

# from cupy_tests.core_tests import test_raw


class TestSize(unittest.TestCase):
class TestSize:

# def tearDown(self):
# # Free huge memory for slow test
Expand Down Expand Up @@ -58,7 +61,7 @@ def test_size_huge(self, xp):


@pytest.mark.skip("no cupy._core submodule")
class TestOrder(unittest.TestCase):
class TestOrder:

@testing.for_orders(_orders.keys())
def test_ndarray(self, order):
Expand Down
179 changes: 72 additions & 107 deletions dpnp/tests/third_party/cupy/core_tests/test_internal.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import math
import unittest
from __future__ import annotations

import numpy
import pytest

# from cupy._core import internal
from dpnp.tests.third_party.cupy import testing

pytest.skip(
"CuPy internal functions are not supported", allow_module_level=True
)


class TestProd(unittest.TestCase):
class TestProd:

def test_empty(self):
assert internal.prod([]) == 1
Expand All @@ -24,7 +22,7 @@ def test_two(self):
assert internal.prod([2, 3]) == 6


class TestProdSequence(unittest.TestCase):
class TestProdSequence:

def test_empty(self):
assert internal.prod_sequence(()) == 1
Expand Down Expand Up @@ -74,7 +72,7 @@ def test_float(self):
assert internal.get_size(1.0) == (1.0,)


class TestVectorEqual(unittest.TestCase):
class TestVectorEqual:

def test_empty(self):
assert internal.vector_equal([], []) is True
Expand All @@ -89,7 +87,7 @@ def test_different_size(self):
assert internal.vector_equal([1, 2, 3], [1, 2]) is False


class TestGetCContiguity(unittest.TestCase):
class TestGetCContiguity:

def test_zero_in_shape(self):
assert internal.get_c_contiguity((1, 0, 1), (1, 1, 1), 3)
Expand Down Expand Up @@ -122,134 +120,101 @@ def test_no_contiguous3(self):
assert not internal.get_c_contiguity((3, 1, 3), (6, 6, 4), 2)


class TestInferUnknownDimension(unittest.TestCase):
class TestInferUnknownDimension:

def test_known_all(self):
assert internal.infer_unknown_dimension((1, 2, 3), 6) == [1, 2, 3]

def test_multiple_unknown(self):
with self.assertRaises(ValueError):
with pytest.raises(ValueError):
internal.infer_unknown_dimension((-1, 1, -1), 10)

def test_infer(self):
assert internal.infer_unknown_dimension((-1, 2, 3), 12) == [2, 2, 3]


@testing.parameterize(
{"slice": (2, 8, 1), "expect": (2, 8, 1)},
{"slice": (2, None, 1), "expect": (2, 10, 1)},
{"slice": (2, 1, 1), "expect": (2, 2, 1)},
{"slice": (2, -1, 1), "expect": (2, 9, 1)},
{"slice": (None, 8, 1), "expect": (0, 8, 1)},
{"slice": (-3, 8, 1), "expect": (7, 8, 1)},
{"slice": (11, 8, 1), "expect": (10, 10, 1)},
{"slice": (11, 11, 1), "expect": (10, 10, 1)},
{"slice": (-11, 8, 1), "expect": (0, 8, 1)},
{"slice": (-11, -11, 1), "expect": (0, 0, 1)},
{"slice": (8, 2, -1), "expect": (8, 2, -1)},
{"slice": (8, None, -1), "expect": (8, -1, -1)},
{"slice": (8, 9, -1), "expect": (8, 8, -1)},
{"slice": (8, -3, -1), "expect": (8, 7, -1)},
{"slice": (None, 8, -1), "expect": (9, 8, -1)},
{"slice": (-3, 6, -1), "expect": (7, 6, -1)},
{"slice": (10, 10, -1), "expect": (9, 9, -1)},
{"slice": (10, 8, -1), "expect": (9, 8, -1)},
{"slice": (9, 10, -1), "expect": (9, 9, -1)},
{"slice": (9, 9, -1), "expect": (9, 9, -1)},
{"slice": (9, 8, -1), "expect": (9, 8, -1)},
{"slice": (8, 8, -1), "expect": (8, 8, -1)},
{"slice": (-9, -8, -1), "expect": (1, 1, -1)},
{"slice": (-9, -9, -1), "expect": (1, 1, -1)},
{"slice": (-9, -10, -1), "expect": (1, 0, -1)},
{"slice": (-9, -11, -1), "expect": (1, -1, -1)},
{"slice": (-9, -12, -1), "expect": (1, -1, -1)},
{"slice": (-10, -9, -1), "expect": (0, 0, -1)},
{"slice": (-10, -10, -1), "expect": (0, 0, -1)},
{"slice": (-10, -11, -1), "expect": (0, -1, -1)},
{"slice": (-10, -12, -1), "expect": (0, -1, -1)},
{"slice": (-11, 8, -1), "expect": (-1, -1, -1)},
{"slice": (-11, -9, -1), "expect": (-1, -1, -1)},
{"slice": (-11, -10, -1), "expect": (-1, -1, -1)},
{"slice": (-11, -11, -1), "expect": (-1, -1, -1)},
{"slice": (-11, -12, -1), "expect": (-1, -1, -1)},
@pytest.mark.parametrize(
("slice_", "expect"),
[
((2, 8, 1), (2, 8, 1)),
((2, None, 1), (2, 10, 1)),
((2, 1, 1), (2, 2, 1)),
((2, -1, 1), (2, 9, 1)),
((None, 8, 1), (0, 8, 1)),
((-3, 8, 1), (7, 8, 1)),
((11, 8, 1), (10, 10, 1)),
((11, 11, 1), (10, 10, 1)),
((-11, 8, 1), (0, 8, 1)),
((-11, -11, 1), (0, 0, 1)),
((8, 2, -1), (8, 2, -1)),
((8, None, -1), (8, -1, -1)),
((8, 9, -1), (8, 8, -1)),
((8, -3, -1), (8, 7, -1)),
((None, 8, -1), (9, 8, -1)),
((-3, 6, -1), (7, 6, -1)),
((10, 10, -1), (9, 9, -1)),
((10, 8, -1), (9, 8, -1)),
((9, 10, -1), (9, 9, -1)),
((9, 9, -1), (9, 9, -1)),
((9, 8, -1), (9, 8, -1)),
((8, 8, -1), (8, 8, -1)),
((-9, -8, -1), (1, 1, -1)),
((-9, -9, -1), (1, 1, -1)),
((-9, -10, -1), (1, 0, -1)),
((-9, -11, -1), (1, -1, -1)),
((-9, -12, -1), (1, -1, -1)),
((-10, -9, -1), (0, 0, -1)),
((-10, -10, -1), (0, 0, -1)),
((-10, -11, -1), (0, -1, -1)),
((-10, -12, -1), (0, -1, -1)),
((-11, 8, -1), (-1, -1, -1)),
((-11, -9, -1), (-1, -1, -1)),
((-11, -10, -1), (-1, -1, -1)),
((-11, -11, -1), (-1, -1, -1)),
((-11, -12, -1), (-1, -1, -1)),
],
)
class TestCompleteSlice(unittest.TestCase):
def test_complete_slice(slice_, expect):
assert internal.complete_slice(slice(*slice_), 10) == slice(*expect)

def test_complete_slice(self):
assert internal.complete_slice(slice(*self.slice), 10) == slice(
*self.expect
)


class TestCompleteSliceError(unittest.TestCase):
class TestCompleteSliceError:

def test_invalid_step_value(self):
with self.assertRaises(ValueError):
with pytest.raises(ValueError):
internal.complete_slice(slice(1, 1, 0), 1)

def test_invalid_step_type(self):
with self.assertRaises(TypeError):
with pytest.raises(TypeError):
internal.complete_slice(slice(1, 1, (1, 2)), 1)

def test_invalid_start_type(self):
with self.assertRaises(TypeError):
with pytest.raises(TypeError):
internal.complete_slice(slice((1, 2), 1, 1), 1)
with self.assertRaises(TypeError):
with pytest.raises(TypeError):
internal.complete_slice(slice((1, 2), 1, -1), 1)

def test_invalid_stop_type(self):
with self.assertRaises(TypeError):
with pytest.raises(TypeError):
internal.complete_slice(slice((1, 2), 1, 1), 1)
with self.assertRaises(TypeError):
with pytest.raises(TypeError):
internal.complete_slice(slice((1, 2), 1, -1), 1)


@testing.parameterize(
{"x": 0, "expect": 0},
{"x": 1, "expect": 1},
{"x": 2, "expect": 2},
{"x": 3, "expect": 4},
{"x": 2**10, "expect": 2**10},
{"x": 2**10 - 1, "expect": 2**10},
{"x": 2**10 + 1, "expect": 2**11},
{"x": 2**40, "expect": 2**40},
{"x": 2**40 - 1, "expect": 2**40},
{"x": 2**40 + 1, "expect": 2**41},
@pytest.mark.parametrize(
("x", "expect"),
[
(0, 0),
(1, 1),
(2, 2),
(3, 4),
(2**10, 2**10),
(2**10 - 1, 2**10),
(2**10 + 1, 2**11),
(2**40, 2**40),
(2**40 - 1, 2**40),
(2**40 + 1, 2**41),
],
)
class TestClp2(unittest.TestCase):

def test_clp2(self):
assert internal.clp2(self.x) == self.expect


@testing.parameterize(
*testing.product(
{
"value": [
0.0,
1.0,
-1.0,
0.25,
-0.25,
11.0,
-11.0,
2**-15,
-(2**-15), # Denormalized Number
float("inf"),
float("-inf"),
],
}
)
)
class TestConvertFloat16(unittest.TestCase):

def test_conversion(self):
half = internal.to_float16(self.value)
assert internal.from_float16(half) == self.value


class TestConvertFloat16Nan(unittest.TestCase):

def test_conversion(self):
half = internal.to_float16(float("nan"))
assert math.isnan(internal.from_float16(half))
def test_clp2(x, expect):
assert internal.clp2(x) == expect
Loading
Loading