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

Function test_vector_buffer_numpy

tests/test_stl_binders.py:90–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88
89
90def test_vector_buffer_numpy():
91 np = pytest.importorskip("numpy")
92 a = np.array([1, 2, 3, 4], dtype=np.int32)
93 with pytest.raises(TypeError):
94 m.VectorInt(a)
95
96 a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.uintc)
97 v = m.VectorInt(a[0, :])
98 assert len(v) == 4
99 assert v[2] == 3
100 ma = np.asarray(v)
101 ma[2] = 5
102 assert v[2] == 5
103
104 v = m.VectorInt(a[:, 1])
105 assert len(v) == 3
106 assert v[2] == 10
107
108 v = m.get_vectorstruct()
109 assert v[0].x == 5
110 ma = np.asarray(v)
111 ma[1]["x"] = 99
112 assert v[1].x == 99
113
114 v = m.VectorStruct(
115 np.zeros(
116 3,
117 dtype=np.dtype(
118 [("w", "bool"), ("x", "I"), ("y", "float64"), ("z", "bool")], align=True
119 ),
120 )
121 )
122 assert len(v) == 3
123
124 b = np.array([1, 2, 3, 4], dtype=np.uint8)
125 v = m.VectorUChar(b[::2])
126 assert v[1] == 3
127
128
129def test_vector_bool():

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
arrayMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected