Registered Member
|
Greetings again, Sorry for flooding with multiple topics, but I am trying to convert some code over to C++ using Eigen and I am having trouble finding ways to do certain things.
I wish to create an array that is 10 raised to the power of all the values in another array. I.E. So where you can do pow(a, 10) to receive an array with all the values in "a" raised to 10, you could do pow(10, a) to receive an array that is 10 raised to the power of all the values in a. However the second version of pow is not overloaded and I am unsure how to replicate this functionality without explicitly looping with my own function. I noticed a cwisePow in the "See Also" of some of the matrix function documentation which I could potentially use on a matrix/array of 10's, but it is not a hyperlink and it doesn't exist when I try to call it. I also thought of maybe using binaryExpr and passing the pow as a function pointer, but I can't get that to work. I like how easy to use Eigen is compared to the other common matrix libraries for C++ but some functionality eludes me even after digging through the API so help is greatly appreciated! Thank you! |
Moderator
|
you have to create a binary pow function (see the file src/Core/Functors.h for examples) and then call A.binaryExpr(B, your_pow_functor());
|
Registered Member
|
Ah that worked. Thanks. I thought maybe there was a way to do it without writing my own function but there wasn't. I got it working with this functor:
Called with the line:
And this successfully raised my array of 10's to the values in dataArray. If there is a better way I am all ears Thanks for the help. |
Moderator
|
maybe using ptr_fun:
|
Registered Member
|
Using "ptr_fun" causes all kinds of errors because "mypow" is actually a struct with a constructor (I did this because I followed what is done in Functors.h and other examples in the documentation). If "mypow" was just a regular function ptr_fun would work (I have done this with _isnan to check if all elements are NaN and array.unaryExpr(ptr_fun(_isnan)) works).
|
Moderator
|
sure, my suggestion was just to avoid the need to define the functor...
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]