aboutsummaryrefslogtreecommitdiffstats
path: root/math/vector_operation.hpp
blob: d149c41f3a82022945bcb6b712b867633bbbfdeb (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
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
   \file vector_operation.hpp
   \brief defing vector operators
   \author Junhua Gu
 */


#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 contract1(const T& x1,const T& x2,...)
  {
    return x1*x2;
  }
  
  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