diff --git a/doc/array.rst b/doc/array.rst index adbd9cfb08bf9a9f6f3db46c15efc5d986d3d237..b10c3efc9bcb5a77c6ec45e1425c32fd97ecc574 100644 --- a/doc/array.rst +++ b/doc/array.rst @@ -292,7 +292,7 @@ Constructing :class:`GPUArray` Instances A synonym for the :class:`GPUArray` constructor. -.. function:: zeros(shape, dtype, *, allocator=None, order="C") +.. function:: zeros(shape, dtype=np.float64, *, allocator=None, order="C") Same as :func:`empty`, but the :class:`GPUArray` is zero-initialized before being returned. diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index 316715d82d6daa89c65515614e246ca917753612..100d21cc7a75325d93295bdc8a89d0bf3e439b01 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -1306,7 +1306,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 881ac6e99dce782bbb3a99970dc0ac46ac3b96d4..7091fee9481c52f4109ea1085a0d2cb0fa9765dc 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -1417,6 +1417,12 @@ class TestGPUArray: a[...] = 1729 np.testing.assert_allclose(a.get(), 1729) + def test_default_zero(self): + # This test was added to make sure that + # gpurray.zeros is using np.float64 as the default dtype arg + a_gpu = gpuarray.zeros(10) + assert a_gpu.dtype == np.float64 + @pytest.mark.parametrize("dtype,rtol", [(np.complex64, 1e-6), (np.complex128, 1e-14)]) def test_log10(self, dtype, rtol):