File: test_2495_concatenate_typetracer.py

package info (click to toggle)
python-awkward 2.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 23,088 kB
  • sloc: python: 148,689; cpp: 33,562; sh: 432; makefile: 21; javascript: 8
file content (51 lines) | stat: -rw-r--r-- 1,848 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
44
45
46
47
48
49
50
51
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import numpy as np
import pytest  # noqa: F401

import awkward as ak
from awkward._nplikes.shape import unknown_length


def test_mixed_known_lengths():
    first = ak.from_numpy(np.arange(3 * 4).reshape(3, 4), highlevel=False)
    first_tt = first.to_typetracer(forget_length=False)

    second = ak.from_numpy(6 - np.arange(3 * 4).reshape(3, 4) * 2, highlevel=False)
    second_tt = second.to_typetracer(forget_length=True)

    result_tt = ak.concatenate((first_tt, second_tt), axis=1)
    result = ak.concatenate((first, second), axis=1)

    assert result_tt.layout.form == result.layout.form
    assert result_tt.layout.length == result.layout.length == 3


def test_known_lengths():
    first = ak.from_numpy(np.arange(3 * 4).reshape(3, 4), highlevel=False)
    first_tt = first.to_typetracer(forget_length=False)

    second = ak.from_numpy(6 - np.arange(3 * 4).reshape(3, 4) * 2, highlevel=False)
    second_tt = second.to_typetracer(forget_length=False)

    result_tt = ak.concatenate((first_tt, second_tt), axis=1)
    result = ak.concatenate((first, second), axis=1)

    assert result_tt.layout.form == result.layout.form
    assert result_tt.layout.length == result.layout.length == 3


def test_unknown_lengths():
    first = ak.from_numpy(np.arange(3 * 4).reshape(3, 4), highlevel=False)
    first_tt = first.to_typetracer(forget_length=True)

    second = ak.from_numpy(6 - np.arange(3 * 4).reshape(3, 4) * 2, highlevel=False)
    second_tt = second.to_typetracer(forget_length=True)

    result_tt = ak.concatenate((first_tt, second_tt), axis=1)
    result = ak.concatenate((first, second), axis=1)

    assert result_tt.layout.form == result.layout.form
    assert result_tt.layout.length is unknown_length