Boost.uBlas 1.49
Linear Algebra in C++: matrices, vectors and numeric algorithms

blas.hpp

Go to the documentation of this file.
00001 //  Copyright (c) 2000-2011 Joerg Walter, Mathias Koch, David Bellot
00002 //
00003 //  Distributed under the Boost Software License, Version 1.0. (See
00004 //  accompanying file LICENSE_1_0.txt or copy at
00005 //  http://www.boost.org/LICENSE_1_0.txt)
00006 //
00007 //  The authors gratefully acknowledge the support of
00008 //  GeNeSys mbH & Co. KG in producing this work.
00009 
00010 #ifndef _BOOST_UBLAS_BLAS_
00011 #define _BOOST_UBLAS_BLAS_
00012 
00013 #include <boost/numeric/ublas/traits.hpp>
00014 
00015 namespace boost { namespace numeric { namespace ublas {
00016     
00017 
00023     namespace blas_1 {
00024 
00032         template<class V>
00033         typename type_traits<typename V::value_type>::real_type
00034         asum (const V &v) {
00035             return norm_1 (v);
00036         }
00037 
00045         template<class V>
00046         typename type_traits<typename V::value_type>::real_type
00047         nrm2 (const V &v) {
00048             return norm_2 (v);
00049         }
00050 
00058         template<class V>
00059         typename type_traits<typename V::value_type>::real_type
00060         amax (const V &v) {
00061             return norm_inf (v);
00062         }
00063 
00073         template<class V1, class V2>
00074         typename promote_traits<typename V1::value_type, typename V2::value_type>::promote_type
00075         dot (const V1 &v1, const V2 &v2) {
00076             return inner_prod (v1, v2);
00077         }
00078 
00088         template<class V1, class V2>
00089         V1 & copy (V1 &v1, const V2 &v2) 
00090     {
00091             return v1.assign (v2);
00092         }
00093 
00102     template<class V1, class V2>
00103         void swap (V1 &v1, V2 &v2) 
00104     {
00105             v1.swap (v2);
00106         }
00107 
00117         template<class V, class T>
00118         V & scal (V &v, const T &t) 
00119     {
00120             return v *= t;
00121         }
00122 
00134         template<class V1, class T, class V2>
00135         V1 & axpy (V1 &v1, const T &t, const V2 &v2) 
00136     {
00137             return v1.plus_assign (t * v2);
00138         }
00139 
00157         template<class T1, class V1, class T2, class V2>
00158         void rot (const T1 &t1, V1 &v1, const T2 &t2, V2 &v2) 
00159     {
00160             typedef typename promote_traits<typename V1::value_type, typename V2::value_type>::promote_type promote_type;
00161             vector<promote_type> vt (t1 * v1 + t2 * v2);
00162             v2.assign (- t2 * v1 + t1 * v2);
00163             v1.assign (vt);
00164         }
00165 
00166     }
00167 
00173     namespace blas_2 {
00174 
00184         template<class V, class M>
00185         V & tmv (V &v, const M &m) 
00186     {
00187             return v = prod (m, v);
00188         }
00189 
00201         template<class V, class M, class C>
00202         V & tsv (V &v, const M &m, C) 
00203     {
00204             return v = solve (m, v, C ());
00205         }
00206 
00222         template<class V1, class T1, class T2, class M, class V2>
00223         V1 & gmv (V1 &v1, const T1 &t1, const T2 &t2, const M &m, const V2 &v2) 
00224     {
00225             return v1 = t1 * v1 + t2 * prod (m, v2);
00226         }
00227 
00241         template<class M, class T, class V1, class V2>
00242         M & gr (M &m, const T &t, const V1 &v1, const V2 &v2) 
00243     {
00244 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
00245             return m += t * outer_prod (v1, v2);
00246 #else
00247             return m = m + t * outer_prod (v1, v2);
00248 #endif
00249         }
00250 
00262         template<class M, class T, class V>
00263         M & sr (M &m, const T &t, const V &v) 
00264     {
00265 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
00266             return m += t * outer_prod (v, v);
00267 #else
00268             return m = m + t * outer_prod (v, v);
00269 #endif
00270         }
00271 
00283         template<class M, class T, class V>
00284         M & hr (M &m, const T &t, const V &v) 
00285     {
00286 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
00287             return m += t * outer_prod (v, conj (v));
00288 #else
00289             return m = m + t * outer_prod (v, conj (v));
00290 #endif
00291         }
00292 
00306         template<class M, class T, class V1, class V2>
00307         M & sr2 (M &m, const T &t, const V1 &v1, const V2 &v2) 
00308     {
00309 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
00310             return m += t * (outer_prod (v1, v2) + outer_prod (v2, v1));
00311 #else
00312             return m = m + t * (outer_prod (v1, v2) + outer_prod (v2, v1));
00313 #endif
00314         }
00315 
00329         template<class M, class T, class V1, class V2>
00330         M & hr2 (M &m, const T &t, const V1 &v1, const V2 &v2) 
00331     {
00332 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
00333             return m += t * outer_prod (v1, conj (v2)) + type_traits<T>::conj (t) * outer_prod (v2, conj (v1));
00334 #else
00335             return m = m + t * outer_prod (v1, conj (v2)) + type_traits<T>::conj (t) * outer_prod (v2, conj (v1));
00336 #endif
00337         }
00338 
00339     }
00340 
00346     namespace blas_3 {
00347 
00362         template<class M1, class T, class M2, class M3>
00363         M1 & tmm (M1 &m1, const T &t, const M2 &m2, const M3 &m3) 
00364     {
00365             return m1 = t * prod (m2, m3);
00366         }
00367 
00381         template<class M1, class T, class M2, class C>
00382         M1 & tsm (M1 &m1, const T &t, const M2 &m2, C) 
00383     {
00384             return m1 = solve (m2, t * m1, C ());
00385         }
00386 
00402         template<class M1, class T1, class T2, class M2, class M3>
00403         M1 & gmm (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) 
00404     {
00405             return m1 = t1 * m1 + t2 * prod (m2, m3);
00406         }
00407 
00422         template<class M1, class T1, class T2, class M2>
00423         M1 & srk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2) 
00424     {
00425             return m1 = t1 * m1 + t2 * prod (m2, trans (m2));
00426         }
00427 
00442         template<class M1, class T1, class T2, class M2>
00443         M1 & hrk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2) 
00444     {
00445             return m1 = t1 * m1 + t2 * prod (m2, herm (m2));
00446         }
00447 
00464         template<class M1, class T1, class T2, class M2, class M3>
00465         M1 & sr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) 
00466     {
00467             return m1 = t1 * m1 + t2 * (prod (m2, trans (m3)) + prod (m3, trans (m2)));
00468         }
00469 
00486         template<class M1, class T1, class T2, class M2, class M3>
00487         M1 & hr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) 
00488     {
00489             return m1 = 
00490               t1 * m1 
00491             + t2 * prod (m2, herm (m3)) 
00492             + type_traits<T2>::conj (t2) * prod (m3, herm (m2));
00493         }
00494 
00495     }
00496 
00497 }}}
00498 
00499 #endif