MathTL
algebra/vector_arithmetics.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_VECTOR_ARITHMETICS_H
00011 #define _MATHTL_VECTOR_ARITHMETICS_H
00012 
00013 #include <algorithm>
00014 #include <cassert>
00015 
00016 namespace MathTL
00017 {
00018   /*
00019     diverse external arithmetics for generic VECTOR classes
00020     with a standard signatur like std::vector<T>
00021 
00022     We use the size() routine for determining the dimension of the vector.
00023 
00024     You can use template specialization to speed up computation
00025     for specific VECTOR classes.
00026   */
00027 
00031   template <class VECTOR>
00032   double mean_value(const VECTOR& v)
00033   {
00034     assert(v.size() > 0);
00035 
00036     double r(0);
00037 
00038     typename VECTOR::const_iterator it(v.begin()), itend(v.end());
00039     while (it != itend)
00040       r += *it++;
00041 
00042     return r/v.size();
00043   }
00044 }
00045 
00046 #endif
 All Classes Functions Variables Typedefs Enumerations