Created
November 30, 2017 18:35
-
-
Save olooney/69f7b4d599b2b6a9f4924f47f704dc9d to your computer and use it in GitHub Desktop.
xtensor eigenpair example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <tuple> | |
#include <algorithm> | |
#include "xtensor/xarray.hpp" | |
#include "xtensor/xio.hpp" | |
#include "xtensor/xmath.hpp" | |
#include "xtensor/xrandom.hpp" | |
#include "xtensor/xbuilder.hpp" | |
#include "xtensor/xbroadcast.hpp" | |
#include "xtensor-blas/xlinalg.hpp" | |
int main() { | |
xt::xarray<double> correlation_matrix {{1,0,0}, {0, 1, 0.5}, {0, 0.5, 1}}; | |
std::cout << correlation_matrix << std::endl; | |
auto eigenpair = xt::linalg::eig(correlation_matrix); | |
auto eigenvalues = std::get<0>(eigenpair); | |
auto eigenvectors = std::get<1>(eigenpair); | |
std::cout << "Eigen values: " << std::endl << xt::real(eigenvalues) << std::endl; | |
std::cout << "Eigen vectors: " << std::endl << xt::real(eigenvectors) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment