diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index a3dbc100738396b897c5699c0de852e1bee92aa1..73fac7270ad7f5023a88669af448b97f8e0ae037 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -1240,7 +1240,7 @@ def to_gpu_async(ary, allocator=drv.mem_alloc, stream=None): empty = GPUArray -def zeros(shape, dtype, allocator=drv.mem_alloc, order="C"): +def zeros(shape, dtype=np.float64, allocator=drv.mem_alloc, order="C"): """Returns an array of the given shape and dtype filled with 0's.""" result = GPUArray(shape, dtype, allocator, order=order) zero = np.zeros((), dtype) diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py index 73ec3ade3f99e8830882b6271aadd70945e4b4f3..45531210e7702e900c5f91008e5935759dcbe510 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -1297,6 +1297,13 @@ class TestGPUArray: assert new_z.dtype == np.complex64 assert new_z.shape == arr.shape + @mark_cuda_test + def test_default_zero(self): + # This test was added to make sure that + # GPUArray.zeros was reverting to dtype = np.float64 by default + a_gpu = gpuarray.zeros(10) + assert a_gpu.dtype == np.float64 + if __name__ == "__main__": # make sure that import failures get reported, instead of skipping the tests.