Skip to content

Instantly share code, notes, and snippets.

@goldbattle
Created January 17, 2023 18:45
Show Gist options
  • Save goldbattle/61126167792ac996e1610a173760086e to your computer and use it in GitHub Desktop.
Save goldbattle/61126167792ac996e1610a173760086e to your computer and use it in GitHub Desktop.
ver slow compared to Eigen3 - https://github.com/jewettaij/jacobi_pd
int n = (int)Amm.rows();
double **M = new double *[n];
double *evals = new double[n]; // Store the eigenvalues here.
double **evecs = new double *[n]; // Store the eigenvectors here.
for (int r = 0; r < n; r++) {
M[r] = new double[n];
evecs[r] = new double[n];
for (int c = 0; c < n; c++) {
M[r][c] = Amm(r, c);
}
}
jacobi_pd::Jacobi<double, double *, double **> eigen_calc(n);
int status = eigen_calc.Diagonalize(M, evals, evecs,
jacobi_pd::Jacobi<double, double *, double **>::eSortCriteria::SORT_INCREASING_EVALS, true, 20);
std::cout << "JACOBI_PD: status " << status << std::endl;
std::cout << "JACOBI_PD: eigenvalues: ";
for (int i = 0; i < n; i++)
std::cout << evals[i] << " ";
std::cout << std::endl << std::endl;
// for (int i = 0; i < n; i++) {
// cout << "JACOBI_PD: eigenvector" << i + 1 << ": ";
// for (int j = 0; j < n; j++)
// cout << evecs[i][j] << " ";
// cout << endl;
// }
for (int r = 0; r < n; r++)
delete[] M[r];
delete[] M;
delete[] evals;
for (int r = 0; r < n; r++)
delete[] evecs[r];
delete[] evecs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment