Created
February 14, 2016 21:55
-
-
Save zdk123/9c623b6bdf3a57018ae2 to your computer and use it in GitHub Desktop.
Test AMD ordering function from the Eigen library
This file contains 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 <Eigen/Core> | |
#include <Eigen/Dense> | |
#include <Eigen/Sparse> | |
#include <Eigen/OrderingMethods> | |
using Eigen::MatrixXd; | |
using Eigen::SparseMatrix; | |
using Eigen::Dynamic; | |
MatrixXd permuteMatAMD(const Eigen::SparseMatrix< double > A) { | |
Eigen::AMDOrdering<int> ordering; | |
Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> perm; | |
ordering(A, perm); | |
return Eigen::MatrixXd(perm); | |
} | |
int main() { | |
int n = 15; | |
SparseMatrix< double > m(n,n); | |
int j; | |
for (int i=0; i < (n-1); ++i) { | |
j = i+(rand()%((n-1)-i))+1; | |
// std::cout << " i=" << i << "j=" << j <<std::endl; | |
m.insert(i,j) = 1; | |
m.insert(j,i) = 1; | |
} | |
std::cout << MatrixXd(m) <<std::endl; | |
std::cout << "\n"; | |
m.makeCompressed(); | |
MatrixXd permed = permuteMatAMD(m); | |
std::cout << permed <<std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment