Skip to content

Commit 601789a

Browse files
author
Diptorup Deb
committed
Unit tests for Range/NdRange constructor overloads
1 parent 84de964 commit 601789a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
import pytest
6+
7+
from numba_dpex import NdRange, Range, dpjit
8+
9+
ranges = [(10,), (10, 10), (10, 10, 10)]
10+
11+
12+
@pytest.mark.parametrize("r", ranges)
13+
def test_range_ctor(r):
14+
@dpjit
15+
def _tester(r):
16+
return Range(*r)
17+
18+
r_expected = Range(*r)
19+
r_out = _tester(r)
20+
21+
assert r_out.ndim == r_expected.ndim
22+
assert r_out.dim0 == r_expected.dim0
23+
assert r_out.dim1 == r_expected.dim1
24+
assert r_out.dim2 == r_expected.dim2
25+
26+
27+
@pytest.mark.parametrize("r", ranges)
28+
def test_ndrange_unbox_box(r):
29+
@dpjit
30+
def _tester(r):
31+
gr = lr = Range(*r)
32+
return NdRange(gr, lr)
33+
34+
gr = lr = Range(*r)
35+
r_expected = NdRange(gr, lr)
36+
r_out = _tester(r)
37+
38+
assert r_out.global_range.ndim == r_expected.global_range.ndim
39+
assert r_out.local_range.ndim == r_expected.local_range.ndim
40+
assert r_out.global_range.dim0 == r_expected.global_range.dim0
41+
assert r_out.global_range.dim1 == r_expected.global_range.dim1
42+
assert r_out.global_range.dim2 == r_expected.global_range.dim2
43+
assert r_out.local_range.dim0 == r_expected.local_range.dim0
44+
assert r_out.local_range.dim1 == r_expected.local_range.dim1
45+
assert r_out.local_range.dim2 == r_expected.local_range.dim2

0 commit comments

Comments
 (0)