简体   繁体   English

将本征稀疏矩阵与C数组相乘

[英]Multiplying eigen sparse matrix with a C array

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. 但是,由于整个对象的设计方式,我的向量存储在STL向量容器中。 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? 如果没有办法解决复制问题,将STL向量或C数组复制到本征VectorXf对象的最有效方法是什么?

You can use Eigen::Map for that purpose: 您可以将Eigen::Map用于此目的:

VectorXd res = some_mat * VectorXf::Map(vec, size);

Note that Map object are read-write, so res could also be a Map . 请注意, Map对象是可读写的,因此res也可以是Map

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM