This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Scalar multiplication/division for Integer matrices

Tags: None
(comma "," separated)
hijokpayne
Registered Member
Posts
25
Karma
0
Code: Select all
Vector2i vec(100, 100);
vec *= 0.5;
std::cout << "vec=\n" << vec << std::endl; // This gives [0, 0] instead of [50, 50]


To get the desired behavior, I need to do:
Code: Select all
Vector2i vec(100, 100);
vec = (vec.cast<double>() * 0.5).cast<int>();
std::cout << "vec=\n" << vec << std::endl; // This gives [50, 50]


Is there a simpler way of doing the above?

The Scalar operations defined in Eigen DenseBase all casts the provided scalar to the Scalar type of the DenseBase. Why not make these methods templated on arbitrary scalar types?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Because we do not allow mixing types implicitly: this kills vectorization and in most cases it means the user is doing something work like multiplying integers by 0.5 instead of dividing by 2.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]