File: test_2917_round.py

package info (click to toggle)
python-awkward 2.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,932 kB
  • sloc: python: 178,875; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (43 lines) | stat: -rw-r--r-- 965 bytes parent folder | download
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
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import numpy as np

import awkward as ak
from awkward.operations import to_list


def test_round():
    """
    Testing Awkward implementations (cpu backend) of real, imag, and angle
    """
    arr_1 = ak.Array(
        [[1 + 0.111j, 2 + 0.222j, 3 + 0.333j], [], [4 + 0.444j, 5 + 0.555j]]
    )
    arr_2 = ak.Array([-2.5, -1.5, -0.6, -0.5, -0.4, 0.4, 0.5, 0.6, 1.5, 2.5])

    assert to_list(np.round(arr_1)) == [
        [(1 + 0j), (2 + 0j), (3 + 0j)],
        [],
        [(4 + 0j), (5 + 1j)],
    ]

    assert to_list(np.round(arr_1, decimals=2)) == [
        [(1 + 0.11j), (2 + 0.22j), (3 + 0.33j)],
        [],
        [(4 + 0.44j), (5 + 0.56j)],
    ]

    assert to_list(np.round(arr_2)) == [
        -2.0,
        -2.0,
        -1.0,
        -0.0,
        -0.0,
        0.0,
        0.0,
        1.0,
        2.0,
        2.0,
    ]