-
-
Notifications
You must be signed in to change notification settings - Fork 196
Description
Description
I think that there is a problem with expect_ad, preventing certain expect_ad calls which would otherwise work as intended from compiling.
This test case for example:
TEST(test_unit_math_test_ad, test_ad_show_problem) {
auto f = [](auto& x, auto& y) { return x + y(0); };
Eigen::VectorXd v(3);
v << 1, 2, 3;
stan::test::expect_ad(f, 0, v);
}
Produces this compilation error:
[...]
./test/unit/math/test_ad.hpp:493:21: error: no matching function for call to ‘expect_all_throw(const test_unit_math_test_ad_test_ad_show_problem_Test::TestBody()::<lambda(auto:50&, auto:51&)>&, int&, const Eigen::Matrix<double, -1, 1>&)’
expect_all_throw(f, x1, x2);
[...]
expect_ad here delegates to expect_ad_vv(tols, f, int, T2), and expect_ad_vv(tols, f, int, T2) tries to call expect_all_throw(f, int, T2), but expect_all_throw only has the following signatures:
void expect_all_throw(const F& f, const Eigen::VectorXd& x) {
void expect_all_throw(const F& f, double x1) {
void expect_all_throw(const F& f, double x1, double x2) {
void expect_all_throw(const F& f, double x1, double x2, double x3) {
I think expect_all_throw is only supposed to be called on the serialized form of the functor f?
After trying to call expect_all_throw, and assuming except_all_throw does not catch an exception, expect_ad_vv(tols, f, int, T2) computes the value at the given arguments, and then again at the same arguments with the int converted to a double. After that it delegates to expect_ad_vv(tols, f, T1, T2) which serializes f and delegates to expect_ad_helper, which itself calls expect_all_throw on the serialized form of f.
Example
Above.
Expected Output
expect_ad compiles in this case, test coverage is not reduced.
Current Version:
v3.0.0
Activity
peterwicksstringfield commentedon Dec 22, 2019
Ah. Well now I see why that exception check was there. Ticket updated. I'm going to take another look at this tomorrow. I do think we can get things like "except_ad(f, 0, v)" to compile, but it will take a bit more work.
bob-carpenter commentedon Dec 22, 2019