UMFPACK和BOOST的uBLAS库稀疏矩阵 [英] UMFPACK and BOOST's uBLAS Sparse Matrix

查看:470
本文介绍了UMFPACK和BOOST的uBLAS库稀疏矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Boost的uBLAS库在数值code和有重求解到位:

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_Inversion

在code工作出色,但是,它是痛苦的缓慢。经过一番研究,我发现 UMF​​PACK ,这是一个稀疏矩阵解算器(其中其他事情)。我的code产生大量稀疏矩阵,我需要非常频繁反转(更正确地解决,逆矩阵的值是不相关的),所以UMFPACk和BOOST的Sparse_Matrix类似乎是一个幸福的婚姻。

The code works excellently, however, it is painfully slow. After some research, I found UMFPACK, which is a sparse matrix solver (among other things). My code generates large sparse matrices which I need to invert very frequently (more correctly solve, the value of the inverse matrix is irrelevant), so UMFPACk and BOOST's Sparse_Matrix class seems to be a happy marriage.

UMF​​PACK要求由三个向量指定的稀疏矩阵:条目数,排索引和条目。 (见例如)。

UMFPACK asks for the sparse matrix specified by three vectors: an entry count, row indexes, and the entries. (See example).

我的问题归结到,我可以最有效地获得这三个矢量从Boost的稀疏矩阵类?

My question boils down to, can I get these three vectors efficiently from BOOST's Sparse Matrix class?

推荐答案

有是此绑定:

<一个href=\"http://mathema.tician.de/software/boost-numeric-bindings\">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 <iostream>
    #include <boost/numeric/bindings/traits/ublas_vector.hpp>
    #include <boost/numeric/bindings/traits/ublas_sparse.hpp>
    #include <boost/numeric/bindings/umfpack/umfpack.hpp>
    #include <boost/numeric/ublas/io.hpp>

    namespace ublas = boost::numeric::ublas;
    namespace umf = boost::numeric::bindings::umfpack;

    int main() {

      ublas::compressed_matrix<double, ublas::column_major, 0,
       ublas::unbounded_array<int>, ublas::unbounded_array<double> > A (5,5,12); 
      ublas::vector<double> 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<double> Symbolic;
      umf::numeric_type<double> 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)
    } 

注意

虽然这个工作,我正在考虑搬到NETLIB

Though this work, I am considering moving to NETLIB

这篇关于UMFPACK和BOOST的uBLAS库稀疏矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆