eigen auto type deduction in general product

对着背影说爱祢 提交于 2019-11-29 14:49:18

The problem is that Id() returns a temporary which is stored by reference in the object representing the expression Id(Foo, 4) * v. Thus after the auto statement, autoresult stores a reference to a dead object. If you do not want an abstract expression but the actual result, do not use auto or call eval to enforce evaluation:

auto autoresult = (Id(Foo, 4) * v).eval();

A third option is to make the object returned by Id() available for further computations:

auto id4 = Id(Foo,4);
auto autoresult = id4 * v;

but in this case, anytime you use autoresult then the product will be re-evaluated and the following will output different results:

cout << autoresult;
v.setRandom();
cout << autoresult;

It probably has a lazy evaluation type that is only safe to evaluate once. You could capture it with:

auto autoresultmatrix = autoresult.eval()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!