Registered Member
|
Can someone point if I am doing anything wrong here, or is it just that * and division operations are currently not defined row & column wise?
#include <iostream> #include <Eigen/Core> int main() { Eigen::ArrayXXf a(2,4); a << 1, 2, 3, 4, 6, 7, 8, 9; Eigen::ArrayXf max = a.colwise().maxCoeff(); a.rowwise()-=max;//Compiles & Works a.rowwise()/=max;//Compilation error return 0; } |
Moderator
|
You can do this as a standard matrix product (the .matrix() are to move to the linear algebra world):
a.matrix() = max.matrix().asDiagonal().inverse() * a.matrix() The main reason that operator / and * are not yet in row/colwise is because we have to make them available only in the array world. Note that diagonal matrix product and inversion are optimized. |
Registered Member
|
Hi, I tried this solution. It seems to be 7x slower than writing a for loop per row with llvm-gcc 4.2 on mac. My array has four columns of float. So every row is perfectly aligned.
|
Moderator
|
make sure you bench with optimization enabled -O2 -DNDEBUG
|
Registered Member
|
Is there a reason why this wouldn't work in place?
The output is
|
Moderator
|
if you compile with -DNDEBUG, you should get your answer: m3 *= d is equivalent to m3 = m3 * d, however here m3 is 2x3 and d 2x2....
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell