如何将Eigen :: SparseMatrix包装在超过3标准压缩行/ colum数组 [英] How to wrap Eigen::SparseMatrix over preexistant 3-standard compress row/colum arrays

查看:396
本文介绍了如何将Eigen :: SparseMatrix包装在超过3标准压缩行/ colum数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我已经提出这个问题,但它被关闭,因为太广泛没有多少解释。我不能看到这个问题可能更具体(它处理特定类的一个特定的库的具体用法...),所以我认为它是一个像主持人的错误,并再次问。 ..

NOTE: I allready asked this question, but it was closed because of "too broad" without much explanation. I can't see how this question could be more specific (it deals with a specific class of a specific library for a specific usage...), so I assume that it was something like a "moderator's mistake" and ask it again...

我想使用Eigen对稀疏矩阵进行稀疏矩阵/矩阵乘法。这些矩阵已经在我在标准3阵列压缩行/列strorage中工作的代码中定义。

I would like to perfom sparse matrix/matrix multiplication using Eigen on sparse matrices. These matrices are already defined in the code I am working on in standard 3-arrays compressed row/column strorage.

然后我想使用Eigen :: SparseMatrix类作为这些数组上的包装器(假定内部使用这种3阵列存储器),以避免在存储器中复制矩阵。我想做如下:

Then I would like to use the Eigen::SparseMatrix class as a wrapper on these arrays (assuming that internally Eigen uses such a 3-arrays storage) in order to avoid to duplicate matrices in memory. I would like to do something like the following:

Eigen::SparseMatrix smin0(n,m);
Eigen::SparseMatrix smin1(m,l);
Eigen::SparseMatrix smout(n,l);

smin0.set_innerPtr(myInnerPtr0);
smin0.set_outerPtr(myOuterPtr0);
smin0.set_valuePtr(myValuePtr0);

smin1.set_innerPtr(myInnerPtr1);
smin1.set_outerPtr(myOuterPtr1);
smin1.set_valuePtr(myValuePtr1);

smout=smin0*smin1;

int *myOutInnerPtr=smout.innerIndexPtr();
int *myOutOuterPtr=smout.outerIndexPtr();
double *myOutValuePtr=smout.valuePtr();

有可能吗?如果是,如何?

Is it possible and if yes, how?

很感谢

推荐答案

ggael指出,您可以使用 Eigen :: MappedSparseMatrix

As ggael pointed out, you can use Eigen::MappedSparseMatrix for that.

之所以不能覆盖 SparseMatrix 的内部指针是当 SparseMatrix 重新分配它们时会导致问题,方式然后Eigen(以及如何Eigen内部分配内存是一个实现细节,你不应该真正依赖在你的代码)。

The reason you can't just overwrite the internal pointers of a SparseMatrix is that this would cause problems when the SparseMatrix deallocates them, but you allocated them in a different way then Eigen does (and how Eigen internally allocates memory is an implementation detail you should not really rely on in your code).

这篇关于如何将Eigen :: SparseMatrix包装在超过3标准压缩行/ colum数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆