| 118 | |
| 119 | |
| 120 | def test_cpp_casting(): |
| 121 | assert m.cpp_copy(m.fixed_r()) == 22.0 |
| 122 | assert m.cpp_copy(m.fixed_c()) == 22.0 |
| 123 | z = np.array([[5.0, 6], [7, 8]]) |
| 124 | assert m.cpp_copy(z) == 7.0 |
| 125 | assert m.cpp_copy(m.get_cm_ref()) == 21.0 |
| 126 | assert m.cpp_copy(m.get_rm_ref()) == 21.0 |
| 127 | assert m.cpp_ref_c(m.get_cm_ref()) == 21.0 |
| 128 | assert m.cpp_ref_r(m.get_rm_ref()) == 21.0 |
| 129 | with pytest.raises(RuntimeError) as excinfo: |
| 130 | # Can't reference m.fixed_c: it contains floats, m.cpp_ref_any wants doubles |
| 131 | m.cpp_ref_any(m.fixed_c()) |
| 132 | assert "Unable to cast Python instance" in str(excinfo.value) |
| 133 | with pytest.raises(RuntimeError) as excinfo: |
| 134 | # Can't reference m.fixed_r: it contains floats, m.cpp_ref_any wants doubles |
| 135 | m.cpp_ref_any(m.fixed_r()) |
| 136 | assert "Unable to cast Python instance" in str(excinfo.value) |
| 137 | assert m.cpp_ref_any(m.ReturnTester.create()) == 1.0 |
| 138 | |
| 139 | assert m.cpp_ref_any(m.get_cm_ref()) == 21.0 |
| 140 | assert m.cpp_ref_any(m.get_cm_ref()) == 21.0 |
| 141 | |
| 142 | |
| 143 | def test_pass_readonly_array(): |