日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eigen库

發布時間:2023/12/9 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eigen库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MatrixXd表示任意size的矩陣,元素類型為double; VectorXd表示任意size的向量,元素類型為double.

//創建3*1的向量v,并賦值為1,2,3 VectorXd v(3); v << 1, 2, 3;

使用固定尺寸的Matrix,Vector相比于可變尺寸的Matrix,Vector,例如Matrix3d?m代替MatrixXd?m(3,3)有以下優點:

運行速度更快,編譯期間可實現更嚴格的錯誤檢查。

Eigen中,所有的矩陣,向量都是Matrix模板類的對象,向量只是矩陣的特例,行數或者列數為1.

//便捷定義 typedef Matrix<float, 4, 4> Matrix4f; typedef Matrix<float, 3, 1> Vector3f; typedef Matrix<int, 1, 2> RowVector2i; ? typedef Matrix<double, Dynamic, Dynamic> MatrixXd;? //編譯期未知尺寸

?Eigen中通過()獲取其元素,起始索引為0。The operator[] is also overloaded for index-based access in vectors, but keep in mind that C++ doesn't allow operator[] to take more than one argument.

?transpose()計算矩陣的轉置,?transpose()不支持就地轉置,使用transposeInPlace()來實現就地轉置。

?Array

We adopt the convention that typedefs of the form ArrayNt stand for 1-dimensional arrays, where N and t are the size and the scalar type.For 2-dimensional arrays, we use typedefs of the form ArrayNNt.?

matrix和array之間可以相互進行轉換,通過調用matrix的.array()函數將matrix轉換為array表達式;通過調用array的.matrix()函數將array轉換為matrix表達式。

Eigen中禁止一個表達式中混合使用matrix和array,但允許賦值運算符這樣操作。

Eigen中為matrix提供了cwiseProduct()函數以實現逐元素相乘。

?Block Operation

matrix.row(i) 獲取矩陣matrix的第i行,matrix.col(j)獲取矩陣matrix的第j列。相比于使用block()性能更好。

Eigen?also provides special methods for blocks that are flushed against one of the corners or sides of a matrix or array. For instance,?.topLeftCorner()?can be used to refer to a block in the top-left corner of a matrix.

?

squaredNorm() 計算2范數的平方,norm()計算2范數,lpNorm<p>()計算p范數,p設置為Infinity可計算無窮范數。

The following reductions operate on boolean values:

  • all()?returns?true?if all of the coefficients in a given?Matrix?or?Array?evaluate to?true?.
  • any()?returns?true?if at least one of the coefficients in a given?Matrix?or?Array?evaluates to?true?.
  • count()?returns the number of coefficients in a given?Matrix?or?Array?that evaluate to?true.

?Visitors

Visitors are useful when one wants to obtain the location of a coefficient inside a?Matrix?or?Array. The simplest examples are?maxCoeff(&x,&y)?and?minCoeff(&x,&y), which can be used to find the location of the greatest or smallest coefficient in a?Matrix?or?Array.

The arguments passed to a visitor are pointers to the variables where the row and column position are to be stored. These variables should be of type?Index?

?matrix.data()函數返回一個指向矩陣內存地址的指針。Eigen中矩陣默認以column-major存儲元素值。

?

轉載于:https://www.cnblogs.com/larry-xia/p/10666834.html

總結

以上是生活随笔為你收集整理的Eigen库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。