3 from pybind11_tests
import buffers
as m
4 from pybind11_tests
import ConstructorStats
6 pytestmark = pytest.requires_numpy
8 with pytest.suppress(ImportError):
13 with pytest.raises(RuntimeError)
as excinfo:
14 m.Matrix(np.array([1, 2, 3]))
15 assert str(excinfo.value) ==
"Incompatible buffer format!" 17 m3 = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
20 for i
in range(m4.rows()):
21 for j
in range(m4.cols()):
22 assert m3[i, j] == m4[i, j]
25 assert cstats.alive() == 1
27 assert cstats.alive() == 0
28 assert cstats.values() == [
"2x3 matrix"]
29 assert cstats.copy_constructions == 0
31 assert cstats.copy_assignments == 0
32 assert cstats.move_assignments == 0
37 @pytest.unsupported_on_pypy
40 assert memoryview(mat).shape == (5, 4)
47 assert struct.unpack_from(
'f', mat, (3 * 4 + 2) * 4) == (7, )
48 assert struct.unpack_from(
'f', mat, (2 * 4 + 3) * 4) == (4, )
50 mat2 = np.array(mat, copy=
False)
51 assert mat2.shape == (5, 4)
52 assert abs(mat2).sum() == 11
53 assert mat2[2, 3] == 4
and mat2[3, 2] == 7
55 assert mat2[2, 3] == 5
58 assert cstats.alive() == 1
61 assert cstats.alive() == 1
64 assert cstats.alive() == 0
65 assert cstats.values() == [
"5x4 matrix"]
66 assert cstats.copy_constructions == 0
68 assert cstats.copy_assignments == 0
69 assert cstats.move_assignments == 0
72 @pytest.unsupported_on_pypy
74 """SquareMatrix is derived from Matrix and inherits the buffer protocol""" 76 matrix = m.SquareMatrix(5)
77 assert memoryview(matrix).shape == (5, 5)
78 assert np.asarray(matrix).shape == (5, 5)
81 @pytest.unsupported_on_pypy
83 for cls
in [m.Buffer, m.ConstBuffer, m.DerivedBuffer]:
85 buf.value = 0x12345678
86 value = struct.unpack(
'i', bytearray(buf))[0]
87 assert value == 0x12345678
static ConstructorStats & get(std::type_index type)
def test_pointer_to_member_fn()
constexpr std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
def test_inherited_protocol()