blas2.hpp

Go to the documentation of this file.
00001 //
00002 //  Copyright Toon Knapen and Kresimir Fresl 2003
00003 //
00004 // Distributed under the Boost Software License, Version 1.0.
00005 // (See accompanying file LICENSE_1_0.txt or copy at
00006 // http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 
00009 #ifndef BOOST_BINDINGS_BLAS_BLAS2_HPP
00010 #define BOOST_BINDINGS_BLAS_BLAS2_HPP
00011 
00012 #include <boost/numeric/bindings/blas/blas2_overloads.hpp>
00013 #include <boost/numeric/bindings/traits/traits.hpp>
00014 #include <boost/numeric/bindings/traits/transpose.hpp>
00015 #include <boost/static_assert.hpp>
00016 #include <boost/type_traits.hpp>
00017 #include <cassert> 
00018 
00019 namespace boost { namespace numeric { namespace bindings { namespace blas {
00020 
00021   // y <- alpha * op (A) * x + beta * y
00022   // op (A) == A || A^T || A^H
00023   // ! CAUTION this function assumes that all matrices involved are column-major matrices
00024   template < typename matrix_type, typename vector_type_x, typename vector_type_y, typename value_type >
00025   inline
00026   void gemv(const char TRANS, 
00027             const value_type& alpha, 
00028             const matrix_type &a, 
00029             const vector_type_x &x, 
00030             const value_type& beta,
00031             vector_type_y &y
00032             )
00033   {
00034     // precondition: matrix_type must be dense or dense_proxy
00035     /* not all compilers can handle the traits
00036     BOOST_STATIC_ASSERT( ( boost::is_same< typename mtraits::matrix_structure,
00037                                            boost::numeric::bindings::traits::general_t
00038                            >::value ) ) ;
00039     */
00040 
00041     const int m = traits::matrix_size1( a ) ;
00042     const int n = traits::matrix_size2( a ) ;
00043     assert ( traits::vector_size( x ) >= (TRANS == traits::NO_TRANSPOSE ? n : m) ) ; 
00044     assert ( traits::vector_size( y ) >= (TRANS == traits::NO_TRANSPOSE ? m : n) ) ; 
00045     const int lda = traits::leading_dimension( a ) ; 
00046     const int stride_x = traits::vector_stride( x ) ;
00047     const int stride_y = traits::vector_stride( y ) ;
00048 
00049     const value_type *a_ptr = traits::matrix_storage( a ) ;
00050     const value_type *x_ptr = traits::vector_storage( x ) ;
00051     value_type *y_ptr = traits::vector_storage( y ) ;
00052 
00053     detail::gemv( TRANS, m, n, alpha, a_ptr, lda, x_ptr, stride_x, beta, y_ptr, stride_y );
00054   }
00055 
00056   // A <- alpha * x * trans(y) ( outer product ), alpha, x and y are real-valued 
00057   // ! CAUTION this function assumes that all matrices involved are column-major matrices
00058   template < typename vector_type_x, typename vector_type_y, typename value_type, typename matrix_type >
00059   inline
00060   void ger( const value_type& alpha, 
00061             const vector_type_x &x, 
00062             const vector_type_y &y,
00063             matrix_type &a 
00064             )
00065   {
00066     // precondition: matrix_type must be dense or dense_proxy
00067     /* not all compilers can handle the traits
00068     BOOST_STATIC_ASSERT( ( boost::is_same< typename mtraits::matrix_structure,
00069                                            boost::numeric::bindings::traits::general_t
00070                            >::value ) ) ;
00071     */
00072 
00073     const int m = traits::matrix_size1( a ) ;
00074     const int n = traits::matrix_size2( a ) ;
00075     assert ( traits::vector_size( x ) <= m ) ; 
00076     assert ( traits::vector_size( y ) <= n ) ; 
00077     const int lda = traits::leading_dimension( a ) ; 
00078     const int stride_x = traits::vector_stride( x ) ;
00079     const int stride_y = traits::vector_stride( y ) ;
00080 
00081     const value_type *x_ptr = traits::vector_storage( x ) ;
00082     const value_type *y_ptr = traits::vector_storage( y ) ;
00083     value_type *a_ptr = traits::matrix_storage( a ) ;
00084     
00085     detail::ger( m, n, alpha, x_ptr, stride_x, y_ptr, stride_y, a_ptr, lda );
00086   }
00087 /*
00088   // A <- alpha * x * trans(y) ( outer product ), alpha, x and y are complex-valued 
00089   template < typename vector_type_x, typename vector_type_y, typename value_type, typename matrix_type >
00090   inline
00091   void geru( const value_type& alpha, 
00092              const vector_type_x &x, 
00093              const vector_type_y &y,
00094              matrix_type &a 
00095              )
00096   {
00097     // precondition: matrix_type must be dense or dense_proxy
00098 //    not all compilers can handle the traits
00099 //    BOOST_STATIC_ASSERT( ( boost::is_same< typename mtraits::matrix_structure,
00100 //                                           boost::numeric::bindings::traits::general_t
00101 //                           >::value ) ) ;
00102     
00103 
00104 //    BOOST_STATIC_ASSERT( ( boost::is_same< x.value_type(), FEMTown::Complex() >::value ) ) ;
00105     const int m = traits::matrix_size1( a ) ;
00106     const int n = traits::matrix_size2( a ) ;
00107     assert ( traits::vector_size( x ) <= m ) ; 
00108     assert ( traits::vector_size( y ) <= n ) ; 
00109     const int lda = traits::leading_dimension( a ) ; 
00110     const int stride_x = traits::vector_stride( x ) ;
00111     const int stride_y = traits::vector_stride( y ) ;
00112 
00113     const value_type *x_ptr = traits::vector_storage( x ) ;
00114     const value_type *y_ptr = traits::vector_storage( y ) ;
00115     value_type *a_ptr = traits::matrix_storage( a ) ;
00116     
00117     detail::geru( m, n, alpha, x_ptr, stride_x, y_ptr, stride_y, a_ptr, lda );
00118   }
00119 */
00120   /*
00121   // y <- alpha * A * x + beta * y 
00122   template < typename matrix_type, typename vector_type_x, typename vector_type_y >
00123   inline 
00124   void gemv(const typename traits::matrix_traits<matrix_type>::value_type &alpha, 
00125             const matrix_type &a, 
00126             const vector_type_x &x, 
00127             const typename traits::vector_traits<vector_type_y>::value_type &beta,
00128             vector_type_y &y
00129             )
00130   {
00131     gemv( traits::NO_TRANSPOSE, alpha, a, x, beta, y ); 
00132   }
00133 
00134 
00135   // y <- A * x
00136   template < typename matrix_type, typename vector_type_x, typename vector_type_y >
00137   inline 
00138   void gemv(const matrix_type &a, const vector_type_x &x, vector_type_y &y)
00139   {
00140     typedef typename traits::matrix_traits<matrix_type>::value_type val_t; 
00141     gemv( traits::NO_TRANSPOSE, (val_t) 1, a, x, (val_t) 0, y );
00142   }
00143   */
00144 
00145 }}}}
00146 
00147 #endif // BOOST_BINDINGS_BLAS_BLAS2_HPP

Generated on Wed Nov 23 18:59:58 2011 for FreeCAD by  doxygen 1.6.1