如何获取Eigen::Matrix的行地址

huangapple go评论52阅读模式
英文:

How to get the row address of an Eigen::Matrix

问题

我想将它逐行传递给 ceres 成本函数,所以我想访问它的各行的引用。

我尝试过以下方式:

intensityEigenMat.row(0)

&intensityEigenMat.row(0)

&intensityEigenMat.row(0).data()

但都没有成功。请问正确的语法是什么?

英文:

I have an
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> intensityEigenMat;

I would like to pass it row by row to a ceres cost function, so I would like to access the reference to its individual rows.

I tried using:

intensityEigenMat.row(0)

&intensityEigenMat.row(0)

&intensityEigenMat.row(0).data()

But none of these worked. What is the right syntax please?

答案1

得分: 0

首先,您需要检查存储顺序选项,它可以是ColMajor或RowMajor。默认值是ColMajor,因此您需要以复杂的方式按行读取矩阵(包括一个跨度因子)。

如果允许您更改矩阵的定义为:

Eigen::Matrix<double, Eigen::Dynamic, Eigen::dynamic, Eigen::RowMajor > intensityEigenMat;

那么事情会更容易,您可以使用
intensityEigenMat.row(i).data() 或 intensityEigenMat.data()+i*rowSize

英文:

First you need to check the storage order option, which can be ColMajor or RowMajor.
Default is ColMajor, so you need a complex way to read the matrix row by row (including a stride factor)

If you are allowed to change the definition of your matrix to:

Eigen::Matrix<double, Eigen::Dynamic, Eigen::dynamic, Eigen::RowMajor > intensityEigenMat;

Then things will be easier, and you can use
intensityEigenMat.row(i).data() or intensityEigenMat.data()+i*rowSize

huangapple
  • 本文由 发表于 2023年7月20日 17:41:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定