I did profile my code using Valgrind (using the "release with debug information" build) and found out that a significant amount of time (~25%) is spent on one line where I calculate the element-wise cubic root of a big matrix. Now, I would like to accelerate this step if possible.
Currently, I'm simply using .pow( 1.0 / 3.0). I wonder if there is a way to improve this, maybe by using std::cbrt()? But how do I pass this function to Eigen in order to do an element-wise cubic root?
#include "iostream"
#include "eigen-3.3.7/Eigen/Dense"
using namespace Eigen;
int main() {
// generate some random numbers
VectorXd v = VectorXd::Random(10).array().abs() ;
std::cout << v << std::endl << std::endl ;
// calculate the cubic root
VectorXd s = v.array().pow( 1.0 / 3.0 );
std::cout << s << std::endl;
}