Registered Member
|
Hello,
I'm a trying to port a home written matrix "library" to make use of eigen instead of the home written code. I would like to make this port in such a way that it does not need any change in the classes that make use of the home grown 'library". This would be the fist step in optimizing the code in terms of speed and maintainability. I completed this task for 99% but got stuck on the final 1%. The home grown library makes use of a plain array ("data") to store the numbers, and 2 integers ("nrow","ncol")for the matrix dimensions. I replaced data with from the old version with:
The problem is the following (type of) line of of code which occurs multiple times in multiple files :
where
The overloaded [] function is used as setter and getter (I have a Java background). I tried to make it work but I started to generate random code: I was able to make it as a getter but unable to write it as getter and setter. Is it possible to call a eigen matrix in this way? The last working getter function looks like this:
I hope someone can help.
Last edited by maarten on Wed May 02, 2012 7:21 pm, edited 1 time in total.
|
Moderator
|
your operator[] should returns a 'DT&', and directly:
return data(row, column); Note that Eigen support 1D indexing by default but only when it can be used with no overhead, e.g. for Matrix object. Also note that Eigen's 1D indexing is dependent on the storage order. |
Registered Member
|
Thanks! This helped a lot with float matrixes. However if I transform the type of the matrix from float to double the compiler starts to complain:
where test_matrix.cpp:60
(the value of this position is set) and the second last line of the next snippet corresponds myownmatrix1.h:75
I have looked together with a colleague at this problem and we are quite clueless . |
Moderator
|
check your data(,) function, it seems it is returning a float while DT is double.
|
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]