File: test_1847_numpy_array_contiguous.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 (41 lines) | stat: -rw-r--r-- 1,129 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
# 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


def test_reduce_1d_strided():
    non_contiguous_array = np.arange(64, dtype=np.int64)[::3]
    layout = ak.contents.NumpyArray(
        non_contiguous_array,
    )
    assert not layout.is_contiguous
    assert ak.sum(layout, axis=-1) == np.sum(non_contiguous_array, axis=-1)


def test_reduce_transpose_2d():
    non_contiguous_array = np.arange(6 * 8, dtype=np.int64).reshape(6, 8).T
    layout = ak.contents.NumpyArray(
        non_contiguous_array,
    )
    assert not layout.is_contiguous
    assert (
        ak.sum(layout, axis=-1).to_list()
        == np.sum(non_contiguous_array, axis=-1).tolist()
    )


def test_reduce_2d():
    non_contiguous_array = np.arange(6 * 8, dtype=np.int64).reshape(6, 8)
    layout = ak.contents.NumpyArray(
        non_contiguous_array,
    )
    assert layout.is_contiguous
    assert (
        ak.sum(layout, axis=-1).to_list()
        == np.sum(non_contiguous_array, axis=-1).tolist()
    )