Registered Member
|
I have a function that requires a 3-element array and a 2-element array as inputs. Since its possible that each one would be an array block, my function looks like the following:
When I call the function with an array created using ArrayXd c(3,1); ArrayXd r(2,1); It works as expected; However, when I try to call it using a fixed-size array, it fails. Array<double,3,1> c; Array<double,2,1> r; Shouldn't ArrayBase be allowing for either one of these? On a more general note, I would expect it to be better to tend towards fixed-size arrays if possible, is this not the case? Here's an example code, uncommenting the second call to solve_quadratic results in a compile-time error. ( gcc version 4.2.1 (Apple Inc. build 5666) )
|
Registered Member
|
ArrayBase does allow for fixed-size arrays. The problem is that the size is encoded in the template parameter. Array3f inherits from ArrayBase<Array3f> and Array2f inherits from ArrayBase<Array2f> (this is called CRTP = Curiously Recurring Template Pattern). In your function, both the array arguments are of type ArrayBase<Derived>, so they have to be of the same type. So you should change the prototype to
And hopefully it will work then. I don't understand your second question; if this does not answer it then please ask again. |
Registered Member
|
Thanks, that was indeed the problem.
The second part of the question was more about the efficiency of dynamic vs fixed arrays. I would suspect that fixed size arrays are fast, but if you're not reallocating the dynamically sized array, I'm not sure. It's something that I can play around with as my project matures. |
Moderator
|
fixed sizes also allow for explicit unrolling and so much faster performance for very small matrices (e.g., 2, 3, 4).
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]