Skip to content

Commit

Permalink
Added np.float64 as default value for GPUArray.zeros
Browse files Browse the repository at this point in the history
commit c1f21281d85952e576c6ae0d41b2e1f94ea206d7
Merge: 2b10eb4 db77dc7
Author: Mit Kotak <[email protected]>
Date:   Tue Aug 9 15:46:55 2022 -0500

    Merge branch 'main' into gpuarray_zeros

commit 2b10eb466a275f3ec32923435ac47c5cf9a80aad
Merge: 601036d 09fd4c3
Author: Mit Kotak <[email protected]>
Date:   Tue Aug 9 14:26:42 2022 -0500

    merged complex changes

commit 601036df6e4dfbe70169a9f00476ea404602814c
Merge: 0c835ea 540bf67
Author: Mit Kotak <[email protected]>
Date:   Thu Aug 4 23:02:36 2022 -0500

    Merge branch 'gpuarray_zeros' of https://gitlab.tiker.net/kaushikcfd/pycuda into gpuarray_zeros

commit 0c835ea23b6568fee93ca217dd91aa606aa1eda0
Merge: 5ea3b74 0569ba1
Author: Mit Kotak <[email protected]>
Date:   Thu Aug 4 23:02:28 2022 -0500

    changed docs as well

commit 540bf673db56284d836d062586146aa97dadd02d
Author: Kaushik Kulkarni <[email protected]>
Date:   Fri Aug 5 04:00:42 2022 +0000

    Apply 1 suggestion(s) to 1 file(s)

commit 0569ba1b07ae44b68cad64c5e7ee369e244955dd
Author: Kaushik Kulkarni <[email protected]>
Date:   Sat Jul 2 23:23:17 2022 +0000

    Reduce test array size

commit 2a7fe4469c24905c338a9f0897d96d497bbf31b9
Author: Mit Kotak <[email protected]>
Date:   Sat Jul 2 13:09:01 2022 -0500

    added dtype default to gpuarray.zeros

commit 5ea3b744a8a4b6ba87d1d1d603d684ff4c29893d
Merge: 1425293 6daaeb1
Author: Mit Kotak <[email protected]>
Date:   Mon Jul 25 18:35:09 2022 -0500

    Merge branch 'gpuarray_zeros' of https://gitlab.tiker.net/kaushikcfd/pycuda into gpuarray_zeros

commit 6daaeb13f90f24d4377c8954af0e810df9059243
Author: Kaushik Kulkarni <[email protected]>
Date:   Sat Jul 2 23:23:17 2022 +0000

    Reduce test array size

commit 9827f9c04abfbe6de9fb9dfaad570d0bdae6f07f
Author: Mit Kotak <[email protected]>
Date:   Sat Jul 2 13:09:01 2022 -0500

    added dtype default to gpuarray.zeros

commit 14252930a1c89633a7f4c7c7ce6ce86e499ada3c
Author: Kaushik Kulkarni <[email protected]>
Date:   Sat Jul 2 23:23:17 2022 +0000

    Reduce test array size

commit b886882b561b25ce4110ca448d692f7612c399dc
Author: Mit Kotak <[email protected]>
Date:   Sat Jul 2 13:09:01 2022 -0500

    added dtype default to gpuarray.zeros
  • Loading branch information
inducer committed Aug 9, 2022
1 parent 5c700d2 commit a25ed98
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pycuda/gpuarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/test_gpuarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,12 @@ def test_setitem_scalar(self):
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):
Expand Down

0 comments on commit a25ed98

Please sign in to comment.