1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
from __future__ import annotations
import numpy as np
import pytest
import awkward as ak
numba = pytest.importorskip("numba")
ak.numba.register_and_check()
def test_array():
@numba.njit
def f1(x):
return np.array(x)
assert isinstance(
f1(ak.highlevel.Array([[[1], [2], [3]], [[4], [5], [6]]])), np.ndarray
)
assert f1(ak.highlevel.Array([[[1], [2], [3]], [[4], [5], [6]]])).tolist() == [
[[1], [2], [3]],
[[4], [5], [6]],
]
assert f1(ak.highlevel.Array([[1, 2, 3], [4, 5, 6]])).tolist() == [
[1, 2, 3],
[4, 5, 6],
]
assert f1(ak.highlevel.Array([1, 2, 3, 4, 5, 6])).tolist() == [1, 2, 3, 4, 5, 6]
with pytest.raises(ValueError):
f1(ak.highlevel.Array([[1, 2, 3, 4], [5, 6]]))
def test_asarray():
@numba.njit
def f1(x):
return np.asarray(x[-1][1:])
akarray = ak.highlevel.Array(
[[1.1, 2.2, 3.3], [], [4.4, 5.5], [6.6, 7.7, 8.8, 9.9]]
)
nparray = f1(akarray)
assert nparray.tolist() == [7.7, 8.8, 9.9]
|