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_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.