hpsv.hpp

Go to the documentation of this file.
00001 /*
00002  * 
00003  * Copyright (c) Toon Knapen & Kresimir Fresl 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_HPSV_HPP
00015 #define BOOST_NUMERIC_BINDINGS_LAPACK_HPSV_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
00037     // with A Hermitian indefinite matrix stored in packed format 
00038     //
00040 
00041     /*
00042      * hpsv() computes the solution to a system of linear equations 
00043      * A * X = B, where A is an N-by-N Hermitian matrix in packed
00044      * storage 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^H,  if UPLO = 'U', 
00048      *   A = L * D * L^H,  if UPLO = 'L',
00049      * where  U (or L) is a product of permutation and unit upper 
00050      * (lower) triangular matrices, and D is Hermitian and block 
00051      * diagonal with 1-by-1 and 2-by-2 diagonal blocks. The factored 
00052      * form of A is then used to solve the system of equations A * X = B.
00053      */
00054 
00055     namespace detail {
00056 
00057       inline 
00058       void hpsv (char const uplo, int const n, int const nrhs,
00059                  traits::complex_f* ap, int* ipiv,  
00060                  traits::complex_f* b, int const ldb, int* info) 
00061       {
00062         LAPACK_CHPSV (&uplo, &n, &nrhs, 
00063                       traits::complex_ptr (ap), ipiv, 
00064                       traits::complex_ptr (b), &ldb, info);
00065       }
00066 
00067       inline 
00068       void hpsv (char const uplo, int const n, int const nrhs,
00069                  traits::complex_d* ap, int* ipiv, 
00070                  traits::complex_d* b, int const ldb, int* info) 
00071       {
00072         LAPACK_ZHPSV (&uplo, &n, &nrhs, 
00073                       traits::complex_ptr (ap), ipiv, 
00074                       traits::complex_ptr (b), &ldb, info);
00075       }
00076 
00077       template <typename HermA, typename MatrB, typename IVec>
00078       inline
00079       int hpsv (HermA& a, IVec& i, MatrB& b) {
00080 
00081 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00082         BOOST_STATIC_ASSERT((boost::is_same<
00083           typename traits::matrix_traits<HermA>::matrix_structure, 
00084           traits::hermitian_packed_t
00085         >::value));
00086         BOOST_STATIC_ASSERT((boost::is_same<
00087           typename traits::matrix_traits<MatrB>::matrix_structure, 
00088           traits::general_t
00089         >::value));
00090 #endif
00091 
00092         int const n = traits::matrix_size1 (a);
00093         assert (n == traits::matrix_size2 (a)); 
00094         assert (n == traits::matrix_size1 (b)); 
00095 
00096         char uplo = traits::matrix_uplo_tag (a);
00097         int info; 
00098         hpsv (uplo, n, traits::matrix_size2 (b), 
00099               traits::matrix_storage (a), 
00100               traits::vector_storage (i),  
00101               traits::matrix_storage (b),
00102               traits::leading_dimension (b),
00103               &info);
00104         return info; 
00105       }
00106 
00107     }
00108 
00109     template <typename HermA, typename MatrB, typename IVec> 
00110     inline
00111     int hpsv (HermA& a, IVec& i, MatrB& b) {
00112       assert (traits::matrix_size1 (a) == traits::vector_size (i)); 
00113       return detail::hpsv (a, i, b); 
00114     }
00115 
00116     template <typename HermA, typename MatrB>
00117     inline
00118     int hpsv (HermA& a, MatrB& b) {
00119       // with 'internal' pivot vector
00120 
00121       int info = -101; 
00122       traits::detail::array<int> i (traits::matrix_size1 (a)); 
00123 
00124       if (i.valid()) 
00125         info = detail::hpsv (a, i, b); 
00126       return info; 
00127     }
00128 
00129 
00130     /*
00131      * hptrf() computes the factorization of a Hermitian matrix A 
00132      * in packed storage using the  Bunch-Kaufman diagonal pivoting 
00133      * method. The form of the factorization is
00134      *    A = U * D * U^H  or  A = L * D * L^H
00135      * where U (or L) is a product of permutation and unit upper (lower)  
00136      * triangular matrices, and D is Hermitian and block diagonal with 
00137      * 1-by-1 and 2-by-2 diagonal blocks.
00138      */
00139 
00140     namespace detail {
00141 
00142       inline 
00143       void hptrf (char const uplo, int const n, 
00144                   traits::complex_f* ap, int* ipiv, int* info) 
00145       {
00146         LAPACK_CHPTRF (&uplo, &n, traits::complex_ptr (ap), ipiv, info);
00147       }
00148 
00149       inline 
00150       void hptrf (char const uplo, int const n, 
00151                   traits::complex_d* ap, int* ipiv, int* info) 
00152       {
00153         LAPACK_ZHPTRF (&uplo, &n, traits::complex_ptr (ap), ipiv, info);
00154       }
00155 
00156       template <typename HermA, typename IVec, typename Work>
00157       inline
00158       int hptrf (char const ul, HermA& a, IVec& i, Work& w, int const lw) {
00159 
00160       }
00161 
00162     }
00163 
00164     template <typename HermA, typename IVec> 
00165     inline
00166     int hptrf (HermA& a, IVec& i) {
00167 
00168 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00169       BOOST_STATIC_ASSERT((boost::is_same<
00170         typename traits::matrix_traits<HermA>::matrix_structure, 
00171         traits::hermitian_packed_t
00172       >::value));
00173 #endif
00174 
00175       int const n = traits::matrix_size1 (a);
00176       assert (n == traits::matrix_size2 (a)); 
00177       assert (n == traits::vector_size (i)); 
00178 
00179       char uplo = traits::matrix_uplo_tag (a);
00180       int info; 
00181       detail::hptrf (uplo, n, traits::matrix_storage (a), 
00182                      traits::vector_storage (i), &info);
00183       return info; 
00184     }
00185 
00186 
00187     /*
00188      * hptrs() solves a system of linear equations A*X = B with 
00189      * a Hermitian matrix A in packed storage using the factorization 
00190      *    A = U * D * U^H   or  A = L * D * L^H
00191      * computed by hptrf().
00192      */
00193 
00194     namespace detail {
00195 
00196       inline 
00197       void hptrs (char const uplo, int const n, int const nrhs,
00198                   traits::complex_f const* ap, int const* ipiv, 
00199                   traits::complex_f* b, int const ldb, int* info) 
00200       {
00201         LAPACK_CHPTRS (&uplo, &n, &nrhs, 
00202                        traits::complex_ptr (ap), ipiv, 
00203                        traits::complex_ptr (b), &ldb, info);
00204       }
00205 
00206       inline 
00207       void hptrs (char const uplo, int const n, int const nrhs,
00208                   traits::complex_d const* ap, int const* ipiv, 
00209                   traits::complex_d* b, int const ldb, int* info) 
00210       {
00211         LAPACK_ZHPTRS (&uplo, &n, &nrhs, 
00212                        traits::complex_ptr (ap), ipiv, 
00213                        traits::complex_ptr (b), &ldb, info);
00214       }
00215 
00216     }
00217 
00218     template <typename HermA, typename MatrB, typename IVec>
00219     inline
00220     int hptrs (HermA const& a, IVec const& i, MatrB& b) {
00221 
00222 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
00223       BOOST_STATIC_ASSERT((boost::is_same<
00224         typename traits::matrix_traits<HermA>::matrix_structure, 
00225         traits::hermitian_packed_t
00226       >::value));
00227       BOOST_STATIC_ASSERT((boost::is_same<
00228         typename traits::matrix_traits<MatrB>::matrix_structure, 
00229         traits::general_t
00230       >::value));
00231 #endif
00232 
00233       int const n = traits::matrix_size1 (a);
00234       assert (n == traits::matrix_size2 (a)); 
00235       assert (n == traits::matrix_size1 (b)); 
00236       assert (n == traits::vector_size (i)); 
00237 
00238       char uplo = traits::matrix_uplo_tag (a);
00239       int info; 
00240       detail::hptrs (uplo, n, traits::matrix_size2 (b), 
00241 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00242                      traits::matrix_storage (a), 
00243                      traits::vector_storage (i),  
00244 #else
00245                      traits::matrix_storage_const (a), 
00246                      traits::vector_storage_const (i),  
00247 #endif 
00248                      traits::matrix_storage (b),
00249                      traits::leading_dimension (b), 
00250                      &info);
00251         return info; 
00252     }
00253 
00254 
00255     // TO DO: hptri
00256 
00257   }
00258 
00259 }}}
00260 
00261 #endif 

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