Reputation: 6196
It doesn't seem like Eigen supports bitwise operations.
I would like bitwise SIMD functionality for "shift left" and "and".
Is there a quick and dirty way to implement this functionality? Can i call an intrinsic function and input it with something like Eigen vector.data()?
Upvotes: 3
Views: 1483
Reputation: 2787
You could use the unaryExpr
and binaryExpr
methods. Here's an example of summing array values
where the corresponding mask
matches the desired bitmask
:
// 'mask' is an Eigen matrix of type an integer type (MaskT).
// 'values' is an Eigen matrix of floating-point type.
// 'bitmask' is of an integer type (MaskT).
auto const select = mask.unaryExpr(
[bitmask](MaskT value) { return value & bitmask; }
).template cast<bool>();
double const sum = select.select(values.template cast<double>(), 0.0).sum();
Upvotes: 0
Reputation: 357
I think Eigen don't support this because that there isn't a good way to do this for float, double and complex numbers.
You can always override those C++ bitwise operators by yourself, taking two MatrixBase as parameters.
For bitwise assignment operators, you need to add a function inside MatrixBase class. Eigen made this possible, see here how to.
Upvotes: 2