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