`operator+=` not defined for `var_value<Eigen::VectorXd>`
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Description
I got an error with this code:
stan::math::var_value<Eigen::MatrixXd> matrix = Eigen::MatrixXd::Random(5, 5);
stan::math::var_value<Eigen::VectorXd> vector = Eigen::VectorXd::Random(5);
vector = stan::math::add(vector, matrix.col(i));
math/stan/math/rev/core/var.hpp:464:24: warning: inline function 'stan::math::var_value<Eigen::Matrix<double, -1, 1, 0, -1, 1>, void>::operator+=' is not defined [-Wundefined-inline]
inline var_value<T>& operator+=(const var_value<T>& b);
...
/tmp/vector_read-829dca.o: In function `read_scalar_varmat(benchmark::State&)':
vector_read.cpp:(.text+0xc9a): undefined reference to `stan::math::var_value<Eigen::Matrix<double, -1, 1, 0, -1, 1>, void>::operator+=(stan::math::var_value<Eigen::Matrix<double, -1, 1, 0, -1, 1>, void> const&)'
I ended up using this code:
vector = stan::math::add(vector, matrix.col(i));
But we should just define operator+= (and make sure all the other operators have implementations)
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 in math/stan/math/rev/core/var.hpp around the declared var_valueEigen::VectorXd::operator+= and inspect the existing var_value operator implementations. Reproduce the linker error from the issue's vector and matrix.col(i) example, then verify that operator+= and the other declared operators have definitions and that the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100