spsv.hpp

Go to the documentation of this file.
00001 /*
00002  * 
00003  * Copyright (c) Kresimir Fresl & Toon Knapen 2003
00004  *
00005  * Distributed under the Boost Software License, Version 1.0.
00006  * (See accompanying file LICENSE_1_0.txt or copy at
00007  * http://www.boost.org/LICENSE_1_0.txt)
00008  *
00009  * KF acknowledges the support of the Faculty of Civil Engineering, 
00010  * University of Zagreb, Croatia.
00011  *
00012  */
00013 
00014 #ifndef BOOST_NUMERIC_BINDINGS_LAPACK_SPSV_HPP
00015 #define BOOST_NUMERIC_BINDINGS_LAPACK_SPSV_HPP
00016 
00017 #include <boost/numeric/bindings/traits/type_traits.hpp>
00018 #include <boost/numeric/bindings/traits/traits.hpp>
00019 #include <boost/numeric/bindings/lapack/lapack.h>
00020 #include <boost/numeric/bindings/traits/detail/array.hpp>
00021 #include <boost/numeric/bindings/traits/detail/utils.hpp>
00022 
00023 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK 
00024 #  include <boost/static_assert.hpp>
00025 #  include <boost/type_traits/is_same.hpp>
00026 #endif 
00027 
00028 #include <cassert>
00029 
00030 namespace boost { namespace numeric { namespace bindings { 
00031 
00032   namespace lapack {
00033 
00035     //
00036     // system of linear equations A * X = B with A symmetric matrix
00037     // stored in packed format 
00038     //
00040 
00041     /*
00042      * spsv() computes the solution to a system of linear equations 
00043      * A * X = B, where A is an N-by-N symmetric matrix stored in packed 
00044      * format and X and B are N-by-NRHS matrices.
00045      *
00046      * The diagonal pivoting method is used to factor A as
00047      *   A = U * D * U^T,  if UPLO = 'U', 
00048      *   A = L * D * L^T,  if UPLO = 'L',
00049      * where  U (or L) is a product of permutation and unit upper 
00050      * (lower) triangular matrices, and D is symmetric and block 
00051      * diagonal with 1-by-1 and 2-by-2 diagonal blocks.  
00052      * The factored form of A is then used to solve the system 
00053      * of equations A * X = B.
00054      */
00055 
00056     namespace detail {
00057 
00058       inline 
00059       void spsv (char const uplo, int const n, int const nrhs,
00060                  float* ap, int* ipiv, 
00061                  float* b, int const ldb, int* info) 
00062       {
00063         LAPACK_SSPSV (&uplo, &n, &nrhs, ap, ipiv, b, &ldb, info);
00064       }
00065 
00066       inline 
00067       void spsv (char const uplo, int const n, int const nrhs,
00068                  double* ap, int* ipiv, 
00069                  double* b, int const ldb, int* info) 
00070       {
00071         LAPACK_DSPSV (&uplo, &n, &nrhs, ap, ipiv, b, &ldb, info);
00072       }
00073 
00074       inline 
00075       void spsv (char const uplo, int const n, int const nrhs,
00076                  traits::complex_f* ap, int* ipiv,  
00077                  traits::complex_f* b, int const ldb, int* info) 
00078       {
00079         LAPACK_CSPSV (&uplo, &n, &nrhs, 
00080                       traits::complex_ptr (ap), ipiv, 
00081                       traits::complex_ptr (b), &ldb, info);
00082       }
00083 
00084       inline 
00085       void spsv (char const uplo, int const n, int const nrhs,
00086                  traits::complex_d* ap, int* ipiv, 
00087                  traits::complex_d* b, int const ldb, int* info) 
00088       {
00089         LAPACK_ZSPSV (&uplo, &n, &nrhs, 
00090                       traits::complex_ptr (ap), ipiv, 
00091                       traits::complex_ptr (b), &ldb, info);
00092       }
00093 
00094       template <typename SymmA, typename MatrB, typename IVec>
00095       inline
00096       int spsv (SymmA& a, IVec& i, MatrB& b) {
00097 
00098 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00099         BOOST_STATIC_ASSERT((boost::is_same<
00100           typename traits::matrix_traits<SymmA>::matrix_structure, 
00101           traits::symmetric_packed_t
00102         >::value));
00103         BOOST_STATIC_ASSERT((boost::is_same<
00104           typename traits::matrix_traits<MatrB>::matrix_structure, 
00105           traits::general_t
00106         >::value));
00107 #endif
00108 
00109         int const n = traits::matrix_size1 (a);
00110         assert (n == traits::matrix_size2 (a)); 
00111         assert (n == traits::matrix_size1 (b)); 
00112 
00113         char uplo = traits::matrix_uplo_tag (a);
00114         int info; 
00115         spsv (uplo, n, traits::matrix_size2 (b), 
00116               traits::matrix_storage (a), 
00117               traits::vector_storage (i),  
00118               traits::matrix_storage (b),
00119               traits::leading_dimension (b),
00120               &info);
00121         return info; 
00122       }
00123 
00124     }
00125 
00126     template <typename SymmA, typename MatrB, typename IVec>
00127     inline
00128     int spsv (SymmA& a, IVec& i, MatrB& b) {
00129       assert (traits::matrix_size1 (a) == traits::vector_size (i)); 
00130       return detail::spsv (a, i, b); 
00131     }
00132 
00133     template <typename SymmA, typename MatrB>
00134     inline
00135     int spsv (SymmA& a, MatrB& b) {
00136       // with 'internal' pivot vector
00137 
00138       int info = -101; 
00139       traits::detail::array<int> i (traits::matrix_size1 (a)); 
00140 
00141       if (i.valid()) 
00142         info = detail::spsv (a, i, b); 
00143       return info; 
00144     }
00145 
00146 
00147     /*
00148      * sptrf() computes the factorization of a symmetric matrix A 
00149      * in packed storage using the  Bunch-Kaufman diagonal pivoting 
00150      * method. The form of the factorization is
00151      *    A = U * D * U^T  or  A = L * D * L^T
00152      * where U (or L) is a product of permutation and unit upper (lower)  
00153      * triangular matrices, and D is symmetric and block diagonal with 
00154      * 1-by-1 and 2-by-2 diagonal blocks.
00155      */
00156 
00157     namespace detail {
00158 
00159       inline 
00160       void sptrf (char const uplo, int const n, 
00161                   float* ap, int* ipiv, int* info) 
00162       {
00163         LAPACK_SSPTRF (&uplo, &n, ap, ipiv, info);
00164       }
00165 
00166       inline 
00167       void sptrf (char const uplo, int const n, 
00168                   double* ap, int* ipiv, int* info) 
00169       {
00170         LAPACK_DSPTRF (&uplo, &n, ap, ipiv, info);
00171       }
00172 
00173       inline 
00174       void sptrf (char const uplo, int const n, 
00175                   traits::complex_f* ap, int* ipiv, int* info) 
00176       {
00177         LAPACK_CSPTRF (&uplo, &n, traits::complex_ptr (ap), ipiv, info);
00178       }
00179 
00180       inline 
00181       void sptrf (char const uplo, int const n, 
00182                   traits::complex_d* ap, int* ipiv, int* info) 
00183       {
00184         LAPACK_ZSPTRF (&uplo, &n, traits::complex_ptr (ap), ipiv, info);
00185       }
00186 
00187     }
00188 
00189     template <typename SymmA, typename IVec>
00190     inline
00191     int sptrf (SymmA& a, IVec& i) {
00192 
00193 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00194       BOOST_STATIC_ASSERT((boost::is_same<
00195         typename traits::matrix_traits<SymmA>::matrix_structure, 
00196         traits::symmetric_packed_t
00197       >::value));
00198 #endif
00199 
00200       int const n = traits::matrix_size1 (a);
00201       assert (n == traits::matrix_size2 (a)); 
00202       assert (n == traits::vector_size (i)); 
00203 
00204       char uplo = traits::matrix_uplo_tag (a);
00205       int info; 
00206       detail::sptrf (uplo, n, traits::matrix_storage (a), 
00207                      traits::vector_storage (i), &info);
00208       return info; 
00209     }
00210 
00211 
00212     /*
00213      * sptrs() solves a system of linear equations A*X = B with 
00214      * a symmetric matrix A in packed storage using the factorization 
00215      *    A = U * D * U^T   or  A = L * D * L^T
00216      * computed by sptrf().
00217      */
00218 
00219     namespace detail {
00220 
00221       inline 
00222       void sptrs (char const uplo, int const n, int const nrhs,
00223                   float const* a, int const* ipiv, 
00224                   float* b, int const ldb, int* info) 
00225       {
00226         LAPACK_SSPTRS (&uplo, &n, &nrhs, a, ipiv, b, &ldb, info);
00227       }
00228 
00229       inline 
00230       void sptrs (char const uplo, int const n, int const nrhs,
00231                   double const* a, int const* ipiv, 
00232                   double* b, int const ldb, int* info) 
00233       {
00234         LAPACK_DSPTRS (&uplo, &n, &nrhs, a, ipiv, b, &ldb, info);
00235       }
00236 
00237       inline 
00238       void sptrs (char const uplo, int const n, int const nrhs,
00239                   traits::complex_f const* a, int const* ipiv,  
00240                   traits::complex_f* b, int const ldb, int* info) 
00241       {
00242         LAPACK_CSPTRS (&uplo, &n, &nrhs, 
00243                       traits::complex_ptr (a), ipiv, 
00244                       traits::complex_ptr (b), &ldb, info);
00245       }
00246 
00247       inline 
00248       void sptrs (char const uplo, int const n, int const nrhs,
00249                   traits::complex_d const* a, int const* ipiv, 
00250                   traits::complex_d* b, int const ldb, int* info) 
00251       {
00252         LAPACK_ZSPTRS (&uplo, &n, &nrhs, 
00253                        traits::complex_ptr (a), ipiv, 
00254                        traits::complex_ptr (b), &ldb, info);
00255       }
00256 
00257     }
00258 
00259     template <typename SymmA, typename MatrB, typename IVec>
00260     inline
00261     int sptrs (SymmA const& a, IVec const& i, MatrB& b) {
00262 
00263 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00264       BOOST_STATIC_ASSERT((boost::is_same<
00265         typename traits::matrix_traits<SymmA>::matrix_structure, 
00266         traits::symmetric_packed_t
00267       >::value));
00268       BOOST_STATIC_ASSERT((boost::is_same<
00269         typename traits::matrix_traits<MatrB>::matrix_structure, 
00270         traits::general_t
00271       >::value));
00272 #endif
00273 
00274       int const n = traits::matrix_size1 (a);
00275       assert (n == traits::matrix_size2 (a)); 
00276       assert (n == traits::matrix_size1 (b)); 
00277       assert (n == traits::vector_size (i)); 
00278 
00279       char uplo = traits::matrix_uplo_tag (a);
00280       int info; 
00281       detail::sptrs (uplo, n, traits::matrix_size2 (b), 
00282 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00283                      traits::matrix_storage (a), 
00284                      traits::vector_storage (i),  
00285 #else
00286                      traits::matrix_storage_const (a), 
00287                      traits::vector_storage_const (i),  
00288 #endif 
00289                      traits::matrix_storage (b),
00290                      traits::leading_dimension (b), 
00291                      &info);
00292       return info; 
00293     }
00294 
00295 
00296     // TO DO: sptri 
00297 
00298   }
00299 
00300 }}}
00301 
00302 #endif 

Generated on Wed Nov 23 19:00:41 2011 for FreeCAD by  doxygen 1.6.1