autodiff test framework is not testing first gradients
Open
Nobody has claimed this yet.
good first issue
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Description
Add this code to stan/math/fwd/fun/inv.hpp:
template <typename T>
inline fvar<fvar<T>> inv(const fvar<fvar<T>>& x) {
T x_sq = square(x.val_.val_);
fvar<T> first(1 / x.val_.val_, 100.0); // incorrect, second argument should be -x.val_.d_ / x_sq
fvar<T> second(-x.d_.val_ / x_sq, -x.d_.d_ / x_sq + 2 * x.val_.d_ * x.d_.val_ / (x.val_.val_ * x_sq));
return fvar<fvar<T>>(first, second);
}
./runTests.py test/unit/math/mix/fun/inv_test.cpp will pass even though the first gradient is wrong.
I'm attaching a rendered copy of the Nomad manual cause that's where I'm getting the eqs and terminology and such (check table 2):
autodiff.pdf
Expected Output
This should throw an error when there is a bug.
Current Version:
v3.4.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with stan/math/fwd/fun/inv.hpp and test/unit/math/mix/fun/inv_test.cpp. Run ./runTests.py test/unit/math/mix/fun/inv_test.cpp to inspect why the incorrect first gradient passes. Done means the test throws an error when the first gradient is wrong.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100