Modified Vector STL bind initialization from a buffer type with optimization for simple arrays (#2298)
* Modified Vector STL bind initialization from a buffer type with optimization for simple arrays
* Add subtests to demonstrate processing Python buffer protocol objects with step > 1
* Fixed memoryview step test to only run on Python 3+
* Modified Vector constructor from buffer to return by value for readability
diff --git a/tests/test_stl_binders.py b/tests/test_stl_binders.py
index 27b326f..baa0f4e 100644
--- a/tests/test_stl_binders.py
+++ b/tests/test_stl_binders.py
@@ -85,6 +85,11 @@
mv[2] = '\x06'
assert v[2] == 6
+ if sys.version_info.major > 2:
+ mv = memoryview(b)
+ v = m.VectorUChar(mv[::2])
+ assert v[1] == 3
+
with pytest.raises(RuntimeError) as excinfo:
m.create_undeclstruct() # Undeclared struct contents, no buffer interface
assert "NumPy type info missing for " in str(excinfo.value)
@@ -119,6 +124,10 @@
('y', 'float64'), ('z', 'bool')], align=True)))
assert len(v) == 3
+ b = np.array([1, 2, 3, 4], dtype=np.uint8)
+ v = m.VectorUChar(b[::2])
+ assert v[1] == 3
+
def test_vector_bool():
import pybind11_cross_module_tests as cm