Skip to content

Commit 3f33c0a

Browse files
mgrid ogrid classes (#366)
* mgrid, ogrid impl
1 parent 1acea67 commit 3f33c0a

File tree

3 files changed

+62
-16
lines changed

3 files changed

+62
-16
lines changed

dpnp/dpnp_iface_arraycreation.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
"linspace",
6565
"logspace",
6666
"meshgrid",
67+
"mgrid",
68+
"ogrid",
6769
"ones",
6870
"ones_like",
6971
"tri",
@@ -771,6 +773,66 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
771773
return call_origin(numpy.meshgrid, xi, copy, sparse, indexing)
772774

773775

776+
class MGridClass:
777+
"""
778+
Construct a dense multi-dimensional "meshgrid".
779+
780+
For full documentation refer to :obj:`numpy.mgrid`.
781+
782+
Examples
783+
--------
784+
>>> import dpnp as np
785+
>>> np.mgrid[0:5,0:5]
786+
array([[[0, 0, 0, 0, 0],
787+
[1, 1, 1, 1, 1],
788+
[2, 2, 2, 2, 2],
789+
[3, 3, 3, 3, 3],
790+
[4, 4, 4, 4, 4]],
791+
[[0, 1, 2, 3, 4],
792+
[0, 1, 2, 3, 4],
793+
[0, 1, 2, 3, 4],
794+
[0, 1, 2, 3, 4],
795+
[0, 1, 2, 3, 4]]])
796+
>>> np.mgrid[-1:1:5j]
797+
array([-1. , -0.5, 0. , 0.5, 1. ])
798+
799+
"""
800+
801+
def __getitem__(self, key):
802+
return dpnp.array(numpy.mgrid[key])
803+
804+
805+
mgrid = MGridClass()
806+
807+
808+
class OGridClass:
809+
"""
810+
Construct an open multi-dimensional "meshgrid".
811+
812+
For full documentation refer to :obj:`numpy.ogrid`.
813+
814+
Examples
815+
--------
816+
>>> import dpnp as np
817+
>>> from numpy import ogrid
818+
>>> ogrid[-1:1:5j]
819+
array([-1. , -0.5, 0. , 0.5, 1. ])
820+
>>> ogrid[0:5,0:5]
821+
[array([[0],
822+
[1],
823+
[2],
824+
[3],
825+
[4]]), array([[0, 1, 2, 3, 4]])]
826+
827+
"""
828+
829+
def __getitem__(self, key):
830+
return dpnp.array(numpy.ogrid[key])
831+
832+
833+
ogrid = OGridClass()
834+
835+
774836
def ones(shape, dtype=None, order='C'):
775837
"""
776838
Return a new array of given shape and type, filled with ones.

tests/skipped_tests.tbl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,7 @@ tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_
321321
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_mixed_start_stop
322322
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_mixed_start_stop2
323323
tests/third_party/cupy/creation_tests/test_ranges.py::TestRanges::test_linspace_start_stop_list
324-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid0
325-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid1
326-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid2
327324
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid3
328-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid4
329-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid5
330-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid0
331-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid1
332-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid2
333325
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid3
334326
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid4
335327
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid5

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,7 @@ tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy
373373
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid1
374374
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid2
375375
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid3
376-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid0
377-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid1
378-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid2
379376
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid3
380-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid4
381-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMgrid::test_mgrid5
382-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid0
383-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid1
384-
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid2
385377
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid3
386378
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid4
387379
tests/third_party/cupy/creation_tests/test_ranges.py::TestOgrid::test_ogrid5

0 commit comments

Comments
 (0)