MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_array_attributes

Function test_array_attributes

tests/test_numpy_array.py:32–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31
32def test_array_attributes():
33 a = np.array(0, "f8")
34 assert m.ndim(a) == 0
35 assert all(m.shape(a) == [])
36 assert all(m.strides(a) == [])
37 with pytest.raises(IndexError) as excinfo:
38 m.shape(a, 0)
39 assert str(excinfo.value) == "invalid axis: 0 (ndim = 0)"
40 with pytest.raises(IndexError) as excinfo:
41 m.strides(a, 0)
42 assert str(excinfo.value) == "invalid axis: 0 (ndim = 0)"
43 assert m.writeable(a)
44 assert m.size(a) == 1
45 assert m.itemsize(a) == 8
46 assert m.nbytes(a) == 8
47 assert m.owndata(a)
48
49 a = np.array([[1, 2, 3], [4, 5, 6]], "u2").view()
50 a.flags.writeable = False
51 assert m.ndim(a) == 2
52 assert all(m.shape(a) == [2, 3])
53 assert m.shape(a, 0) == 2
54 assert m.shape(a, 1) == 3
55 assert all(m.strides(a) == [6, 2])
56 assert m.strides(a, 0) == 6
57 assert m.strides(a, 1) == 2
58 with pytest.raises(IndexError) as excinfo:
59 m.shape(a, 2)
60 assert str(excinfo.value) == "invalid axis: 2 (ndim = 2)"
61 with pytest.raises(IndexError) as excinfo:
62 m.strides(a, 2)
63 assert str(excinfo.value) == "invalid axis: 2 (ndim = 2)"
64 assert not m.writeable(a)
65 assert m.size(a) == 6
66 assert m.itemsize(a) == 2
67 assert m.nbytes(a) == 12
68 assert not m.owndata(a)
69
70
71@pytest.mark.skipif(not hasattr(m, "shape_span"), reason="std::span not available")

Callers

nothing calls this directly

Calls 11

strClass · 0.85
arrayMethod · 0.80
stridesMethod · 0.80
writeableMethod · 0.80
owndataMethod · 0.80
ndimMethod · 0.45
shapeMethod · 0.45
sizeMethod · 0.45
itemsizeMethod · 0.45
nbytesMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected