简体   繁体   中英

Why Eigen use Column-Major by default instead of Row-Major?

Although Eigen is C++ library and C/C++ use row-major storage structure, why Eigen prefers to use column-major storage order? From Why does MATLAB use column-major order? post, I understand that MATLAB use it because of historical (due to FORTRAN) reasons. But Eigen is built on C++ at the beginning as far as I know.

In Eigen Library website it says:

The default in Eigen is column-major. Naturally, most of the development and testing of the Eigen library is thus done with column-major matrices. This means that, even though we aim to support column-major and row-major storage orders transparently, the Eigen library may well work best with column-major matrices. (retrieved from https://eigen.tuxfamily.org/dox/group__TopicStorageOrders.html )

Maybe due to using C++ and OpenCV very frequently, my brain tends to think in row-major form. Are there any performance (cache locality, load/store speed etc.) reasons of making development and testing of Eigen library with column-major matrices?

Actually, you are right, originally, for row-major stored data, row-major traversal has better cache locality, thus a higher cache hit rate.

Eigen stores data in col-major order by default. It seems a little bit counterintuitive,however, Eigen also traverses data in col-major order by default.

Also, you can find the official document here Eigen storage order : Algorithms that traverse a matrix row by row will go faster when the matrix is stored in row-major order because of better data locality. Similarly, column-by-column traversal is faster for column-major matrices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM