eigen

Eigen: Return a reference to a block of a matrix with compile-time dimension checks

左心房为你撑大大i 提交于 2019-12-10 14:43:38
问题 What I am asking is a generalization of this question. Specifically, I would like to make a C++ Eigen wrapper around a legacy C and Fortran library, which uses a 2D data-structure: [ x[0,0] ... x[0,w-1] ] [ u[0,0] ... u[0,w-1] ] [ ... ] [ x[c-1,0] ... x[c-1,w-1] ] [ u[c-1,0] ... u[c-1,w-1] ] where each of the entries x[i,j] and u[i,j] are themselves column vectors of size ( nx1 ) and ( mx1 ) respectively. This leads to some complicated (and error prone) pointer arithmetic as well as some very

Constructing diagonal matrix in eigen

人盡茶涼 提交于 2019-12-10 12:38:20
问题 In eigen, we can create a matrix as Matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; How can I create a diagonal matrix like the one below 3, 0, 0, 0, 8, 0, 0, 0, 6; I don't understand how Eigen handle diagonal matrix? Only the diagonal elements are important here. So does Eigen save all 9 elements from above example or Eigen just save only 3 elements 3,8,6. Also, if eigen save all 9 elements then is it necessary to define the matrix as diagonal or is it the same as defining normal 3*3 matrix? 回答1

激光SLAM学习笔记

我的梦境 提交于 2019-12-10 12:28:23
位姿表示与旋转矩阵 作业 # include <iostream> # include <Eigen/Core> # include <Eigen/Geometry> using namespace std ; int main ( int argc , char * * argv ) { // 机器人B在坐标系O中的坐标: Eigen :: Vector3d B ( 3 , 4 , M_PI ) ; // 坐标系B到坐标O的转换矩阵: Eigen :: Matrix3d TOB ; TOB << cos ( B ( 2 ) ) , - sin ( B ( 2 ) ) , B ( 0 ) , sin ( B ( 2 ) ) , cos ( B ( 2 ) ) , B ( 1 ) , 0 , 0 , 1 ; //向量、矩阵赋值使用 “<<” // 坐标系O到坐标B的转换矩阵: Eigen :: Matrix3d TBO = TOB . inverse ( ) ; // 机器人A在坐标系O中的坐标: Eigen :: Vector3d A ( 1 , 3 , - M_PI / 2 ) ; // 求机器人A在机器人B中的坐标: Eigen :: Vector3d BA ; // TODO 参照PPT // start your code here (5~10 lines) Eigen :

Eigen学习笔记2-Matrix类

北慕城南 提交于 2019-12-10 11:47:14
原文:Eigen官网- The Matrix class 在Eigen中,所有的矩阵Matrix和向量Vector都是由Matrix类构造的。向量只不过是矩阵的特殊形式,只有一列(列向量)或者一行(行向量)。 Matrix类的参数 Matrix有6个模板参数,主要使用前三个参数,剩下的三个参数有默认值。 Matrix<typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime> Scalar是表示元素的类型,取值可以是 float ,int, double 等; RowsAtCompileTime为矩阵的行,在程序编译的时候就已经知道的; ColsAtCompileTime为矩阵的列,在程序编译的时候就已经知道的。 Eigen 提供了一些常用的 定义好的类型。比如,Matrix4f表示一个类型为float的4*4矩阵,在Eigen中定义如下: typedef Matrix<float, 4, 4> Matrix4f; Vectors向量 列向量是默认向量。 Eigen中定义的包含3个float元素的列向量如下: typedef Matrix<float, 3, 1> Vector3f; 行向量定义如下: typedef Matrix<int, 1, 2> RowVector2i; Dynamic

solving a singular matrix

假如想象 提交于 2019-12-10 11:29:05
问题 I am trying to write a little unwrapper for meshes. This uses a finite-element-method to solve for minimal linear stress between flattened and the raw surface. At the moment there are some vertices pinned to get a result. Without this the triangles are rotated and translated randomly... But as this pinning isn't necessary for the problem, the better solution would be to directly solve the singular matrix. Petsc does provide some methodes to solve a singular system by providing some

RcppEigen - going from inline to a .cpp function in a package and “Map”

我只是一个虾纸丫 提交于 2019-12-10 11:28:16
问题 Everything seems to work in my package, but I wanted to check if the steps to make it were correct and about memory use using "Map". (It's a simple example, somewhere in-between the inline examples and the fastLm() example.) Here is an inline function that takes the maximum over each column of a matrix: library(Rcpp); library(inline); library(RcppEigen); maxOverColCpp <- ' using Eigen::Map; using Eigen::MatrixXd; // Map the double matrix AA from R const Map<MatrixXd> A(as<Map<MatrixXd> >(AA))

Set row/column/block to 0 in Eigen sparse matrix?

亡梦爱人 提交于 2019-12-10 10:59:22
问题 I see with new Eigen 3.2, you can get row, column or even block from a sparse matrix, is there a way to set any of these to 0? Eigen::SparseMatrix<float, Eigen::RowMajor> A( 5, 5 ); A.block(1, 1, 2, 2) = 0; // won't work A.row(1) = 0; // won't work A.col(1) = 0; // won't work Thanks! 回答1: For 5x5 matrices, it is overkill to use a sparse matrix. Better use a MatrixXd , or even a Matrix<float,5,5> . In this case you can set a row to zero with A.row(1).setZero() . Sparse matrices are worth it

Reshaping tensors in C++

倾然丶 夕夏残阳落幕 提交于 2019-12-10 10:05:04
问题 The C++ interface to TensorFlow doesn't seem to have a reshape method. Does anyone have an idea how to convert e.g. [A,B,C,D] into [A*B,C,D] ? It looks like the only way to do this is to use Eigen? However, the documentation there is very slim and the code is template hell and not easy to parse. 回答1: Solution with checking whether reshaped tensor has the same number of elements of the source tensor: // Extracted image features from MobileNet_224 tensorflow::Tensor image_features(tensorflow:

世界坐标系和相机坐标系之间的转换

北慕城南 提交于 2019-12-10 03:53:02
博客转载自: https://www.cnblogs.com/-Mr-y/p/7737990.html 机器人一号和二号,分别在世界坐标系中。 一号的位姿 q 1 = [ 0.35 , 0.2 , 0.3 , 0.1 ], t 1 = [ 0.3 , 0.1 , 0.1 ] T。 二号的位姿 q 2 = [ − 0.5 , 0.4 , − 0.1 , 0.2 ], t 2 = [ − 0.1 , 0.5 , 0.3 ] T。 q的第一项是实部,且还未归一化。 q和t表达的是T cw 也就是世界坐标系到相机坐标系的变换关系。 已知一号机器人看到某个点,在他的坐标系下是 p = [ 0.5 , 0 , 0.2 ] T, 求在二号机器人坐标系下该点的位置。 #include <iostream> #include <cmath> // Eigen 部分 #include <Eigen/Core> // 稠密矩阵的代数运算(逆,特征值等) #include <Eigen/Dense> //Eigen 几何模块 #include <Eigen/Geometry> using namespace std; int main(int argc, char **argv) { Eigen::Quaterniond q1(0.35, 0.2, 0.3, 0.1); Eigen:

Rcpp equivalent for rowsum [closed]

时光怂恿深爱的人放手 提交于 2019-12-09 23:13:51
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am looking for a fast alternative for the R function rowsum in C++ / Rcpp / Eigen or Armadillo. The purpose is to get the sum of elements in a vector a according to a grouping vector b . For example: > a [1] 2