Inconsistent `arena_matrix`/`varmat` interaction between `=` and `+=`
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Opening this one as an issue since I'm not sure what the correct/intentional behaviour should be!
The arena_matrix <-> var_value<Eigen::MatrixXd> interaction currently handles inplace writes differently to assignment.
Where modifying an arena_matrix after creating a var_value will also update the value of the var_value if an inplace write is used, but not if an assignment is used:
#include <stan/math/rev.hpp>
#include <iostream>
int main() {
Eigen::MatrixXd m = Eigen::MatrixXd::Constant(1, 1, 1);
stan::arena_t<Eigen::MatrixXd> a(m);
stan::math::var_value<Eigen::MatrixXd> v(a); // shares a's memory
std::cout << v.val() << "\n";
a += m; // writes in place, v sees the new values
std::cout << v.val() << "\n";
a = a + m; // rebinds a, v keeps the old memory
std::cout << v.val() << std::endl;
}
Returns:
$ ./arena
1
2
2
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 the provided reproducer and inspect the interaction between arena_tEigen::MatrixXd and var_valueEigen::MatrixXd. Determine the intended aliasing behavior for += versus =, then define a consistent expected result and tests for both operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100