Registered Member
|
Hello!
I could not think of an apt title but I will go right into it. I am working on an embedded project and I need linear algebra library so I chose Eigen. It has been very good so far, I tested my code on Visual Studio with optimizations on and it reports that the code compiled in 0.008 seconds, but my console window doesn't open up that fast. It takes about 30 seconds for it to open up (I build in release mode by the way). I have 3 things I want to get some assistance on. Firstly, I have opted for fixed sized matrices of type float because the microcontroller I am to upload my code to doesn't work well with dynamic sized matrices of type double. I do know that by doing
I am declaring Matrix A as a fixed size. My question, at what size does using a fixed sized matrix become a performance issue? In my work the biggest matrix size I have is a
The section of code below will be used to ask my next two questions:
So this is a function that takes in the arguments by reference (I did it this way to speed things up, to avoid making copies each time the function was called). Now the thing is, I know the sizes of matrices A and B, hence I can declare them as fixed matrix types. So how would you think i could declare the type of the matrix P (I am assuming that you cannot mix dynamic and fixed matrix types)? Lastly, in this line in the for loop,
I am multiplying C with A raised to a power. Is there another way to compute this that is faster? There was a method I tried:
it is faster but outputs the wrong answer. I made some tweaks yesterday by changing the dynamically sized matrices ( I could change) to fixed sized ones and it improved my performance but I am afraid that my STM32F4 microcontroller still isn't as fast. My last option might be to hardcode some of the variables to be
I tremendously appreciate any input I can get from you. Please ask me for any clarifications. Thank you! |
Registered Member
|
PS
The console window reporting speed of 0.008 s gets to me especially since it takes 30 seconds for the window to open. Is this the right way to clock the computation:
Thanks again |
Moderator
|
Why do you use pointers ? References, and even const references would be more appropriate:
MatrixXf P_output(const MatrixTypeA &A, const MatrixTypeC &C, int ny) and this will make your code more readable. You can mix fixed and dynamic sized objects, you can even fix only one dimension, but unless ny is known at compile-time, there is no way to avoid a dynamic size for P. Regarding A.pow(i), better compute it incrementally during the for loop, and then make use of Eigen's API to avoid stupid for loops and temporaries:
for your embedded platform you might want to enforce a simpler product implementation using lazyProduct:
|
Registered Member
|
Hello,
I took your advice and decided to have a test run where matrices C and A are dynamically fixed:
But doing this results in a program crash and this is the only section of code running. Likewise, if I define the matrices A and C as fixed, it also crashes
I am expecting P to output this:
Please let me know what I am doing wrong. Thank you Ggael |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]