def test_empty_like_reshape_nlcpy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), nlcpy, dtype) b = nlcpy.empty_like(a, shape=self.shape) b.fill(0) c = nlcpy.empty(self.shape, order=order, dtype=dtype) c.fill(0) testing.assert_array_equal(b, c)
def test_adv_getitem_nlcpy_indices5(self): a = nlcpy.zeros(self.shape) index = nlcpy.array([4, -5]) original_index = index.copy() b = a[[1, 0], index] b_cpu = a.get()[[1, 0], index.get() % self.shape[1]] testing.assert_array_equal(b, b_cpu) testing.assert_array_equal(original_index, index)
def test_nlcpy_indices_integer_array_3(self): a = nlcpy.zeros(self.shape) index = nlcpy.array([3, -5]) original_index = index.copy() a[[1, 1], index] = nlcpy.array(1.) testing.assert_array_equal(a, nlcpy.array([[0., 0., 0.], [1., 1., 0.]])) testing.assert_array_equal(index, original_index)
def test_adv_getitem_nlcpy_indices3(self): a = nlcpy.zeros(self.shape) index = nlcpy.array([True, False]) original_index = index.copy() b = a[index] b_cpu = a.get()[index.get()] testing.assert_array_equal(b, b_cpu) testing.assert_array_equal(original_index, index)
def test_adv_getitem_nlcpy_indices2(self): a = nlcpy.zeros(self.shape) index = nlcpy.array([1, 0]) original_index = index.copy() b = a[(slice(None), index)] b_cpu = a.get()[(slice(None), index.get())] testing.assert_array_equal(b, b_cpu) testing.assert_array_equal(original_index, index)
def test_nlcpy_indices_boolean_array(self): a = nlcpy.zeros(self.shape) index = nlcpy.array([True, False]) original_index = index.copy() a[index] = nlcpy.array(1.) testing.assert_array_equal(a, nlcpy.array([[1., 1., 1.], [0., 0., 0.]])) testing.assert_array_almost_equal(original_index, index)
def test_asl_random_f(self): self._helper(_test_asl_random_f, '/opt/nec/ve/bin/nfort', 'random_normal_d_', (int64, void_p, float64, float64, uint64), int32) N, seed, D_M, D_S, val = self._prep() err = self.kern(N, veo.OnStack(seed, inout=veo.INTENT_IN), D_M, D_S, val.ve_adr, sync=self.sync, callback=self.callback) testing.assert_array_equal(val, self._exec_random(seed, D_M, D_S, N), err_msg='File-ID: {}'.format(self.lib.id)) if self.sync: assert err == 0
def test_empty_like_reshape_contiguity_nlcpy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), nlcpy, dtype) b = nlcpy.empty_like(a, order=order, shape=self.shape) b.fill(0) c = nlcpy.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_getitem(self): a = nlcpy.arange(numpy.prod(self.shape)).reshape(self.shape) indexes_ve = [] for s in self.indexes: if isinstance(s, numpy.ndarray): s = nlcpy.array(s) indexes_ve.append(s) indexes_ve = tuple(indexes_ve) b = a[indexes_ve] b_cpu = a.get()[self.indexes] testing.assert_array_equal(b, b_cpu)
def test_setitem(self): a_cpu = numpy.arange(numpy.prod(self.shape)).reshape(self.shape) a = nlcpy.array(a_cpu) indexes_ve = [] for s in self.indexes: if isinstance(s, numpy.ndarray): s = nlcpy.array(s) indexes_ve.append(s) indexes_ve = tuple(indexes_ve) a[indexes_ve] = -1 a_cpu[self.indexes] = -1 testing.assert_array_equal(a, a_cpu)
def test_arg_type_f(self): code = string.Template(_test_arg_type_f).substitute( dtype1=_ftypes[self.dtype[0]], dtype2=_ftypes[self.dtype[1]], dtype3=_ftypes[self.dtype[2]], ) self._helper(code, '/opt/nec/ve/bin/nfort', 'test_sum_', (_ctypes[self.dtype[0]], _ctypes[self.dtype[1]]), _ctypes[self.dtype[2]]) res = self.kern(1, 2, sync=True) testing.assert_array_equal(res, 3, err_msg='File-ID: {}'.format(self.lib.id))
def test_asl_sort_f(self): self._helper(_test_asl_sort_f, '/opt/nec/ve/bin/nfort', 'sort_ascending_s_', (int64, uint64, uint64), int32) NX, kyi, kyo = self._prep() err = self.kern(NX, kyi.ve_adr, kyo.ve_adr, sync=self.sync, callback=self.callback) testing.assert_array_equal(kyo, self._exec_sort(kyi), err_msg='File-ID: {}'.format(self.lib.id)) if self.sync: assert err == 0
def test_reshape_contiguity(self): shape_init, shape_final = self.shape_in_out a_nlcpy = testing.shaped_arange(shape_init, xp=nlcpy) a_nlcpy = nlcpy.asarray(a_nlcpy, order=self.order_init) b_nlcpy = a_nlcpy.reshape(shape_final, order=self.order_reshape) a_numpy = testing.shaped_arange(shape_init, xp=numpy) a_numpy = numpy.asarray(a_numpy, order=self.order_init) b_numpy = a_numpy.reshape(shape_final, order=self.order_reshape) assert b_nlcpy.flags.f_contiguous == b_numpy.flags.f_contiguous assert b_nlcpy.flags.c_contiguous == b_numpy.flags.c_contiguous testing.assert_array_equal(b_nlcpy.strides, b_numpy.strides) testing.assert_array_equal(b_nlcpy, b_numpy)
def test_cblas_f(self): self._helper(_test_blas_f, '/opt/nec/ve/bin/nfort', 'test_blas_dgemm_', (int64, int64, int64, uint64, uint64, uint64), int64) M, N, K, a, b, c = self._prep(order='F') err = self.kern(M, N, K, a.ve_adr, b.ve_adr, c.ve_adr, sync=self.sync, callback=self.callback) testing.assert_array_equal(c, self._exec_matmul(a, b), err_msg='File-ID: {}'.format(self.lib.id)) if self.sync: assert err == 0
def test_asl_fft_f(self): self._helper(_test_asl_fft_f, '/opt/nec/ve/bin/nfort', 'fft_complex_1d_multi_s_', (uint64, uint64, uint64, int64, int64), int32) zin, zout_forward, zout_backward, nx, m = self._prep() err = self.kern(zin.ve_adr, zout_forward.ve_adr, zout_backward.ve_adr, nx, m, sync=self.sync, callback=self.callback) testing.assert_array_equal(zout_forward, self._exec_fft(zin, inverse=False), err_msg='File-ID: {}'.format(self.lib.id)) testing.assert_array_equal(zout_backward, self._exec_fft(zout_forward, inverse=True), err_msg='File-ID: {}'.format(self.lib.id)) if self.sync: assert err == 0
def test_zeros_like_reshape_nlcpy_only(self, dtype, order): a = testing.shaped_arange((2, 3, 4), nlcpy, dtype) b = nlcpy.zeros_like(a, shape=self.shape) c = nlcpy.zeros(self.shape, order=order, dtype=dtype) testing.assert_array_equal(b, c)
def test_ones_like_reshape_nlcpy_only(self, dtype): a = testing.shaped_arange((2, 3, 4), nlcpy, dtype) b = nlcpy.ones_like(a, shape=self.shape) c = nlcpy.ones(self.shape, dtype=dtype) testing.assert_array_equal(b, c)