I am using the Eigen library in C++: I am currently calculating the covariance matrix myself as follows:
Eigen::MatrixXd covariance_matrix = Eigen::MatrixXd:
Using Eigen expressions will leverage SIMD and cache optimized algorithms, so yes it should definitely be faster, and in any case, much simpler to write:
MatrixXd centered = mat.rowwise() - mat.colwise().mean();
MatrixXd cov = (centered.adjoint() * centered) / double(mat.rows() - 1);
Moreover, assuming "data" is a typedef for a double[21], then you can use the Map<> feature to view your std::vector as an Eigen object:
Map > mat(&(all_data[0][0], all_data.size(), 21);