英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论