Exemple #1
0
 def impl_test_addvec(self, dtype):
     x = np.random.normal(scale=5.0, size=(3, 5)).astype(dtype)
     #x = np.zeros((4, 5), dtype=dtype)
     a = np.random.normal(scale=5.0, size=(1, 5)).astype(dtype)
     b = np.random.normal(scale=5.0, size=(3, 1)).astype(dtype)
     x_gpu = gpuarray.to_gpu(x)
     a_gpu = gpuarray.to_gpu(a)
     b_gpu = gpuarray.to_gpu(b)
     out = gpuarray.empty(x.shape, dtype=dtype)
     res = misc.add_matvec(x_gpu, a_gpu, out=out).get()
     assert np.allclose(res, x+a)
     assert np.allclose(misc.add_matvec(x_gpu, b_gpu).get(), x+b)
Exemple #2
0
 def impl_test_binaryop_matvec(self, dtype):
     x = np.random.normal(scale=5.0, size=(3, 5)).astype(dtype)
     #x = np.zeros((4, 5), dtype=dtype)
     a = np.random.normal(scale=5.0, size=(1, 5)).astype(dtype)
     b = np.random.normal(scale=5.0, size=(3, 1)).astype(dtype)
     x_gpu = gpuarray.to_gpu(x)
     a_gpu = gpuarray.to_gpu(a)
     b_gpu = gpuarray.to_gpu(b)
     out = gpuarray.empty(x.shape, dtype=dtype)
     # addition
     res = misc.add_matvec(x_gpu, a_gpu, out=out).get()
     assert np.allclose(res, x+a)
     assert np.allclose(misc.add_matvec(x_gpu, b_gpu).get(), x+b)
     # multiplication
     res = misc.mult_matvec(x_gpu, a_gpu, out=out).get()
     assert np.allclose(res, x*a)
     assert np.allclose(misc.mult_matvec(x_gpu, b_gpu).get(), x*b)
     # division
     res = misc.div_matvec(x_gpu, a_gpu, out=out).get()
     assert np.allclose(res, x/a)
     assert np.allclose(misc.div_matvec(x_gpu, b_gpu).get(), x/b)