stan-dev / stan-dev/math

Some expect_ad calls fail to compile

Open
#1,533 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

testing
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in test/unit/math/test_ad.hpp with the supplied test_ad_show_problem case, then trace the expect_ad_vv and expect_all_throw overloads described in the issue. Confirm the fix by compiling that test case and ensuring expect_ad still provides the intended test coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.