关于C#:将特征稀疏矩阵与C数组相乘 | 珊瑚贝

Multiplying eigen sparse matrix with a C array


我有一个特征稀疏矩阵,我想将它与向量相乘。但是,由于整个事物的设计方式,我的向量存储在 STL 向量容器中。所以,我有类似的东西:

1
2
3
4
5
6
std::vector<float> values;
Eigen::SparseMatrix<float> some_mat;

// fill the matrix and vector
….
float * vec = &values[0];

现在有办法做类似的事情:

1
some_mat * vec;

不将向量复制到特征向量对象中。如果无法绕过复制,将 STL 向量或 C 数组复制到特征 VectorXf 对象的最有效方法是什么?


你可以使用 Eigen::Map 来达到这个目的:

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

注意 Map 对象是可读写的,所以 res 也可以是 Map.


来源:https://www.codenong.com/27135013/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8760.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?