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:
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_matrixafter creating avar_valuewill also update the value of thevar_valueif an inplace write is used, but not if an assignment is used:Returns: