9 from pybind11_tests
import buffers
as m
10 from pybind11_tests
import ConstructorStats
12 np = pytest.importorskip(
"numpy")
16 with pytest.raises(RuntimeError)
as excinfo:
17 m.Matrix(np.array([1, 2, 3]))
18 assert str(excinfo.value) ==
"Incompatible buffer format!" 20 m3 = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
23 for i
in range(m4.rows()):
24 for j
in range(m4.cols()):
25 assert m3[i, j] == m4[i, j]
28 assert cstats.alive() == 1
30 assert cstats.alive() == 0
31 assert cstats.values() == [
"2x3 matrix"]
32 assert cstats.copy_constructions == 0
34 assert cstats.copy_assignments == 0
35 assert cstats.move_assignments == 0
48 assert struct.unpack_from(
'f', mat, (3 * 4 + 2) * 4) == (7, )
49 assert struct.unpack_from(
'f', mat, (2 * 4 + 3) * 4) == (4, )
51 mat2 = np.array(mat, copy=
False)
52 assert mat2.shape == (5, 4)
53 assert abs(mat2).
sum() == 11
54 assert mat2[2, 3] == 4
and mat2[3, 2] == 7
56 assert mat2[2, 3] == 5
59 assert cstats.alive() == 1
62 assert cstats.alive() == 1
65 assert cstats.alive() == 0
66 assert cstats.values() == [
"5x4 matrix"]
67 assert cstats.copy_constructions == 0
69 assert cstats.copy_assignments == 0
70 assert cstats.move_assignments == 0
74 """SquareMatrix is derived from Matrix and inherits the buffer protocol""" 76 matrix = m.SquareMatrix(5)
78 assert np.asarray(matrix).shape == (5, 5)
82 for cls
in [m.Buffer, m.ConstBuffer, m.DerivedBuffer]:
84 buf.value = 0x12345678
85 value = struct.unpack(
'i', bytearray(buf))[0]
86 assert value == 0x12345678
90 buf = m.BufferReadOnly(0x64)
92 assert view[0] == b
'd' if env.PY2
else 0x64
97 buf = m.BufferReadOnlySelect()
100 assert buf.value == 0x64
102 io.BytesIO(b
'A').readinto(buf)
103 assert buf.value == ord(b
'A')
106 with pytest.raises(TypeError):
108 with pytest.raises(TypeError):
109 io.BytesIO(b
'1').readinto(buf)
def test_pointer_to_member_fn()
static ConstructorStats & get(std::type_index type)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
def test_readonly_buffer()
def test_inherited_protocol()
def test_selective_readonly_buffer()