Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_binary(self, name, xp, dtype):
a = testing.shaped_arange((2, 3), xp, dtype)
b = testing.shaped_reverse_arange((2, 3), xp, dtype)
return getattr(xp, name)(a, b)
def test_diagflat3(self, xp):
a = testing.shaped_arange((3, 3), xp)
return xp.diagflat(a, -2)
@testing.numpy_cupy_raises()
def test_stack_out_of_bounds(self, xp):
a = testing.shaped_arange((2, 3), xp)
return xp.stack([a, a], axis=3)
@testing.for_float_dtypes()
@testing.numpy_cupy_allclose()
def test_modf(self, xp, dtype):
a = xp.array([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5], dtype=dtype)
b, c = xp.modf(a)
d = xp.empty((2, 7), dtype=dtype)
d[0] = b
d[1] = c
return d
def test_shape_mismatch(self, xp, dtype):
a = testing.shaped_arange(self.shape, xp, dtype)
i = testing.shaped_arange(self.indices, xp, numpy.int32) % 3
o = testing.shaped_arange(self.out_shape, xp, dtype)
wrap_take(a, i, out=o)
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.assert_array_equal(a2, b2)
def test_clip1(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype)
return a.clip(3, 13)
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose()
def test_max_axis1(self, xp, dtype):
a = testing.shaped_random((2, 3, 4), xp, dtype)
return a.max(axis=1)
@testing.for_float_dtypes()
@testing.numpy_cupy_array_equal()
def check_binary_nan(self, name, xp, dtype):
a = xp.array([-3, numpy.NAN, -1, numpy.NAN, 0, numpy.NAN, 2],
dtype=dtype)
b = xp.array([numpy.NAN, numpy.NAN, 1, 0, numpy.NAN, -1, -2],
dtype=dtype)
return getattr(xp, name)(a, b)
import unittest
import cupy
from cupy import cuda
from cupy import testing
import numpy
from numpy import testing as np_testing
@testing.gpu
class TestArrayGet(unittest.TestCase):
_multiprocess_can_split_ = True
def setUp(self):
self.stream = cuda.Stream(null=True)
def check_get(self, f, stream):
a_gpu = f(cupy)
a_cpu = a_gpu.get(stream)
if stream:
stream.synchronize()
b_cpu = f(numpy)
np_testing.assert_array_equal(a_cpu, b_cpu)
@testing.for_all_dtypes()