Skip to content

Commit b70c087

Browse files
authored
Merge branch 'master' into fix_asfarray_func
2 parents 6380aa5 + bcbff63 commit b70c087

11 files changed

+75
-89
lines changed

.github/workflows/build-sphinx.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
sudo apt-get install -y nvidia-cuda-toolkit clinfo
5555
5656
- name: Checkout repo
57-
uses: actions/checkout@v3.1.0
57+
uses: actions/checkout@v3.3.0
5858

5959
# https://github.com/marketplace/actions/setup-miniconda
6060
- name: Setup miniconda
@@ -94,7 +94,7 @@ jobs:
9494

9595
# https://github.com/marketplace/actions/doxygen-action
9696
- name: Build backend docs
97-
uses: mattnotmitt/[email protected].4
97+
uses: mattnotmitt/[email protected].5
9898
with:
9999
working-directory: 'dpnp/backend/doc'
100100

@@ -106,7 +106,7 @@ jobs:
106106
if: |
107107
!github.event.pull_request.head.repo.fork &&
108108
(github.ref == 'refs/heads/master' || (startsWith(github.ref, 'refs/heads/release') == true) || github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
109-
uses: peaceiris/[email protected].0
109+
uses: peaceiris/[email protected].2
110110
with:
111111
github_token: ${{ secrets.GITHUB_TOKEN }}
112112
publish_dir: doc/_build/html/

.github/workflows/conda-package.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
access_token: ${{ github.token }}
4848

4949
- name: Checkout DPNP repo
50-
uses: actions/checkout@v3.1.0
50+
uses: actions/checkout@v3.3.0
5151
with:
5252
fetch-depth: 0
5353

@@ -74,7 +74,7 @@ jobs:
7474
run: conda install conda-build
7575

7676
- name: Cache conda packages
77-
uses: actions/cache@v3.0.11
77+
uses: actions/cache@v3.2.6
7878
env:
7979
CACHE_NUMBER: 1 # Increase to reset cache
8080
with:
@@ -89,7 +89,7 @@ jobs:
8989
run: conda build --no-test --python ${{ matrix.python }} ${{ env.CHANNELS }} conda-recipe
9090

9191
- name: Upload artifact
92-
uses: actions/[email protected].1
92+
uses: actions/[email protected].2
9393
with:
9494
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
9595
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.tar.bz2
@@ -124,7 +124,7 @@ jobs:
124124

125125
steps:
126126
- name: Download artifact
127-
uses: actions/[email protected].1
127+
uses: actions/[email protected].2
128128
with:
129129
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
130130
path: ${{ env.pkg-path-in-channel }}
@@ -167,7 +167,7 @@ jobs:
167167
TEST_CHANNELS: '-c ${{ env.channel-path }} ${{ env.CHANNELS }}'
168168

169169
- name: Cache conda packages
170-
uses: actions/cache@v3.0.11
170+
uses: actions/cache@v3.2.6
171171
env:
172172
CACHE_NUMBER: 1 # Increase to reset cache
173173
with:
@@ -228,7 +228,7 @@ jobs:
228228

229229
steps:
230230
- name: Download artifact
231-
uses: actions/[email protected].1
231+
uses: actions/[email protected].2
232232
with:
233233
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
234234
path: ${{ env.pkg-path-in-channel }}
@@ -294,7 +294,7 @@ jobs:
294294
run: more lockfile
295295

296296
- name: Cache conda packages
297-
uses: actions/cache@v3.0.11
297+
uses: actions/cache@v3.2.6
298298
env:
299299
CACHE_NUMBER: 1 # Increase to reset cache
300300
with:
@@ -398,7 +398,7 @@ jobs:
398398
399399
steps:
400400
- name: Download artifact
401-
uses: actions/[email protected].1
401+
uses: actions/[email protected].2
402402
with:
403403
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
404404

.github/workflows/pre-commit.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3.1.0
13-
- uses: actions/setup-python@v4.3.0
12+
- uses: actions/checkout@v3.3.0
13+
- uses: actions/setup-python@v4.5.0
1414
with:
1515
python-version: '3.10'
1616
- uses: pre-commit/[email protected]

dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx

-48
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ __all__ += [
4141
"dpnp_identity",
4242
"dpnp_linspace",
4343
"dpnp_logspace",
44-
"dpnp_meshgrid",
4544
"dpnp_ptp",
4645
"dpnp_trace",
4746
"dpnp_tri",
@@ -222,53 +221,6 @@ cpdef utils.dpnp_descriptor dpnp_logspace(start, stop, num, endpoint, base, dtyp
222221
return dpnp.get_dpnp_descriptor(dpnp.astype(dpnp.power(base, temp), dtype))
223222

224223

225-
cpdef list dpnp_meshgrid(xi, copy, sparse, indexing):
226-
input_count = len(xi)
227-
228-
# simple case
229-
if input_count == 0:
230-
return []
231-
232-
# simple case
233-
if input_count == 1:
234-
return [dpnp_copy(dpnp.get_dpnp_descriptor(xi[0])).get_pyobj()]
235-
236-
shape_mult = 1
237-
for i in range(input_count):
238-
shape_mult = shape_mult * xi[i].size
239-
240-
shape_list = []
241-
for i in range(input_count):
242-
shape_list.append(xi[i].size)
243-
if indexing == "xy":
244-
temp = shape_list[0]
245-
shape_list[0] = shape_list[1]
246-
shape_list[1] = temp
247-
248-
steps = []
249-
for i in range(input_count):
250-
shape_mult = shape_mult // shape_list[i]
251-
steps.append(shape_mult)
252-
if indexing == "xy":
253-
temp = steps[0]
254-
steps[0] = steps[1]
255-
steps[1] = temp
256-
257-
shape = tuple(shape_list)
258-
259-
cdef utils.dpnp_descriptor res_item
260-
result = []
261-
for i in range(input_count):
262-
res_item = utils_py.create_output_descriptor_py(shape, xi[i].dtype, None)
263-
264-
for j in range(res_item.size):
265-
res_item.get_pyobj()[j] = xi[i][(j // steps[i]) % xi[i].size]
266-
267-
result.append(res_item.get_pyobj())
268-
269-
return result
270-
271-
272224
cpdef dpnp_ptp(utils.dpnp_descriptor arr, axis=None):
273225
cdef shape_type_c shape_arr = arr.shape
274226
cdef shape_type_c output_shape

dpnp/dpnp_container.py

+9
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ def eye(N,
180180
return dpnp_array(array_obj.shape, buffer=array_obj, order=order)
181181

182182

183+
def meshgrid(*xi, indexing="xy"):
184+
"""Creates list of `dpnp_array` coordinate matrices from vectors."""
185+
if len(xi) == 0:
186+
return []
187+
arrays = tuple(x.get_array() if isinstance(x, dpnp_array) else x for x in xi)
188+
arrays_obj = dpt.meshgrid(*arrays, indexing=indexing)
189+
return [dpnp_array._create_from_usm_ndarray(array_obj) for array_obj in arrays_obj]
190+
191+
183192
def ones(shape,
184193
*,
185194
dtype=None,

dpnp/dpnp_iface_arraycreation.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,10 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
10101010
10111011
Limitations
10121012
-----------
1013+
Each array instance from `xi` is supported as either :class:`dpnp.dpnp_array` or :class:`dpctl.tensor.usm_ndarray`.
10131014
Parameter ``copy`` is supported only with default value ``True``.
10141015
Parameter ``sparse`` is supported only with default value ``False``.
1016+
Otherwise the function will be executed sequentially on CPU.
10151017
10161018
Examples
10171019
--------
@@ -1045,17 +1047,16 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
10451047
10461048
"""
10471049

1048-
if not use_origin_backend():
1049-
# original limitation
1050-
if indexing not in ["ij", "xy"]:
1051-
checker_throw_value_error("meshgrid", "indexing", indexing, "'ij' or 'xy'")
1052-
1053-
if copy is not True:
1054-
checker_throw_value_error("meshgrid", "copy", copy, True)
1055-
if sparse is not False:
1056-
checker_throw_value_error("meshgrid", "sparse", sparse, False)
1057-
1058-
return dpnp_meshgrid(xi, copy, sparse, indexing)
1050+
if not all((isinstance(x, (dpnp.ndarray, dpt.usm_ndarray)) for x in xi)):
1051+
pass
1052+
elif indexing not in ["ij", "xy"]:
1053+
pass
1054+
elif copy is not True:
1055+
pass
1056+
elif sparse is not False:
1057+
pass
1058+
else:
1059+
return dpnp_container.meshgrid(*xi, indexing=indexing)
10591060

10601061
return call_origin(numpy.meshgrid, xi, copy, sparse, indexing)
10611062

tests/skipped_tests.tbl

-6
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,10 @@ tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy
406406
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid1
407407
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid2
408408
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid3
409-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid1
410-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid2
411-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid3
412409
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid0
413410
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid1
414411
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid2
415412
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid3
416-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid1
417-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid2
418-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid3
419413
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid0
420414
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid1
421415
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid2

tests/skipped_tests_gpu.tbl

-6
Original file line numberDiff line numberDiff line change
@@ -581,16 +581,10 @@ tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy
581581
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid1
582582
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid2
583583
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_3_{copy=False, indexing='ij', sparse=True}::test_meshgrid3
584-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid1
585-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid2
586-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_4_{copy=True, indexing='xy', sparse=False}::test_meshgrid3
587584
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid0
588585
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid1
589586
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid2
590587
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_5_{copy=True, indexing='xy', sparse=True}::test_meshgrid3
591-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid1
592-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid2
593-
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_6_{copy=True, indexing='ij', sparse=False}::test_meshgrid3
594588
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid0
595589
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid1
596590
tests/third_party/cupy/creation_tests/test_ranges.py::TestMeshgrid_param_7_{copy=True, indexing='ij', sparse=True}::test_meshgrid2

tests/test_arraycreation.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,21 @@ def test_dpctl_tensor_input(func, args):
507507
new_args = [eval(val, {'x0' : x0}) for val in args]
508508
X = getattr(dpt, func)(*new_args)
509509
Y = getattr(dpnp, func)(*new_args)
510-
if func is 'empty_like':
510+
if func == 'empty_like':
511511
assert X.shape == Y.shape
512512
else:
513513
assert_array_equal(X, Y)
514+
515+
516+
@pytest.mark.parametrize("arrays",
517+
[[], [[1]], [[1, 2, 3], [4, 5, 6]], [[1, 2], [3, 4], [5, 6]]],
518+
ids=['[]', '[[1]]', '[[1, 2, 3], [4, 5, 6]]', '[[1, 2], [3, 4], [5, 6]]'])
519+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False))
520+
@pytest.mark.parametrize("indexing",
521+
["ij", "xy"],
522+
ids=["ij", "xy"])
523+
def test_meshgrid(arrays, dtype, indexing):
524+
func = lambda xp, xi: xp.meshgrid(*xi, indexing=indexing)
525+
a = tuple(numpy.array(array, dtype=dtype) for array in arrays)
526+
ia = tuple(dpnp.array(array, dtype=dtype) for array in arrays)
527+
assert_array_equal(func(numpy, a), func(dpnp, ia))

tests/test_sycl_queue.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ def test_tril_triu(func, device):
177177
assert_sycl_queue_equal(x.sycl_queue, x0.sycl_queue)
178178

179179

180+
@pytest.mark.parametrize("device_x",
181+
valid_devices,
182+
ids=[device.filter_string for device in valid_devices])
183+
@pytest.mark.parametrize("device_y",
184+
valid_devices,
185+
ids=[device.filter_string for device in valid_devices])
186+
def test_meshgrid(device_x, device_y):
187+
x = dpnp.arange(100, device = device_x)
188+
y = dpnp.arange(100, device = device_y)
189+
z = dpnp.meshgrid(x, y)
190+
assert_sycl_queue_equal(z[0].sycl_queue, x.sycl_queue)
191+
assert_sycl_queue_equal(z[1].sycl_queue, y.sycl_queue)
192+
193+
180194
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
181195
@pytest.mark.parametrize(
182196
"func,data",
@@ -848,8 +862,7 @@ def test_from_dlpack(arr_dtype, shape, device):
848862
Y = dpnp.from_dlpack(X)
849863
assert_array_equal(X, Y)
850864
assert X.__dlpack_device__() == Y.__dlpack_device__()
851-
assert X.sycl_device == Y.sycl_device
852-
assert X.sycl_context == Y.sycl_context
865+
assert_sycl_queue_equal(X.sycl_queue, Y.sycl_queue)
853866
assert X.usm_type == Y.usm_type
854867
if Y.ndim:
855868
V = Y[::-1]
@@ -868,6 +881,5 @@ def test_from_dlpack_with_dpt(arr_dtype, device):
868881
assert_array_equal(X, Y)
869882
assert isinstance(Y, dpnp.dpnp_array.dpnp_array)
870883
assert X.__dlpack_device__() == Y.__dlpack_device__()
871-
assert X.sycl_device == Y.sycl_device
872-
assert X.sycl_context == Y.sycl_context
873884
assert X.usm_type == Y.usm_type
885+
assert_sycl_queue_equal(X.sycl_queue, Y.sycl_queue)

tests/test_usm_type.py

+10
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,13 @@ def test_coerced_usm_types_logic_op(op, usm_type_x, usm_type_y):
117117
assert x.usm_type == zx.usm_type == usm_type_x
118118
assert y.usm_type == zy.usm_type == usm_type_y
119119
assert z.usm_type == du.get_coerced_usm_type([usm_type_x, usm_type_y])
120+
121+
122+
@pytest.mark.parametrize("usm_type_x", list_of_usm_types, ids=list_of_usm_types)
123+
@pytest.mark.parametrize("usm_type_y", list_of_usm_types, ids=list_of_usm_types)
124+
def test_meshgrid(usm_type_x, usm_type_y):
125+
x = dp.arange(100, usm_type = usm_type_x)
126+
y = dp.arange(100, usm_type = usm_type_y)
127+
z = dp.meshgrid(x, y)
128+
assert z[0].usm_type == usm_type_x
129+
assert z[1].usm_type == usm_type_y

0 commit comments

Comments
 (0)