vectorop.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef __STL_ADDON_VECTOROP_H__
00003 #define __STL_ADDON_VECTOROP_H__
00004 
00027 #include <assert.h>
00028 #include <vector>
00029 
00030 namespace lemga {
00031 namespace op {
00032 
00033 using std::vector;
00034 
00036 template <typename R, typename N>
00037 vector<R>& operator+= (vector<R>& u, const vector<N>& v) {
00038     assert(u.size() == v.size());
00039     typename vector<R>::iterator x = u.begin();
00040     typename vector<N>::const_iterator y = v.begin();
00041     for (; x != u.end(); ++x, ++y) *x += *y;
00042     return u;
00043 }
00044 
00046 template <typename R>
00047 vector<R> operator- (const vector<R>& v) {
00048     vector<R> s(v);
00049     for (typename vector<R>::iterator x = s.begin(); x != s.end(); ++x)
00050         *x = -*x;
00051     return s;
00052 }
00053 
00060 template <typename R, typename N>
00061 inline R inner_product (const R& u, const N& v) {
00062     return u * v;
00063 }
00064 template <typename RET, typename R, typename N>
00065 RET inner_product (const vector<R>& u, const vector<N>& v) {
00066     assert(u.size() == v.size());
00067     RET s(0);
00068     typename vector<R>::const_iterator x = u.begin();
00069     typename vector<N>::const_iterator y = v.begin();
00070     for (; x != u.end(); ++x, ++y) s += inner_product<RET>(*x, *y);
00071     return s;
00072 }
00073 
00075 template <typename R, typename N>
00076 vector<R>& operator*= (vector<R>& v, const N& r) {
00077     for (typename vector<R>::iterator x = v.begin(); x != v.end(); ++x)
00078         *x *= r;
00079     return v;
00080 }
00081 
00082 }} // namespace lemga::op
00083 
00084 #ifdef  __VECTOROP_H__
00085 #warning "This header file may conflict with another `vectorop.h' file."
00086 #endif
00087 #define __VECTOROP_H__
00088 #endif

Generated on Mon Jan 9 23:43:25 2006 for LEMGA by  doxygen 1.4.6