File: uses_numpy.py

package info (click to toggle)
python-array-api-compat 1.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 708 kB
  • sloc: python: 3,954; sh: 16; makefile: 15
file content (26 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (3)
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
# Basic test that vendoring works

from .vendored._compat import (
    is_numpy_array,
    is_numpy_namespace,
    numpy as np_compat,
)


import numpy as np

def _test_numpy():
    a = np_compat.asarray([1., 2., 3.])
    b = np_compat.arange(3, dtype=np_compat.float32)

    # np.pow does not exist. Update this to use something else if it is added
    res = np_compat.pow(a, b)
    assert res.dtype == np_compat.float64 == np.float64
    assert isinstance(a, np.ndarray)
    assert isinstance(b, np.ndarray)
    assert isinstance(res, np.ndarray)

    np.testing.assert_allclose(res, [1., 2., 9.])

    assert is_numpy_array(res)
    assert is_numpy_namespace(np) and is_numpy_namespace(np_compat)