aboutsummaryrefslogtreecommitdiffstats
path: root/math/vector_operation.hpp
blob: a856847d15d3630597022806aaed0bb301ea6aaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef VECTOR_OPERATION_HPP
#define VECTOR_OPERATION_HPP
#include <core/opt_traits.hpp>
namespace opt_utilities
{

  template <typename pT>
  typename element_type_trait<pT>::element_type
  inner_product(const pT& v1,const pT& v2)
  {
    typename element_type_trait<pT>::element_type result(0);
    for(int i=0;i<get_size(v1);++i)
      {
	result+=get_element(v1,i)*get_element(v2,i);
      }
    return result;
  }

  template <typename T>
  T contract(const T& x1,const T& x2,...)
  {
    return x1*x2;
  }

  template <typename pT>
  typename element_type_trait<pT>::element_type
  contract(const pT& v1,const pT& v2,const typename element_type_trait<pT>::element_type&)
  {
    typename element_type_trait<pT>::element_type result(0);
    for(int i=0;i<get_size(v1);++i)
      {
	result+=get_element(v1,i)*get_element(v2,i);
      }
    return result;
  }

  
}
#endif