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

Scalar divided by matrix or array operator undefined?

Tags: None
(comma "," separated)
lowsfer
Registered Member
Posts
5
Karma
0
Hi, I'm learning Eigen by porting some of my STL code to Eigen. Eigen is really great! It really ease my life and give a significant speed boost.

However I see one operator seems to be undefined, which is Scalar/Matrix (coefficient-wise). I also tried with Scalar/Matrix.array(). It still says operator undefined. I see we have coefficient-wise Scalar*Matrix, Matrix*Scalar and Matrix/Scalar, but can't find Scalar/Matrix. Is there a existing operator or function to do this in Eigen?

Currently I'm using Scalar*Matrix.array().inverse(). Is there any over head for this? Will the expression template be parsed to
Code: Select all
for (index=each coefficient index)
{
    answer(index)=Scalar/Matrix(index); //1 operation
}

or
Code: Select all
for (index=each coefficient index)
{
    answer(index)=Scalar*(1/Matrix(index)); //2 operations
}

Sorry if I'm ignorant about expression template. But I think even if inverse() will do the job without overhead, a "Scalar/Matrix" operator will be more convenient.

Thank the Eigen people for the really nice library! I'm escaping from Matlab because I found myself beginning to get used to index number starting from 1, :o which will lock me into Matlab and Fortran. I'm trying to avoid them with C++ and python. Eigen really make this process easier than I thought about C++.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
works for me. Make sure you are using the 3.1 version.

Code: Select all
#include <Eigen/Eigen>
using namespace Eigen;
int main()
{
  MatrixXf a, b=MatrixXf::Random(3,3);
  float s=2;
  a = s/b.array();
}
lowsfer
Registered Member
Posts
5
Karma
0
Opps. I'm using 3.0.6 from gentoo portage. Time to upgrade ;) Thank you!


Bookmarks



Who is online

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