ublas: blas.hpp Source File

- Main Page
- Related Pages
- Classes
- Files

- File List

# blas.hpp

    00001 //
    00002 //  Copyright (c) 2000-2002
    00003 //  Joerg Walter, Mathias Koch
    00004 //
    00005 //  Distributed under the Boost Software License, Version 1.0. (See
    00006 //  accompanying file LICENSE_1_0.txt or copy at
    00007 //  http://www.boost.org/LICENSE_1_0.txt)
    00008 //
    00009 //  The authors gratefully acknowledge the support of
    00010 //  GeNeSys mbH & Co. KG in producing this work.
    00011 //
    00012
    00013 #ifndef _BOOST_UBLAS_BLAS_
    00014 #define _BOOST_UBLAS_BLAS_
    00015
    00016 #include <boost/numeric/ublas/traits.hpp>
    00017
    00018 namespace boost { namespace numeric { namespace ublas {
    00019
    00020
    00026     namespace blas_1 {
    00027
    00035         template<class V>
    00036         typename type_traits<typename V::value_type>::real_type
    00037         asum (const V &v) {
    00038             return norm_1 (v);
    00039         }
    00040
    00048         template<class V>
    00049         typename type_traits<typename V::value_type>::real_type
    00050         nrm2 (const V &v) {
    00051             return norm_2 (v);
    00052         }
    00053
    00061         template<class V>
    00062         typename type_traits<typename V::value_type>::real_type
    00063         amax (const V &v) {
    00064             return norm_inf (v);
    00065         }
    00066
    00076         template<class V1, class V2>
    00077         typename promote_traits<typename V1::value_type, typename V2::value_type>::promote_type
    00078         dot (const V1 &v1, const V2 &v2) {
    00079             return inner_prod (v1, v2);
    00080         }
    00081
    00091         template<class V1, class V2>
    00092         V1 & copy (V1 &v1, const V2 &v2)
    00093         {
    00094             return v1.assign (v2);
    00095         }
    00096
    00105         template<class V1, class V2>
    00106         void swap (V1 &v1, V2 &v2)
    00107         {
    00108             v1.swap (v2);
    00109         }
    00110
    00120         template<class V, class T>
    00121         V & scal (V &v, const T &t)
    00122         {
    00123             return v *= t;
    00124         }
    00125
    00137         template<class V1, class T, class V2>
    00138         V1 & axpy (V1 &v1, const T &t, const V2 &v2)
    00139         {
    00140             return v1.plus_assign (t * v2);
    00141         }
    00142
    00160         template<class T1, class V1, class T2, class V2>
    00161         void rot (const T1 &t1, V1 &v1, const T2 &t2, V2 &v2)
    00162         {
    00163             typedef typename promote_traits<typename V1::value_type, typename V2::value_type>::promote_type promote_type;
    00164             vector<promote_type> vt (t1 * v1 + t2 * v2);
    00165             v2.assign (- t2 * v1 + t1 * v2);
    00166             v1.assign (vt);
    00167         }
    00168
    00169     }
    00170
    00176     namespace blas_2 {
    00177
    00187         template<class V, class M>
    00188         V & tmv (V &v, const M &m)
    00189         {
    00190             return v = prod (m, v);
    00191         }
    00192
    00204         template<class V, class M, class C>
    00205         V & tsv (V &v, const M &m, C)
    00206         {
    00207             return v = solve (m, v, C ());
    00208         }
    00209
    00225         template<class V1, class T1, class T2, class M, class V2>
    00226         V1 & gmv (V1 &v1, const T1 &t1, const T2 &t2, const M &m, const V2 &v2)
    00227         {
    00228             return v1 = t1 * v1 + t2 * prod (m, v2);
    00229         }
    00230
    00244         template<class M, class T, class V1, class V2>
    00245         M & gr (M &m, const T &t, const V1 &v1, const V2 &v2)
    00246         {
    00247 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
    00248             return m += t * outer_prod (v1, v2);
    00249 #else
    00250             return m = m + t * outer_prod (v1, v2);
    00251 #endif
    00252         }
    00253
    00265         template<class M, class T, class V>
    00266         M & sr (M &m, const T &t, const V &v)
    00267         {
    00268 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
    00269             return m += t * outer_prod (v, v);
    00270 #else
    00271             return m = m + t * outer_prod (v, v);
    00272 #endif
    00273         }
    00274
    00286         template<class M, class T, class V>
    00287         M & hr (M &m, const T &t, const V &v)
    00288         {
    00289 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
    00290             return m += t * outer_prod (v, conj (v));
    00291 #else
    00292             return m = m + t * outer_prod (v, conj (v));
    00293 #endif
    00294         }
    00295
    00309         template<class M, class T, class V1, class V2>
    00310         M & sr2 (M &m, const T &t, const V1 &v1, const V2 &v2)
    00311         {
    00312 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
    00313             return m += t * (outer_prod (v1, v2) + outer_prod (v2, v1));
    00314 #else
    00315             return m = m + t * (outer_prod (v1, v2) + outer_prod (v2, v1));
    00316 #endif
    00317         }
    00318
    00332         template<class M, class T, class V1, class V2>
    00333         M & hr2 (M &m, const T &t, const V1 &v1, const V2 &v2)
    00334         {
    00335 #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
    00336             return m += t * outer_prod (v1, conj (v2)) + type_traits<T>::conj (t) * outer_prod (v2, conj (v1));
    00337 #else
    00338             return m = m + t * outer_prod (v1, conj (v2)) + type_traits<T>::conj (t) * outer_prod (v2, conj (v1));
    00339 #endif
    00340         }
    00341
    00342     }
    00343
    00349     namespace blas_3 {
    00350
    00365         template<class M1, class T, class M2, class M3>
    00366         M1 & tmm (M1 &m1, const T &t, const M2 &m2, const M3 &m3)
    00367         {
    00368             return m1 = t * prod (m2, m3);
    00369         }
    00370
    00384         template<class M1, class T, class M2, class C>
    00385         M1 & tsm (M1 &m1, const T &t, const M2 &m2, C)
    00386         {
    00387             return m1 = solve (m2, t * m1, C ());
    00388         }
    00389
    00405         template<class M1, class T1, class T2, class M2, class M3>
    00406         M1 & gmm (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3)
    00407         {
    00408             return m1 = t1 * m1 + t2 * prod (m2, m3);
    00409         }
    00410
    00425         template<class M1, class T1, class T2, class M2>
    00426         M1 & srk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2)
    00427         {
    00428             return m1 = t1 * m1 + t2 * prod (m2, trans (m2));
    00429         }
    00430
    00445         template<class M1, class T1, class T2, class M2>
    00446         M1 & hrk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2)
    00447         {
    00448             return m1 = t1 * m1 + t2 * prod (m2, herm (m2));
    00449         }
    00450
    00467         template<class M1, class T1, class T2, class M2, class M3>
    00468         M1 & sr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3)
    00469         {
    00470             return m1 = t1 * m1 + t2 * (prod (m2, trans (m3)) + prod (m3, trans (m2)));
    00471         }
    00472
    00489         template<class M1, class T1, class T2, class M2, class M3>
    00490         M1 & hr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3)
    00491         {
    00492             return m1 =
    00493                       t1 * m1
    00494                     + t2 * prod (m2, herm (m3))
    00495                     + type_traits<T2>::conj (t2) * prod (m3, herm (m2));
    00496         }
    00497
    00498     }
    00499
    00500 }}}
    00501
    00502 #endif