简体   繁体   English

特征矩阵乘法

[英]Eigen Matrices multiplication

Why is it necessary to use the noallias() expression when doing matrix product when using c++ eigen library? 在使用c ++特征库时,为什么在使用矩阵乘积时需要使用noallias()表达式?

m1.noalias() += (s1*s2*conj(s3)*s4) * m2.adjoint() * m3.conjugate()

I have been reading some notes about it but still find it difficult to understand. 我一直在阅读有关它的一些注释,但仍然觉得很难理解。

when you are doing a sum like: 当你做一个像:

A=A+B

eigen can directly use the variable A to perform the operation since, each cell of the matrix can be calculated without impacting the calculation of the other cells Ai,j=Ai,j+Bi,j 因为,可以直接使用变量A来执行操作,因为可以计算矩阵的每个单元而不影响其他单元Ai,j=Ai,j+Bi,j

when you are doing a product like: 当你做一个像以下产品:

A=A*B

you can not do the same since if you start calculating and replace A0,0 - then you can not calculate the other A0,j 你不能这样做,因为如果你开始计算并替换A0,0 - 那么你就无法计算其他的A0,j

so by default - when performing assignment of a product operation, a temporary structure is created and the assignment is done afterward (see noalias ). 所以默认情况下 - 在执行产品操作的分配时,会创建一个临时结构,然后完成分配(参见noalias )。

When you use noalias on the source term of an assignment, you "guarantee" that the assigned variable is not part of the terms of the product and that it is safe to not use a temporary structure. 当您在作业的源术语上使用noalias时,您“保证”指定的变量不是产品术语的一部分,并且不使用临时结构是安全的。

This is coming from the fact that Eigen is "lazy" about when performing the operations (meaning that it does it only when necessary and not instantly as we are used to in standard C++) - noalias is the way to tell Eigen that this is also safe to do when doing a product operation and assigning it to a variable. 这是因为Eigen在执行操作时“懒惰”(这意味着它只在必要时执行,而不是像我们在标准C ++中那样立即执行) - noalias是告诉Eigen这也是在进行产品操作并将其分配给变量时可以安全地执行。

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

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