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

Rewrite a constructor

Tags: None
(comma "," separated)
Zmatt
Registered Member
Posts
27
Karma
0
OS

Rewrite a constructor

Mon Jul 12, 2010 12:31 pm
Hi,

I'm trying to write a new constructor for my application. I need that the users can write a code like :
Code: Select all
MatrixXd A(n)

and A will be a matrix Nx1, but the constructor doesn't like this expression and returns me a YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX error.

So I decided to add a new constructor in EIGEN_MATRIX_PLUGIN or EIGEN_MATRIXBASE_PLUGIN with no result. So I try to modify Matrix.h : I remove the constructor EIGEN_STRONG_INLINE explicit Matrix(int dim) and modify the other EIGEN_STRONG_INLINE Matrix(int x, int y) by adding and default value for y:
EIGEN_STRONG_INLINE Matrix(int x, int y = 1), but it still doesn't work. I think it comes from ColsAtCompileTime but I don't know where that variable is updated.

If you have any response or a better idea, I'm open :)

Thanks
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Rewrite a constructor

Mon Jul 12, 2010 2:04 pm
If you want your own matrix class with custom constructors, the easiest way would be to define a new class inheriting Matrix. Since constructors aren't inherited, you could do whatever you want to.

http://eigen.tuxfamily.org/dox-devel/To ... FromMatrix


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Rewrite a constructor

Mon Jul 12, 2010 2:57 pm
I'm puzzled, if you write:

MatrixXd A(n)

then you know that A is a vector, so why not using a vector which will bring higher performance as a bonus ?
Zmatt
Registered Member
Posts
27
Karma
0
OS

Re: Rewrite a constructor

Mon Jul 12, 2010 3:04 pm
Thank you, It can be a solution, but I think that will first add new problems ^^

But I've some questions : if I use a class, are the template preserve ? I mean if my new class is "matrix", and if i write matrix u = v + w; the asm code will be u[i] = v[i] + w[i] ?
What are the functions i need to add ? (in the doc you said "a few members") for instance to avoid "impossible to convert 'const Eigen::CwiseNullaryOp<NullaryOp,MatrixType>' in 'matrix'" :)

@ggael : I know that it's strange, but it's because i'm updating a previous library and thousands of lines of code already exist, and i can't rewrite all. For the future code, it will be naturally better to use Eigen syntax or at least vector instead of always matrix.

EDIT : The error is corrected, I forget some constructors and operators = (for Scalar), (it's quit easy in fact !), but i've still my question about the template :)
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Rewrite a constructor

Mon Jul 12, 2010 3:23 pm
Yes, expression templates are still working. Just check it for yourself (look at the generated assembly!)


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Rewrite a constructor

Mon Jul 12, 2010 3:32 pm
OK, I understand, inheriting Matrix is also what I did when starting to use Eigen and keep some minimal level of compatibility ;)
Zmatt
Registered Member
Posts
27
Karma
0
OS

Re: Rewrite a constructor  Topic is solved

Mon Jul 12, 2010 3:46 pm
@bjacob & ggael : Thank you for your answers :) I will check the assembly code but only when i'll go back on linux ^^ (i'm on windows for this project and it seems to be complicated to produce an asm file... (where is gcc -S ? ^^))


Bookmarks



Who is online

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