Skip to content

Commit

Permalink
Really add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Mar 20, 2016
1 parent e4884ed commit c6be1f8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ def test_get_by_inds(self):
ind_gpu = gpuarray.to_gpu(ind)

result = gpu.get_by_inds(src_gpu, ind_gpu)
np.allclose(result, src[ind])
assert np.allclose(result, src[ind])

def test_set_by_inds(self):
# Set specified entries in dest_gpu to src_gpu:
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))
gpu.set_by_inds(dest_gpu, ind, src_gpu, 'dest')
assert np.allclose(dest_gpu.get(), np.array([1, 1, 1, 3, 1], dtype=np.float32))

# Set dest_gpu to specified entries in src_gpu:
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))
gpu.set_by_inds(dest_gpu, ind, src_gpu, 'src')
assert np.allclose(dest_gpu.get(), np.array([0, 2, 4], dtype=np.float32))

if __name__ == '__main__':
main()
Expand Down

0 comments on commit c6be1f8

Please sign in to comment.