I have an eigen sparse matrix and I would like to multiply it with a vector. However, my vector is stored in a STL vector container because of the way the whole thing is designed. So, I have something like:
std::vector<float> values;
Eigen::SparseMatrix<float> some_mat;
// fill the matrix and vector
....
float * vec = &values[0];
Now is there a way to do something like:
some_mat * vec;
Without copying the vector into an eigen vector object. If there is no way around the copy, what would be the most efficient way to copy an STL vector or a C-array to an eigen VectorXf object?
You can use Eigen::Map
for that purpose:
VectorXd res = some_mat * VectorXf::Map(vec, size);
Note that Map
object are read-write, so res
could also be a Map
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.