'Initializing segments of an Eigen VectorXd
I'd like to efficiently initialize segments of an VectorXd object from the Eigen library. This vector is large (~1e6) so I would like to do this efficiently. Below is an example showing what I was thinking.
size_t N = 1e6;
std::vector<double> F(1., 2., 3., 4.);
Eigen::VectorXd ln_f_origin( F.size() * num_B );
for (size_t i=0; i<F.size(); i++) {
ln_f_origin.segment(i*num_B, num_B) = log(F[i]/num_B);
}
This doesn't seem to be working. I'm getting the following error:
error: no match for 'operator=' (operand types are 'Eigen::DenseBase<Eigen::Matrix<double, -1, 1> >::FixedSegmentReturnType<-1>::Type' {aka 'Eigen::VectorBlock<Eigen::Matrix<double, -1, 1>, -1>'} and 'double')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
