def test_set_by_index_src_float64(self): dest_gpu = gpuarray.to_gpu(np.zeros(3, dtype=np.double)) ind = gpuarray.to_gpu(np.array([0, 2, 4])) src_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.double)) misc.set_by_index(dest_gpu, ind, src_gpu, 'src') assert np.allclose(dest_gpu.get(), np.array([0, 2, 4], dtype=np.double)) dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.double)) ind = gpuarray.to_gpu(np.array([], np.int64)) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.double)) misc.set_by_index(dest_gpu, ind, src_gpu, 'src') assert np.allclose(dest_gpu.get(), np.arange(5, dtype=np.double))
def test_set_by_index_dest_float32(self): dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.float32)) ind = gpuarray.to_gpu(np.array([0, 2, 4])) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.float32)) misc.set_by_index(dest_gpu, ind, src_gpu, 'dest') assert np.allclose(dest_gpu.get(), np.array([1, 1, 1, 3, 1], dtype=np.float32)) dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.float32)) ind = gpuarray.to_gpu(np.array([], np.int64)) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.float32)) misc.set_by_index(dest_gpu, ind, src_gpu, 'dest') assert np.allclose(dest_gpu.get(), np.arange(5, dtype=np.float32))
def test_set_by_index_src_float32(self): dest_gpu = gpuarray.to_gpu(np.zeros(3, dtype=np.float32)) ind = gpuarray.to_gpu(np.array([0, 2, 4])) src_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.float32)) misc.set_by_index(dest_gpu, ind, src_gpu, 'src') assert_allclose(dest_gpu.get(), np.array([0, 2, 4], dtype=np.float32), rtol=dtype_to_rtol[np.float32], atol=dtype_to_atol[np.float32]) dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.float32)) ind = gpuarray.to_gpu(np.array([], np.int64)) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.float32)) misc.set_by_index(dest_gpu, ind, src_gpu, 'src') assert_allclose(dest_gpu.get(), np.arange(5, dtype=np.float32), rtol=dtype_to_rtol[np.float32], atol=dtype_to_atol[np.float32])
def test_set_by_index_dest_float64(self): #XXX dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.double)) ind = gpuarray.to_gpu(np.array([0, 2, 4])) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.double)) misc.set_by_index(dest_gpu, ind, src_gpu, 'dest') assert_allclose(dest_gpu.get(), np.array([1, 1, 1, 3, 1], dtype=np.double), rtol=dtype_to_rtol[np.float64], atol=dtype_to_atol[np.float64]) dest_gpu = gpuarray.to_gpu(np.arange(5, dtype=np.double)) ind = gpuarray.to_gpu(np.array([], np.int64)) src_gpu = gpuarray.to_gpu(np.array([1, 1, 1], dtype=np.double)) misc.set_by_index(dest_gpu, ind, src_gpu, 'dest') assert_allclose(dest_gpu.get(), np.arange(5, dtype=np.double), rtol=dtype_to_rtol[np.float64], atol=dtype_to_atol[np.float64])