def test_copy_multi_device_non_contiguous(self, order): arr = core.ndarray((20,))[::2] dev1 = cuda.Device(1) with dev1: arr2 = arr.copy(order) assert arr2.device == dev1 testing.assert_array_equal(arr, arr2)
def test_order(self): shape = (2, 3, 4) a = core.ndarray(shape, order='F') a_cpu = numpy.ndarray(shape, order='F') assert a.strides == a_cpu.strides assert a.flags.f_contiguous assert not a.flags.c_contiguous
def _convert_object_with_cuda_array_interface(a): desc = a.__cuda_array_interface__ shape = desc['shape'] dtype = numpy.dtype(desc['typestr']) if 'strides' in desc: strides = desc['strides'] nbytes = numpy.max(numpy.array(shape) * numpy.array(strides)) else: strides = None nbytes = numpy.prod(shape) * dtype.itemsize mem = memory.UnownedMemory(desc['data'][0], nbytes, a) memptr = memory.MemoryPointer(mem, 0) return ndarray(shape, dtype=dtype, memptr=memptr, strides=strides)
def test_copy_multi_device_non_contiguous_K(self): arr = core.ndarray((20,))[::2] with cuda.Device(1): with self.assertRaises(NotImplementedError): arr.copy('K')
def test_deepcopy_multi_device(self): arr = core.ndarray(self.shape) with cuda.Device(1): arr2 = copy.deepcopy(arr) self._check_deepcopy(arr, arr2) assert arr2.device == arr.device
def test_deepcopy(self): arr = core.ndarray(self.shape) arr2 = copy.deepcopy(arr) self._check_deepcopy(arr, arr2)
def test_order_none(self): a = core.ndarray(self.shape, order=None) a_cpu = numpy.ndarray(self.shape, order=None) self.assertEqual(a.flags.c_contiguous, a_cpu.flags.c_contiguous) self.assertEqual(a.flags.f_contiguous, a_cpu.flags.f_contiguous) self.assertTupleEqual(a.strides, a_cpu.strides)
def test_order(self): a = core.ndarray(self.shape, order='F') a_cpu = numpy.ndarray(self.shape, order='F') self.assertTupleEqual(a.strides, a_cpu.strides) self.assertTrue(a.flags.f_contiguous) self.assertTrue(not a.flags.c_contiguous)
def test_shape(self): a = core.ndarray(self.arg) self.assertTupleEqual(a.shape, self.shape)
def setUp(self): self.a = core.ndarray(())