简体   繁体   中英

Eigen::Matrix | Why does eigen expect an int and not size_t?

According to the Eigen documentation , the second and third template arguments, which correspond to number of rows and cols, are expected to be int .

I am wondering why these arguments are not size_t ? The only reason to have int there is, when eigen would allow to have negative number of rows or cols?

The only reason why this could make sense is because of Eigen::Dynamic . Can anyone confirm that this is the reason to allow negative values for rows/cols?

Eigen::Dynamic is not a reason at all as it could be made equal for instance to numeric_limits<size_t>::max() , or same size_t(-1) .

I believe that is rather because the target audience of Eigen is more comfortable using int then anything else. Then if you are not comfortable with this choice, you can use the EIGEN_DEFAULT_DENSE_INDEX_TYPE preprocessor directive to set to whatever you feel is appropriate and face the consequences... :) No, seriously, I would at least run the complete Eigen test set before actually using that.

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