File tree Expand file tree Collapse file tree 4 files changed +109
-28
lines changed Expand file tree Collapse file tree 4 files changed +109
-28
lines changed Original file line number Diff line number Diff line change 77"""
88
99import dpctl
10- import pytest
1110
1211from numba_dpex import dpjit
1312
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation
2+ #
3+ # SPDX-License-Identifier: Apache-2.0
4+
5+ """
6+ Tests for boxing for dpnp.ndarray
7+ """
8+
9+ import dpnp
10+
11+ from numba_dpex import dpjit
12+
13+
14+ def test_boxing_unboxing ():
15+ """Tests basic boxing and unboxing of a dpnp.ndarray object.
16+
17+ Checks if we can pass in and return a dpctl.ndarray object to and
18+ from a dpjit decorated function.
19+ """
20+
21+ @dpjit
22+ def func (a ):
23+ return a
24+
25+ a = dpnp .empty (10 )
26+ try :
27+ b = func (a )
28+ except :
29+ assert False , "Failure during unbox/box of dpnp.ndarray"
30+
31+ assert a .shape == b .shape
32+ assert a .device == b .device
33+ assert a .strides == b .strides
34+ assert a .dtype == b .dtype
35+
36+
37+ def test_stride_calc_at_unboxing ():
38+ """Tests if strides were correctly computed during unboxing."""
39+
40+ def _tester (a ):
41+ return a .strides
42+
43+ b = dpnp .empty ((4 , 16 , 4 ))
44+ strides = dpjit (_tester )(b )
45+
46+ # Numba computes strides as bytes
47+ assert list (strides ) == [512 , 32 , 8 ]
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation
2+ #
3+ # SPDX-License-Identifier: Apache-2.0
4+
5+ """
6+ Tests for boxing for dpnp.ndarray
7+ """
8+
9+ import dpnp
10+ import numpy
11+
12+ from numba_dpex import dpjit
13+
14+
15+ def test_1d_slicing ():
16+ """Tests if dpjit properly computes strides and returns them to Python."""
17+
18+ def _tester (a ):
19+ return a [1 :5 ]
20+
21+ a = dpnp .arange (10 )
22+ b = dpnp .asnumpy (dpjit (_tester )(a ))
23+
24+ na = numpy .arange (10 )
25+ nb = _tester (na )
26+
27+ assert (b == nb ).all ()
28+
29+
30+ def test_1d_slicing2 ():
31+ """Tests if dpjit properly computes strides and returns them to Python."""
32+
33+ def _tester (a ):
34+ b = a [1 :4 ]
35+ a [6 :9 ] = b
36+
37+ a = dpnp .arange (10 )
38+ b = dpnp .asnumpy (dpjit (_tester )(a ))
39+
40+ na = numpy .arange (10 )
41+ nb = _tester (na )
42+
43+ assert (b == nb ).all ()
44+
45+
46+ def test_multidim_slicing ():
47+ """Tests if dpjit properly slices strides and returns them to Python."""
48+
49+ def _tester (a , b ):
50+ b [:, :, 0 ] = a
51+
52+ a = dpnp .arange (64 )
53+ a = a .reshape (4 , 16 )
54+ b = dpnp .empty ((4 , 16 , 4 ))
55+ dpjit (_tester )(a , b )
56+
57+ na = numpy .arange (64 )
58+ na = na .reshape (4 , 16 )
59+ nb = numpy .empty ((4 , 16 , 4 ))
60+ _tester (na , nb )
61+
62+ assert numpy .allclose (nb , dpnp .asnumpy (b ))
You can’t perform that action at this time.
0 commit comments