如何传递本征矩阵行参考,将其视为向量? [英] How do I pass an Eigen matrix row reference, to be treated as a vector?

查看:54
本文介绍了如何传递本征矩阵行参考,将其视为向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可在Vector参考上运行的函数,例如

I have a function that operates on a Vector reference, e.g.

void auto_bias(const Eigen::VectorXf& v, Eigen:Ref<Eigen::VectorXf>> out)
{
  out = ...
}

,在某个时候,我需要让此函数在Matrix行上运行.现在,由于默认的内存布局是基于列的,所以我不能仅仅将行所指向的数据映射到向量中.那么,如何将行传递到上面的函数中以便可以对其进行操作?

and at some point I need to have this function operate on a Matrix row. Now, because the default memory layout is column-major, I can't just Map<> the data the row points to into a vector. So, how do I go about passing the row into the above function so that I can operate on it?

不太好的解决方案是拥有一个温度矢量,例如

The not-so-pretty solution is to have a temp vector, e.g.

VectorXf tmpVec = matrix.row(5);
auto_bias(otherVector, tmpVec);
matrix.row(5) = tmpVec;

但是有直接方法吗?

推荐答案

您可以允许 Ref<> 具有非默认的内部步幅(也称为增量),如下所示:

You can allow Ref<> to have a non default inner-stride (also called increment), as follows:

Ref<VectorXf, 0, InnerStride<>>

请参阅Ref的文档的示例函数 foo3 .

See the example function foo3 of the Ref's documentation.

即使您传递了真实的 VectorXf ,也可能会导致性能下降.

The downside is a possible loss of performance even when you are passing a true VectorXf.

这篇关于如何传递本征矩阵行参考,将其视为向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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