Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose()
def test_sum_axis(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
return a.sum(axis=1)
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(atol=1e-5)
def check_binary(self, name, xp, dtype, no_bool=False):
if no_bool and numpy.dtype(dtype).char == '?':
return numpy.int_(0)
a = testing.shaped_arange((2, 3), xp, dtype)
b = testing.shaped_reverse_arange((2, 3), xp, dtype)
return getattr(xp, name)(a, b)
@testing.for_all_dtypes()
@testing.numpy_cupy_array_equal()
def test_adv_getitem(self, xp, dtype):
a = testing.shaped_arange(self.shape, xp, dtype)
if self.transpose:
a = a.transpose(self.transpose)
return a[self.indexes]
@testing.for_all_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal()
def test_linspace(self, xp, dtype):
return xp.linspace(0, 10, 5, dtype=dtype)
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose()
def test_external_trace(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4, 5), xp, dtype)
return xp.trace(a, 1, 3, 2)
@testing.for_all_dtypes()
def test_scan(self, dtype):
element_num = 10000
if dtype in {cupy.int8, cupy.uint8}:
element_num = 100
a = cupy.ones((element_num,), dtype=dtype)
prefix_sum = cupy.core.core.scan(a)
expect = cupy.arange(start=1, stop=element_num + 1).astype(dtype)
testing.assert_array_equal(prefix_sum, expect)
@testing.for_all_dtypes()
def check_savez(self, savez, dtype):
a1 = testing.shaped_arange((2, 3, 4), dtype=dtype)
a2 = testing.shaped_arange((3, 4, 5), dtype=dtype)
sio = six.BytesIO()
savez(sio, a1, a2)
s = sio.getvalue()
sio.close()
sio = six.BytesIO(s)
with cupy.load(sio) as d:
b1 = d['arr_0']
b2 = d['arr_1']
sio.close()
testing.assert_array_equal(a1, b1)
@testing.for_all_dtypes()
@testing.numpy_cupy_array_equal()
def test_fill(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
a.fill(1)
return a
@testing.for_all_dtypes()
def test_broadcast_to_fail_numpy19(self, dtype):
# Note that broadcast_to is only supported on numpy>=1.10
a = testing.shaped_arange((3, 1, 4), cupy, dtype)
with self.assertRaises(ValueError):
cupy.broadcast_to(a, (1, 3, 4))
@testing.for_all_dtypes(name='dtype')
@testing.numpy_cupy_array_equal()
def test_concatenate1(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
b = testing.shaped_reverse_arange((2, 3, 2), xp, dtype)
c = testing.shaped_arange((2, 3, 3), xp, dtype)
return xp.concatenate((a, b, c), axis=2)