def test_xcov_cputensor(): np.random.seed(0) n = 10 k = 8 (k1, k2) = (3, 5) a = np.array(np.random.randn(k, n) * 10, dtype='float32', order='C') acc = xcc(a[:k1], a[k1:]) expected_result = 0.5 * (acc**2.).sum() be = CPU(rng_seed=0) outputs = CPUTensor(a.copy()) tempbuf1 = be.empty((k1, n)) tempbuf2 = be.empty((k2, n)) tempbuf3 = be.empty((k1, k2)) tempbuf4 = be.empty(outputs.shape) temp = [tempbuf1, tempbuf2, tempbuf3, tempbuf4] my_result = xcov_cost(be, outputs, [], temp, k1) assert_tensor_near_equal(expected_result, my_result)
def test_xcov_cputensor(): np.random.seed(0) n = 10 k = 8 (k1, k2) = (3, 5) a = np.array(np.random.randn(k, n)*10, dtype='float32', order='C') acc = xcc(a[:k1], a[k1:]) expected_result = 0.5 * (acc**2.).sum() be = CPU(rng_seed=0) outputs = CPUTensor(a.copy()) tempbuf1 = be.empty((k1, n)) tempbuf2 = be.empty((k2, n)) tempbuf3 = be.empty((k1, k2)) tempbuf4 = be.empty(outputs.shape) temp = [tempbuf1, tempbuf2, tempbuf3, tempbuf4] my_result = xcov_cost(be, outputs, [], temp, k1) assert_tensor_near_equal(expected_result, my_result)
def test_xcov_cc2tensor(): np.random.seed(0) n = 10 k = 8 (k1, k2) = (3, 5) a = np.array(np.random.randn(k, n) * 10, dtype='float32', order='C') acc = xcc(a[:k1], a[k1:]) expected_result = 0.5 * (acc**2.).sum() from neon.backends.cc2 import GPU, GPUTensor be = GPU(rng_seed=0) # to ensure cublas_init() is called. outputs = GPUTensor(a.copy()) tempbuf1 = be.empty((k1, n)) tempbuf2 = be.empty((k2, n)) tempbuf3 = be.empty((k1, k2)) tempbuf4 = be.empty(outputs.shape) temp = [tempbuf1, tempbuf2, tempbuf3, tempbuf4] my_result = xcov_cost(be, outputs, [], temp, k1) assert_tensor_near_equal(expected_result, my_result, tolerance=1e-3)
def test_xcov_cc2tensor(): np.random.seed(0) n = 10 k = 8 (k1, k2) = (3, 5) a = np.array(np.random.randn(k, n)*10, dtype='float32', order='C') acc = xcc(a[:k1], a[k1:]) expected_result = 0.5 * (acc**2.).sum() from neon.backends.cc2 import GPU, GPUTensor be = GPU(rng_seed=0) # to ensure cublas_init() is called. outputs = GPUTensor(a.copy()) tempbuf1 = be.empty((k1, n)) tempbuf2 = be.empty((k2, n)) tempbuf3 = be.empty((k1, k2)) tempbuf4 = be.empty(outputs.shape) temp = [tempbuf1, tempbuf2, tempbuf3, tempbuf4] my_result = xcov_cost(be, outputs, [], temp, k1) assert_tensor_near_equal(expected_result, my_result, tolerance=1e-3)