Hello,
I'm trying to write up a model in TMB (I'm quite familiar with R, a little bit less familiar with TMB and C++) and having a bit of trouble. I think I'm missing something obvious, but I've looked a bit at previous questions as well as the docs and still can't figure it out. The problem I'm having can be simplified to the short example below:
#include "TMB.hpp"
template<class Type>
Type objective_function<Type>::operator() ()
{
// Data
DATA_MATRIX( M );
// Parameters
PARAMETER_VECTOR( v );
vector<Type> value = M.row(0) + v;
return 0;
}
This piece of code doesn't compile because I can't add M.row(0) to v. I'm a bit confused as to why because M.row(0) should be stored as a vector<Type>, and I should theoretically be able to add two vector<Type>'s elementwise. Of course - I'm not suggesting that there is a bug - just wondering what I'm missing! I understand that obviously if these vectors are different lengths, this poses a problem, but figured that would show up as a runtime error - if I'm missing something let me know! What is the proper way to get "value" - is a for loop required?
Any input is appreciated,
Peter Thompson (he/him)