UMFPACK and BOOST's uBLAS Sparse Matrix

前端 未结 1 468
南笙
南笙 2021-01-01 04:20

I am using Boost\'s uBLAS in a numerical code and have a \'heavy\' solver in place:

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?LU_Matrix_Inversio

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 04:40

    There is a binding for this:

    http://mathema.tician.de/software/boost-numeric-bindings

    The project seems to be two years stagnant, but it does the job well. An example use:

        #include 
        #include 
        #include 
        #include 
        #include 
    
        namespace ublas = boost::numeric::ublas;
        namespace umf = boost::numeric::bindings::umfpack;
    
        int main() {
    
          ublas::compressed_matrix, ublas::unbounded_array > A (5,5,12); 
          ublas::vector B (5), X (5);
    
          A(0,0) = 2.; A(0,1) = 3; 
          A(1,0) = 3.; A(1,2) = 4.; A(1,4) = 6;
          A(2,1) = -1.; A(2,2) = -3.; A(2,3) = 2.;
          A(3,2) = 1.;
          A(4,1) = 4.; A(4,2) = 2.; A(4,4) = 1.; 
    
          B(0) = 8.; B(1) = 45.; B(2) = -3.; B(3) = 3.; B(4) = 19.; 
    
          umf::symbolic_type Symbolic;
          umf::numeric_type Numeric;
    
          umf::symbolic (A, Symbolic); 
          umf::numeric (A, Symbolic, Numeric); 
          umf::solve (A, X, B, Numeric);   
    
          std::cout << X << std::endl;  // output: [5](1,2,3,4,5)
        } 
    

    NOTE:

    Though this work, I am considering moving to NETLIB

    0 讨论(0)
提交回复
热议问题