Registered Member
|
Hi !
I have (again ^^) a new question about Eigen. I precise the situation : I'm wrapping Eigen to preserve the compatibility with an older library and it works well, all my functionnalities are there and the result is fast. But there is still a problem and this problem deals with the Block. How can I write functions that work when I call them with : f(A.col(1), B.row(2)) Usually I write my functions in a new file using my matrix class (that inherits from MatrixXd) like matrix f(matrix A, matrix B) { ... } Nevertheless A.row(1) is a Block (a matrix::Block indeed) so my function doesn't match. One solution could be to defined new functions but it will be very long... I try to redefined row and col in my matrix class but I don't find someting that works. Has someone an idea ? Thanks |
Registered Member
|
EDIT : Well I was a bit wrong a finaly after some tests it works for functions
But i had to create special function for make this legal : A.col(1) <= 0.5 But i've still a problem : how can i create a function that returns a block, to create for instance a function sub that makes the same work than .block ? Thanks for any help EDIIT BIS : Why can I do :
But not
Eigen is still full of mysteries ! |
Registered Member
|
I really hope that you're rather passing A and B by reference! http://eigen.tuxfamily.org/dox-devel/To ... Value.html
Classical question but indeed Google doesn't find easily our past answers... definitely need to write a good docs page about that. Here goes: all expression types T inherit MatrixBase<T> so you can just do:
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
I guess just because Eigen already defines a templated method col() and your own col() method would shadow it...? C++ definitely allows overloaded template method declarations but I'm not sure if it allows to have one templated and one non-templated overload.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Ok, but it compiles in fact !
But when I use A.col(1,2) for instance I get a horrible
|
Registered Member
|
I found a solution to my problem
The functions have to be in the matrix class ! (and no "typename" is needed) I have a "last but not least question" ^^ : How can i simply add a new operator+ and - for the Scalar type (double in fact) to do A + 1 that does the same work than A.cwise() + 1 ? I added some functions
But no result :S (Nevertheless the addition 1 + A works with the function :
Thanks for any help and for the patience of bjacob and ggael (I ask lots of questions ) NB : tell me if I need the create a new subject |
Registered Member
|
This really shouldn't go in the matrix class, as that means that you can't call that on an expression...
For your operator +/-, since this is a coefficient-wise unary operator, you could implement these methods as returning a CwiseUnaryOp. Don't return a plain matrix as that will be inefficient (creates a temporary).
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thanks that works now (but it returns still a plain matrix, I need to return a CwiseOp as you said)
New question related to the function with blocks ^^ : If have a function
How can I call it to do :
For the moment it's impossible because Eigen can't convert the parameter
A solution can be to rewrite col, and col will return a matrix where the datas are just pointing on the matrix A (for A.col(1)) but I don't know how to do that :S |
Registered Member
|
see my first answer above, your function needs to take a matrixbase...
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Yes yes, I know
But I want to preserve the prototypes of my functions : f(matrix A&) is it possible ? |
Registered Member
|
No, it's not possible! Block expressions have a different type than matrices. The only thing they have in common is that they each inherit some specialization of MatrixBase<T> ... but for different types T, whence the need to make that a template parameter.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Arf
I tried to do something with m_data, I code a method that return a part of the matrix but naturally I have memory problems I will probably stop that idea ^^ and use the right method (but I have lots of lines to rewrite ) Thanks for your help ! (and if a specialist of m_data know how to do a "col" method that returns a MatrixXd without a segfault I'm still interrested ^^) |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]