Do not call `get_size(None)` in other tests
@@ -7,7 +7,6 @@ import numpy
import pytest
import cupy
-from cupy import core
from cupy import cuda
from cupy.random import _generator
from cupy import testing
@@ -78,6 +77,14 @@ def two_sample_Kolmogorov_Smirnov_test(observed1, observed2):
return d_plus, d_minus, p
+def _get_size(size):
+ # CuPy returns an ndarray of shape () even if size=None.
+ # cf. NumPy returns a Python scalar if size=None.
+ if size is None:
+ return ()
+ return cupy.core.get_size(size)
+
+
class RandomGeneratorTestCase(unittest.TestCase):
target_method = None
@@ -497,7 +504,7 @@ class TestLogNormal(RandomGeneratorTestCase):
vals = self.generate_many(
self.args[0], self.args[1], self.size, dtype, _count=10)
- shape = core.get_size(self.size)
+ shape = _get_size(self.size)
for val in vals:
assert isinstance(val, cupy.ndarray)
assert val.dtype == dtype
@@ -558,7 +565,7 @@ class TestMultivariateNormal(RandomGeneratorTestCase):
mean=self.args[0], cov=self.args[1], size=self.size, tol=self.tol,
dtype=dtype, _count=10)
- shape = core.get_size(self.size)
+ shape = _get_size(self.size)
for val in vals:
assert isinstance(val, cupy.ndarray)
assert val.dtype == dtype
@@ -647,7 +654,7 @@ class TestNormal(RandomGeneratorTestCase):
vals = self.generate_many(
self.args[0], self.args[1], self.size, dtype, _count=10)
- shape = core.get_size(self.size)
+ shape = _get_size(self.size)
for val in vals:
assert isinstance(val, cupy.ndarray)
assert val.dtype == dtype
@@ -742,7 +749,7 @@ class TestRandomSample(unittest.TestCase):
def check_random_sample(self, dtype):
vals = [self.rs.random_sample(self.size, dtype) for _ in range(10)]
- shape = core.get_size(self.size)
+ shape = _get_size(self.size)
for val in vals:
assert isinstance(val, cupy.ndarray)
assert val.dtype == dtype
