-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable third party tests for dpnp.size (#2031)
* Enable third party tests for dpnp.size * Applied pre-commit hooks
- Loading branch information
1 parent
d525760
commit aaf8e4e
Showing
2 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,124 @@ | ||
import sys | ||
import unittest | ||
|
||
import numpy | ||
import pytest | ||
|
||
import dpnp as cupy | ||
from tests.third_party.cupy import testing | ||
|
||
|
||
class TestSize(unittest.TestCase): | ||
# def tearDown(self): | ||
# # Free huge memory for slow test | ||
# cupy.get_default_memory_pool().free_all_blocks() | ||
|
||
@testing.for_all_dtypes() | ||
@testing.numpy_cupy_equal() | ||
def test_size(self, xp, dtype): | ||
a = xp.ndarray((2, 3), dtype=dtype) | ||
return xp.size(a) | ||
|
||
@testing.for_all_dtypes() | ||
@testing.numpy_cupy_equal() | ||
def test_size_axis(self, xp, dtype): | ||
a = xp.ndarray((2, 3), dtype=dtype) | ||
return xp.size(a, axis=1) | ||
|
||
@testing.for_all_dtypes() | ||
def test_size_axis_error(self, dtype): | ||
for xp in (numpy, cupy): | ||
a = xp.ndarray((2, 3), dtype=dtype) | ||
with pytest.raises(IndexError): | ||
return xp.size(a, axis=3) | ||
|
||
@testing.numpy_cupy_equal() | ||
@testing.slow | ||
def test_size_huge(self, xp): | ||
a = xp.ndarray(2**32, "b") # 4 GiB | ||
return xp.size(a) | ||
|
||
|
||
_orders = { | ||
order_arg: order_expect | ||
for order_expect, order_args in [ | ||
("C", ["C", "c", "CONTIGUOUS", "", None]), | ||
("F", ["F", "f", "FORTRAN"]), | ||
] | ||
for order_arg in order_args | ||
} | ||
|
||
|
||
@pytest.mark.skip("no cupy._core submodule") | ||
class TestOrder(unittest.TestCase): | ||
@testing.for_orders(_orders.keys()) | ||
def test_ndarray(self, order): | ||
order_expect = _orders[order] | ||
a = core.ndarray((2, 3), order=order) | ||
expect_c = order_expect == "C" | ||
expect_f = order_expect == "F" | ||
assert a.flags.c_contiguous == expect_c | ||
assert a.flags.f_contiguous == expect_f | ||
|
||
|
||
@pytest.mark.skip("min_scalar_type() is not supported") | ||
class TestMinScalarType: | ||
def test_scalar(self): | ||
for v in (-129, -128, 0, 1.2, numpy.inf): | ||
assert cupy.min_scalar_type(v) is numpy.min_scalar_type(v) | ||
|
||
@testing.for_all_dtypes() | ||
def test_numpy_scalar(self, dtype): | ||
sc = dtype(1) | ||
for v in (sc, [sc, sc]): | ||
assert cupy.min_scalar_type(v) is numpy.min_scalar_type(v) | ||
|
||
@testing.for_all_dtypes() | ||
def test_cupy_scalar(self, dtype): | ||
sc = cupy.array(-1).astype(dtype) | ||
for v in (sc, [sc, sc]): | ||
assert cupy.min_scalar_type(v) is sc.dtype | ||
|
||
@testing.for_all_dtypes() | ||
def test_numpy_ndarray(self, dtype): | ||
arr = numpy.array([[-1, 1]]).astype(dtype) | ||
for v in (arr, (arr, arr)): | ||
assert cupy.min_scalar_type(v) is numpy.min_scalar_type(v) | ||
|
||
@testing.for_all_dtypes() | ||
def test_cupy_ndarray(self, dtype): | ||
arr = cupy.array([[-1, 1]]).astype(dtype) | ||
for v in (arr, (arr, arr)): | ||
assert cupy.min_scalar_type(v) is arr.dtype | ||
|
||
|
||
@testing.parameterize( | ||
*testing.product( | ||
{ | ||
"cxx": (None, "--std=c++11"), | ||
} | ||
) | ||
) | ||
@pytest.mark.skip("compiling cupy headers are not supported") | ||
class TestCuPyHeaders(unittest.TestCase): | ||
def setUp(self): | ||
self.temporary_cache_dir_context = test_raw.use_temporary_cache_dir() | ||
self.cache_dir = self.temporary_cache_dir_context.__enter__() | ||
self.header = "\n".join( | ||
["#include <" + h + ">" for h in core._cupy_header_list] | ||
) | ||
|
||
def tearDown(self): | ||
self.temporary_cache_dir_context.__exit__(*sys.exc_info()) | ||
|
||
def test_compiling_core_header(self): | ||
code = r""" | ||
extern "C" __global__ void _test_ker_() { } | ||
""" | ||
code = self.header + code | ||
options = () if self.cxx is None else (self.cxx,) | ||
ker = cupy.RawKernel( | ||
code, "_test_ker_", options=options, backend="nvrtc" | ||
) | ||
ker((1,), (1,), ()) | ||
cupy.cuda.Device().synchronize() |
This file contains 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