简体   繁体   English

本征:对不同类型的向量进行运算

[英]Eigen: Operating on Vectors of Different Types

I have many expressions that look like 我有很多表情

auto result = vec3f.cwiseProduct( vec3ui );

where vec3f is from type Eigen::Matrix< float, 3, 1 > and vec3ui is from Eigen::Matrix< unsigned int, 3, 1 > . 其中vec3f来自Eigen::Matrix< float, 3, 1 >vec3ui来自Eigen::Matrix< unsigned int, 3, 1 > These doesn't seem to be allowed, at least the compiler complains about it. 这些似乎是不允许的,至少编译器对此有所抱怨。

Hence I need to write the above like 因此我需要像上面这样写

Eigen::Matrix< float, 3, 1 > result( vec3f.x() * vec3ui.x(), /*...*/ );

which leads to very long, less-readable code. 这会导致代码很长,可读性较差。

Is it possible to vectorize the above expression using Eigen 3? 是否可以使用特征3对上述表达式进行矢量化处理?

You need to cast the second matrix to the form of the first, like this: 您需要将第二个矩阵转换为第一个矩阵的形式,如下所示:

Eigen::Matrix< float, 3, 1 > mf;
Eigen::Matrix< unsigned int, 3, 1 > mi;
mf.dot(mi.cast<float>());

Also, Eigen gives ready to use types for vectors, like Eigen::Vector3f for floats and Eigen::Vector3i for ints. 同样,Eigen可以随时使用矢量类型,例如Eigen::Vector3f表示浮点数, Eigen::Vector3i表示整数。 (but none for unsigned int ) (但对于unsigned int没有)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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