stan-dev / stan-dev/math

Return types not being checked for consistency in test framework

Open
#2,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Somehow the test framework should be checking that return types are consistent between different autodiff implementations.

What I mean by consistent is if a function returns a matrix in prim, it returns a matrix in rev. This is not the same as returning the same type (since the scalar types will be different in the different versions).

That is not the case currently.

This test passes:

#include <test/unit/math/test_ad.hpp>

template <typename T,
          stan::require_not_var_t<T>* = nullptr>
auto myfunc(const T& x1) {
  T x2 = x1;
  return x2;
}

template <typename T,
          stan::require_var_t<T>* = nullptr>
auto myfunc(const T& x1) {
  Eigen::Matrix<T, -1, -1> x2(1, 1);
  x2 << x1;
  return x2;
}

TEST(MathMixMatFun, mat_vs_var) {
  auto f = [](const auto& x) { return myfunc(x); };

  double d = 2;
  stan::test::expect_ad(f, d);
}
Current Version:

v3.3.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 with test/unit/math/test_ad.hpp and the stan::test::expect_ad call shown in the reproducer. Trace how return values from prim and rev implementations are compared, then add coverage for matrix-versus-scalar return mismatches. Done means the supplied mat_vs_var example is rejected while valid autodiff return shapes remain accepted.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.