geqrf.hpp

Go to the documentation of this file.
00001 /*
00002  * 
00003  * Copyright (c) Toon Knapen, Karl Meerbergen & 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_GEQRF_HPP
00015 #define BOOST_NUMERIC_BINDINGS_LAPACK_GEQRF_HPP
00016 
00017 #include <complex>
00018 #include <boost/numeric/bindings/traits/traits.hpp>
00019 #include <boost/numeric/bindings/lapack/lapack.h>
00020 #include <boost/numeric/bindings/lapack/workspace.hpp>
00021 #include <boost/numeric/bindings/traits/detail/array.hpp>
00022 // #include <boost/numeric/bindings/traits/std_vector.hpp>
00023 
00024 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK 
00025 #  include <boost/static_assert.hpp>
00026 #  include <boost/type_traits.hpp>
00027 #endif 
00028 #include <cassert>
00029 
00030 
00031 namespace boost { namespace numeric { namespace bindings { 
00032 
00033   namespace lapack {
00034 
00036     //
00037     // QR factorization of a general m x n matrix  A = Q * R
00038     // 
00040 
00041     /* 
00042      * geqrf() computes the QR factorization of a rectangular matrix
00043      * A = Q *  R,  where Q is a M x min(M,N) matrix with orthogonal
00044      * and normalized column (i.e. herm(Q) $ Q = I) and R is a
00045      * min(M,N) x N upper triangular matrix.
00046      *
00047      * On return of geqrf, the elements on and above the diagonal of
00048      * A contain the min(M,N) x N upper trapezoidal matrix R (R is
00049      * upper triangular if  m  >=  n);  the elements below the diagonal,
00050      * with the array TAU, represent the orthogonal matrix Q as a product
00051      * of min(M,N) elementary reflectors.
00052      */ 
00053 
00054     namespace detail {
00055 
00056       inline 
00057       void geqrf (int const m, int const n,
00058                  float* a, int const lda,
00059                  float* tau, float* work, int const lwork, int& info) 
00060       {
00061         LAPACK_SGEQRF (&m, &n, a, &lda, tau, work, &lwork, &info);
00062       }
00063 
00064       inline 
00065       void geqrf (int const m, int const n,
00066                  double* a, int const lda,
00067                  double* tau, double* work, int const lwork, int& info) 
00068       {
00069         LAPACK_DGEQRF (&m, &n, a, &lda, tau, work, &lwork, &info);
00070       }
00071 
00072       inline 
00073       void geqrf (int const m, int const n,
00074                   traits::complex_f* a, int const lda,
00075                   traits::complex_f* tau, traits::complex_f* work,
00076                   int const lwork, int& info) 
00077       {
00078         LAPACK_CGEQRF (&m, &n,
00079                       traits::complex_ptr (a), &lda,
00080                       traits::complex_ptr (tau),
00081                       traits::complex_ptr (work), &lwork, &info );
00082       }
00083       
00084 
00085       inline 
00086       void geqrf (int const m, int const n,
00087                   traits::complex_d* a, int const lda,
00088                   traits::complex_d* tau, traits::complex_d* work,
00089                   int const lwork, int& info) 
00090       {
00091         LAPACK_ZGEQRF (&m, &n,
00092                       traits::complex_ptr (a), &lda,
00093                       traits::complex_ptr (tau),
00094                       traits::complex_ptr (work), &lwork, &info );
00095       }
00096       
00097     } 
00098 
00099     template <typename A, typename Tau, typename Work>
00100     inline
00101     int geqrf (A& a, Tau& tau, Work& work) {
00102 
00103 #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK 
00104       BOOST_STATIC_ASSERT((boost::is_same<
00105         typename traits::matrix_traits<A>::matrix_structure, 
00106         traits::general_t
00107       >::value)); 
00108 #endif 
00109 
00110       int const m = traits::matrix_size1 (a);
00111       int const n = traits::matrix_size2 (a);
00112       assert (std::min(m,n) <= traits::vector_size (tau)); 
00113       assert (n <= traits::vector_size (work)); 
00114 
00115       int info; 
00116       detail::geqrf (m, n,
00117                      traits::matrix_storage (a), 
00118                      traits::leading_dimension (a),
00119                      traits::vector_storage (tau),  
00120                      traits::vector_storage (work),
00121                      traits::vector_size (work),
00122                      info);
00123       return info; 
00124     }
00125 
00126     // Computation of the QR factorization.
00127     // Workspace is allocated dynamically so that the optimization of
00128     // blas 3 calls is optimal.
00129     template <typename A, typename Tau>
00130     inline
00131     int geqrf (A& a, Tau& tau, optimal_workspace ) {
00132        typedef typename A::value_type value_type ;
00133        const int n = traits::matrix_size2 (a);
00134        traits::detail::array<value_type> work(std::max(1, n*32));
00135        return geqrf( a, tau, work );
00136     }
00137 
00138     // Computation of the QR factorization.
00139     // Workspace is allocated dynamically to its minimum size.
00140     // Blas 3 calls are not optimal.
00141     template <typename A, typename Tau>
00142     inline
00143     int geqrf (A& a, Tau& tau, minimal_workspace ) {
00144        typedef typename A::value_type value_type ;
00145        const int n = traits::matrix_size2 (a);
00146        traits::detail::array<value_type> work(std::max(1, n));
00147        return geqrf( a, tau, work );
00148     }
00149 
00150     // Computation of the QR factorization.
00151     // Workspace is taken from the array in workspace.
00152     // The calling sequence is
00153     // geqrf( a, tau, workspace( work ) ) where work is an array with the same value_type
00154     // as a.
00155     template <typename A, typename Tau, typename Work>
00156     inline
00157     int geqrf (A& a, Tau& tau, detail::workspace1<Work> workspace ) {
00158        typedef typename A::value_type value_type ;
00159        const int n = traits::matrix_size2 (a);
00160        traits::detail::array<value_type> work(std::max(1, n));
00161        return geqrf( a, tau, workspace.w_ );
00162     }
00163 
00164     // Function without workarray as argument
00165     template <typename A, typename Tau>
00166     inline
00167     int geqrf (A& a, Tau& tau) {
00168        return geqrf( a, tau, optimal_workspace() );
00169     }
00170 
00171   }
00172 
00173 }}}
00174 
00175 #endif 

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