ppsv.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 /* Modified to include xPPTRI by Kian Ming A. Chai (14 May 2008) */
00014 
00015 #ifndef BOOST_NUMERIC_BINDINGS_LAPACK_PPSV_HPP
00016 #define BOOST_NUMERIC_BINDINGS_LAPACK_PPSV_HPP
00017 
00018 #include <boost/numeric/bindings/traits/type_traits.hpp>
00019 #include <boost/numeric/bindings/traits/traits.hpp>
00020 #include <boost/numeric/bindings/lapack/lapack.h>
00021 
00022 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK 
00023 #  include <boost/numeric/bindings/traits/detail/symm_herm_traits.hpp>
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
00037     // with A symmetric or Hermitian positive definite matrix
00038     // stored in packed format 
00039     //
00041 
00042     /*
00043      * ppsv() computes the solution to a system of linear equations 
00044      * A * X = B, where A is an N-by-N symmetric or Hermitian positive 
00045      * definite matrix stored in packed format and X and B are N-by-NRHS 
00046      * matrices.
00047      *
00048      * The Cholesky decomposition is used to factor A as
00049      *   A = U^T * U or A = U^H * U,  if UPLO = 'U', 
00050      *   A = L * L^T or A = L * L^H,  if UPLO = 'L',
00051      * where U is an upper triangular matrix and L is a lower triangular
00052      * matrix. The factored form of A is then used to solve the system of
00053      * equations A * X = B.
00054      * 
00055      * Only upper or lower triangle of the symmetric matrix A is stored,  
00056      * packed columnwise in a linear array AP. 
00057      */
00058 
00059     namespace detail {
00060 
00061       inline 
00062       void ppsv (char const uplo, int const n, int const nrhs,
00063                  float* ap, float* b, int const ldb, int* info) 
00064       {
00065         LAPACK_SPPSV (&uplo, &n, &nrhs, ap, b, &ldb, info);
00066       }
00067 
00068       inline 
00069       void ppsv (char const uplo, int const n, int const nrhs,
00070                  double* ap, double* b, int const ldb, int* info) 
00071       {
00072         LAPACK_DPPSV (&uplo, &n, &nrhs, ap, b, &ldb, info);
00073       }
00074 
00075       inline 
00076       void ppsv (char const uplo, int const n, int const nrhs,
00077                  traits::complex_f* ap, traits::complex_f* b, int const ldb, 
00078                  int* info) 
00079       {
00080         LAPACK_CPPSV (&uplo, &n, &nrhs, 
00081                       traits::complex_ptr (ap), 
00082                       traits::complex_ptr (b), &ldb, info);
00083       }
00084 
00085       inline 
00086       void ppsv (char const uplo, int const n, int const nrhs,
00087                  traits::complex_d* ap, traits::complex_d* b, int const ldb, 
00088                  int* info) 
00089       {
00090         LAPACK_ZPPSV (&uplo, &n, &nrhs, 
00091                       traits::complex_ptr (ap), 
00092                       traits::complex_ptr (b), &ldb, info);
00093       }
00094 
00095     }
00096 
00097     template <typename SymmMatrA, typename MatrB>
00098     inline
00099     int ppsv (SymmMatrA& a, MatrB& b) {
00100 
00101 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00102       BOOST_STATIC_ASSERT((boost::is_same<
00103         typename traits::matrix_traits<SymmMatrA>::matrix_structure,
00104         typename traits::detail::symm_herm_pack_t<
00105           typename traits::matrix_traits<SymmMatrA>::value_type
00106         >::type
00107       >::value));
00108       BOOST_STATIC_ASSERT((boost::is_same<
00109         typename traits::matrix_traits<MatrB>::matrix_structure, 
00110         traits::general_t
00111       >::value));
00112 #endif
00113 
00114       int const n = traits::matrix_size1 (a);
00115       assert (n == traits::matrix_size2 (a));
00116       assert (n == traits::matrix_size1 (b));
00117 
00118       char uplo = traits::matrix_uplo_tag (a);
00119       int info; 
00120       detail::ppsv (uplo, n, traits::matrix_size2 (b),
00121                     traits::matrix_storage (a), 
00122                     traits::matrix_storage (b), 
00123                     traits::leading_dimension (b), 
00124                     &info);
00125       return info; 
00126     }
00127 
00128 
00129     /*
00130      * pptrf() computes the Cholesky factorization of a symmetric
00131      * or Hermitian positive definite matrix A in packed storage. 
00132      * The factorization has the form
00133      *   A = U^T * U or A = U^H * U,  if UPLO = 'U', 
00134      *   A = L * L^T or A = L * L^H,  if UPLO = 'L',
00135      * where U is an upper triangular matrix and L is lower triangular.
00136      */
00137 
00138     namespace detail {
00139 
00140       inline 
00141       void pptrf (char const uplo, int const n, float* ap, int* info) {
00142         LAPACK_SPPTRF (&uplo, &n, ap, info);
00143       }
00144 
00145       inline 
00146       void pptrf (char const uplo, int const n, double* ap, int* info) {
00147         LAPACK_DPPTRF (&uplo, &n, ap, info);
00148       }
00149 
00150       inline 
00151       void pptrf (char const uplo, int const n, 
00152                   traits::complex_f* ap, int* info) 
00153       {
00154         LAPACK_CPPTRF (&uplo, &n, traits::complex_ptr (ap), info);
00155       }
00156 
00157       inline 
00158       void pptrf (char const uplo, int const n, 
00159                   traits::complex_d* ap, int* info) 
00160       {
00161         LAPACK_ZPPTRF (&uplo, &n, traits::complex_ptr (ap), info);
00162       }
00163 
00164     }
00165 
00166     template <typename SymmMatrA>
00167     inline
00168     int pptrf (SymmMatrA& a) {
00169 
00170 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00171       BOOST_STATIC_ASSERT((boost::is_same<
00172         typename traits::matrix_traits<SymmMatrA>::matrix_structure,
00173         typename traits::detail::symm_herm_pack_t<
00174           typename traits::matrix_traits<SymmMatrA>::value_type
00175         >::type
00176       >::value));
00177 #endif
00178 
00179       int const n = traits::matrix_size1 (a);
00180       assert (n == traits::matrix_size2 (a));
00181       char uplo = traits::matrix_uplo_tag (a);
00182       int info; 
00183       detail::pptrf (uplo, n, traits::matrix_storage (a), &info);
00184       return info; 
00185     }
00186 
00187 
00188     /*
00189      * pptrs() solves a system of linear equations A*X = B with 
00190      * a symmetric or Hermitian positive definite matrix A in packed 
00191      * storage using the Cholesky factorization computed by pptrf().
00192      */
00193 
00194     namespace detail {
00195 
00196       inline 
00197       void pptrs (char const uplo, int const n, int const nrhs,
00198                   float const* ap, float* b, int const ldb, int* info) 
00199       {
00200         LAPACK_SPPTRS (&uplo, &n, &nrhs, ap, b, &ldb, info);
00201       }
00202 
00203       inline 
00204       void pptrs (char const uplo, int const n, int const nrhs,
00205                   double const* ap, double* b, int const ldb, int* info) 
00206       {
00207         LAPACK_DPPTRS (&uplo, &n, &nrhs, ap, b, &ldb, info);
00208       }
00209 
00210       inline 
00211       void pptrs (char const uplo, int const n, int const nrhs,
00212                   traits::complex_f const* ap, 
00213                   traits::complex_f* b, int const ldb, int* info) 
00214       {
00215         LAPACK_CPPTRS (&uplo, &n, &nrhs, 
00216                        traits::complex_ptr (ap), 
00217                        traits::complex_ptr (b), &ldb, info);
00218       }
00219 
00220       inline 
00221       void pptrs (char const uplo, int const n, int const nrhs,
00222                   traits::complex_d const* ap, 
00223                   traits::complex_d* b, int const ldb, int* info) 
00224       {
00225         LAPACK_ZPPTRS (&uplo, &n, &nrhs, 
00226                        traits::complex_ptr (ap), 
00227                        traits::complex_ptr (b), &ldb, info);
00228       }
00229 
00230     }
00231 
00232     template <typename SymmMatrA, typename MatrB>
00233     inline
00234     int pptrs (SymmMatrA const& a, MatrB& b) {
00235 
00236 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00237       BOOST_STATIC_ASSERT((boost::is_same<
00238         typename traits::matrix_traits<SymmMatrA>::matrix_structure,
00239         typename traits::detail::symm_herm_pack_t<
00240           typename traits::matrix_traits<SymmMatrA>::value_type
00241         >::type
00242       >::value));
00243       BOOST_STATIC_ASSERT((boost::is_same<
00244         typename traits::matrix_traits<MatrB>::matrix_structure, 
00245         traits::general_t
00246       >::value));
00247 #endif
00248 
00249       int const n = traits::matrix_size1 (a);
00250       assert (n == traits::matrix_size2 (a));
00251       assert (n == traits::matrix_size1 (b));
00252       
00253       char uplo = traits::matrix_uplo_tag (a);
00254       int info; 
00255       detail::pptrs (uplo, n, traits::matrix_size2 (b),
00256 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00257                      traits::matrix_storage (a), 
00258 #else
00259                      traits::matrix_storage_const (a), 
00260 #endif 
00261                      traits::matrix_storage (b), 
00262                      traits::leading_dimension (b), 
00263                      &info);
00264       return info; 
00265     }
00266 
00267 
00268     /*
00269     *  pptri() computes the inverse of a real symmetric positive definite
00270     *  matrix A using the Cholesky factorization A = U**T*U or A = L*L**T
00271     *  computed by pptrf().
00272     */
00273     
00274     namespace detail {
00275 
00276       inline 
00277       void pptri (char const uplo, int const n, float* ap, int* info) {
00278         LAPACK_SPPTRI (&uplo, &n, ap, info);
00279       }
00280 
00281       inline 
00282       void pptri (char const uplo, int const n, double* ap, int* info) {
00283         LAPACK_DPPTRI (&uplo, &n, ap, info);
00284       }
00285 
00286       inline 
00287       void pptri (char const uplo, int const n, 
00288                   traits::complex_f* ap, int* info) 
00289       {
00290         LAPACK_CPPTRI (&uplo, &n, traits::complex_ptr (ap), info);
00291       }
00292 
00293       inline 
00294       void pptri (char const uplo, int const n, 
00295                   traits::complex_d* ap, int* info) 
00296       {
00297         LAPACK_ZPPTRI(&uplo, &n, traits::complex_ptr (ap), info);
00298       }
00299 
00300     }
00301 
00302     template <typename SymmMatrA>
00303     inline
00304     int pptri (SymmMatrA& a) { //ISSUE: More correctly, triangular matrix
00305 
00306 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00307       BOOST_STATIC_ASSERT((boost::is_same<
00308         typename traits::matrix_traits<SymmMatrA>::matrix_structure,
00309         typename traits::detail::symm_herm_pack_t<
00310           typename traits::matrix_traits<SymmMatrA>::value_type
00311         >::type
00312       >::value));
00313 #endif
00314 
00315       int const n = traits::matrix_size1 (a);
00316       assert (n == traits::matrix_size2 (a));
00317       char uplo = traits::matrix_uplo_tag (a);
00318       int info; 
00319       detail::pptri (uplo, n, traits::matrix_storage (a), &info);
00320       return info; 
00321     }
00322 
00323 
00324   }
00325 
00326 }}}
00327 
00328 #endif 

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