def test_fixed(): from pybind11_tests import fixed_r, fixed_c, fixed_passthrough_r, fixed_passthrough_c assert_equal_ref(fixed_c()) assert_equal_ref(fixed_r()) assert_equal_ref(fixed_passthrough_r(fixed_r())) assert_equal_ref(fixed_passthrough_c(fixed_c())) assert_equal_ref(fixed_passthrough_r(fixed_c())) assert_equal_ref(fixed_passthrough_c(fixed_r()))
def test_fixed(): from pybind11_tests import fixed_r, fixed_c, fixed_copy_r, fixed_copy_c assert_equal_ref(fixed_c()) assert_equal_ref(fixed_r()) assert_equal_ref(fixed_copy_r(fixed_r())) assert_equal_ref(fixed_copy_c(fixed_c())) assert_equal_ref(fixed_copy_r(fixed_c())) assert_equal_ref(fixed_copy_c(fixed_r()))
def test_pass_readonly_array(): from pybind11_tests import fixed_copy_r, fixed_r, fixed_r_const z = np.full((5, 6), 42.0) z.flags.writeable = False np.testing.assert_array_equal(z, fixed_copy_r(z)) np.testing.assert_array_equal(fixed_r_const(), fixed_r()) assert not fixed_r_const().flags.writeable np.testing.assert_array_equal(fixed_copy_r(fixed_r_const()), fixed_r_const())
def test_cpp_casting(): from pybind11_tests import (cpp_copy, cpp_ref_c, cpp_ref_r, cpp_ref_any, fixed_r, fixed_c, get_cm_ref, get_rm_ref, ReturnTester) assert cpp_copy(fixed_r()) == 22. assert cpp_copy(fixed_c()) == 22. z = np.array([[5., 6], [7, 8]]) assert cpp_copy(z) == 7. assert cpp_copy(get_cm_ref()) == 21. assert cpp_copy(get_rm_ref()) == 21. assert cpp_ref_c(get_cm_ref()) == 21. assert cpp_ref_r(get_rm_ref()) == 21. with pytest.raises(RuntimeError) as excinfo: # Can't reference fixed_c: it contains floats, cpp_ref_any wants doubles cpp_ref_any(fixed_c()) assert 'Unable to cast Python instance' in str(excinfo.value) with pytest.raises(RuntimeError) as excinfo: # Can't reference fixed_r: it contains floats, cpp_ref_any wants doubles cpp_ref_any(fixed_r()) assert 'Unable to cast Python instance' in str(excinfo.value) assert cpp_ref_any(ReturnTester.create()) == 1. assert cpp_ref_any(get_cm_ref()) == 21. assert cpp_ref_any(get_cm_ref()) == 21.