def test_empty_like_reshape_cupy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), cupy, dtype) b = cupy.empty_like(a, shape=self.shape) b.fill(0) c = cupy.empty(self.shape, order=order, dtype=dtype) c.fill(0) testing.assert_array_equal(b, c)
def test_empty_like_reshape_contiguity_cupy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), cupy, dtype) b = cupy.empty_like(a, order=order, shape=self.shape) b.fill(0) c = cupy.empty(self.shape) c.fill(0) if order in ['f', 'F']: self.assertTrue(b.flags.f_contiguous) else: self.assertTrue(b.flags.c_contiguous) testing.assert_array_equal(b, c)
def test_empty_like_reshape_contiguity2_cupy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), cupy, dtype) a = cupy.asfortranarray(a) b = cupy.empty_like(a, order=order, shape=self.shape) b.fill(0) c = cupy.empty(self.shape) c.fill(0) shape = self.shape if not numpy.isscalar(self.shape) else ( self.shape, ) if (order in ['c', 'C'] or (order in ['k', 'K', None] and len(shape) != a.ndim)): self.assertTrue(b.flags.c_contiguous) else: self.assertTrue(b.flags.f_contiguous) testing.assert_array_equal(b, c)
def test_empty_like_K_strides_reshape(self, dtype): # test strides that are both non-contiguous and non-descending a = testing.shaped_arange((2, 3, 4), numpy, dtype) a = a[:, ::2, :].swapaxes(0, 1) b = numpy.empty_like(a, order='K', shape=self.shape) b.fill(0) # GPU case ag = testing.shaped_arange((2, 3, 4), cupy, dtype) ag = ag[:, ::2, :].swapaxes(0, 1) bg = cupy.empty_like(ag, order='K', shape=self.shape) bg.fill(0) # make sure NumPy and CuPy strides agree self.assertEqual(b.strides, bg.strides) return
def test_empty_like_reshape_contiguity3_cupy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), cupy, dtype) # test strides that are both non-contiguous and non-descending a = a[:, ::2, :].swapaxes(0, 1) b = cupy.empty_like(a, order=order, shape=self.shape) b.fill(0) shape = self.shape if not numpy.isscalar(self.shape) else ( self.shape, ) if len(shape) == 1: self.assertTrue(b.flags.c_contiguous) self.assertTrue(b.flags.f_contiguous) elif order in ['k', 'K', None] and len(shape) == a.ndim: self.assertFalse(b.flags.c_contiguous) self.assertFalse(b.flags.f_contiguous) elif order in ['f', 'F']: self.assertFalse(b.flags.c_contiguous) self.assertTrue(b.flags.f_contiguous) else: self.assertTrue(b.flags.c_contiguous) self.assertFalse(b.flags.f_contiguous) c = cupy.zeros(self.shape) c.fill(0) testing.assert_array_equal(b, c)
def test_empty_like_subok(self): a = testing.shaped_arange((2, 3, 4), cupy) with pytest.raises(TypeError): cupy.empty_like(a, subok=True)