Add random broadcast tests
@@ -9,6 +9,17 @@ def _dec_shape(shape, dec):
return tuple(1 if s == 1 else max(0, s - dec) for s in shape)
+def _rand1_shape(shape, prob):
+ # return tuple(1 if numpy.random.rand() < prob else s for s in shape)
+ table = {}
+ new_shape = []
+ for s in shape:
+ if s not in table:
+ table[s] = 1 if numpy.random.rand() < prob else s
+ new_shape.append(table[s])
+ return tuple(new_shape)
+
+
class TestEinSumError(unittest.TestCase):
@testing.numpy_cupy_raises()
@@ -107,6 +118,10 @@ class TestEinSumError(unittest.TestCase):
def test_invalid_diagonal2(self, xp):
xp.einsum('ii->', xp.arange(6).reshape(2, 3))
+ @testing.numpy_cupy_raises()
+ def test_invalid_diagonal3(self, xp):
+ xp.einsum('ii', xp.arange(3).reshape(1, 3))
+
# invalid -> operator
@testing.numpy_cupy_raises()
def test_invalid_arrow1(self, xp):
@@ -126,7 +141,9 @@ class TestEinSumError(unittest.TestCase):
@testing.parameterize(
-*testing.product_dict([{'shape_x': 0}, {'shape_x': 1}, {'shape_x': 2}, ], [
+*testing.product_dict(testing.product(
+ {'shape_dec': [0, 1, 2], 'shape_drop': [0, 0.2, 0.8]}
+), [
{'shape_a': (2, 3), 'subscripts': 'ij'}, # do nothing
{'shape_a': (2, 3), 'subscripts': '...'}, # do nothing
{'shape_a': (2, 3), 'subscripts': 'ji'}, # transpose
@@ -165,7 +182,7 @@ class TestEinSumUnaryOperation(unittest.TestCase):
skip_dtypes = (numpy.bool_, numpy.int8, numpy.uint8)
def setUp(self):
- self.shape_a = _dec_shape(self.shape_a, self.shape_x)
+ self.shape_a = _rand1_shape(_dec_shape(self.shape_a, self.shape_dec), self.shape_drop)
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(contiguous_check=False)
@@ -189,7 +206,9 @@ class TestEinSumUnaryOperation(unittest.TestCase):
@testing.parameterize(
-*testing.product_dict([{'shape_x': 0}, {'shape_x': 1}, {'shape_x': 2}, ], [
+*testing.product_dict(testing.product(
+ {'shape_dec': [0, 1, 2], 'shape_drop': [0, 0.2, 0.8]}
+), [
# outer
{'shape_a': (2,), 'shape_b': (3,),
'subscripts': 'i,j'},
@@ -243,8 +262,8 @@ class TestEinSumBinaryOperation(unittest.TestCase):
skip_overflow = False
def setUp(self):
- self.shape_a = _dec_shape(self.shape_a, self.shape_x)
- self.shape_b = _dec_shape(self.shape_b, self.shape_x)
+ self.shape_a = _rand1_shape(_dec_shape(self.shape_a, self.shape_dec), self.shape_drop)
+ self.shape_b = _rand1_shape(_dec_shape(self.shape_b, self.shape_dec), self.shape_drop)
@testing.for_all_dtypes_combination(['dtype_a', 'dtype_b'])
@testing.numpy_cupy_allclose(contiguous_check=False)
