File: nvector.hh

package info (click to toggle)
python-demgengeo 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,004 kB
  • ctags: 2,158
  • sloc: cpp: 12,532; python: 1,260; makefile: 281; sh: 92
file content (115 lines) | stat: -rw-r--r-- 2,481 bytes parent folder | download | duplicates (2)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2007-2014 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////

template<class T,int n>
nvector<T,n>::nvector()
{}

template<class T,int n>
nvector<T,n>::nvector(const T t)
{
  for(int i=0;i<n;i++){
    m_data[i]=t; 
  }
}

template<class T,int n>
nvector<T,n>::nvector(const nvector& v)
{
  for(int i=0;i<n;i++){
    m_data[i]=v.m_data[i]; 
  }
}

template<class T,int n>
nvector<T,n>::~nvector()
{}

template<class T,int n>
nvector<T,n>& nvector<T,n>::operator=(const nvector<T,n>& v)
{
  if(&v!=this){
    for(int i=0;i<n;i++){
      m_data[i]=v.m_data[i]; 
    }
  }
  return *this;
}

template<class T,int n>
nvector<T,n>& nvector<T,n>::operator-=(const nvector<T,n>& v)
{
  for(int i=0;i<n;i++){
    m_data[i]-=v.m_data[i]; 
  }
  return *this;
}

template<class T,int n>
nvector<T,n>& nvector<T,n>::operator+=(const nvector<T,n>& v)
{
  for(int i=0;i<n;i++){
    m_data[i]+=v.m_data[i]; 
  }
  return *this;
}

template<class T,int n>
nvector<T,n> nvector<T,n>::operator+(const nvector<T,n>& v) const
{
  nvector<T,n> res;
  for(int i=0;i<n;i++){
    res.m_data[i]=m_data[i]+v.m_data[i]; 
  }
  return res;
}

template<class T,int n>
nvector<T,n> nvector<T,n>::operator-(const nvector<T,n>& v) const
{
  nvector<T,n> res;
  for(int i=0;i<n;i++){
    res.m_data[i]=m_data[i]-v.m_data[i]; 
  }
  return res;
}

template<class T,int n>
nvector<T,n> operator/(const nvector<T,n>& v, T d)
{
  nvector<T,n> res;
  for(int i=0;i<n;i++){
    res.m_data[i]=v.m_data[i]/d; 
  }
  return res;
}

template<class T,int n>
nvector<T,n> nvector<T,n>::unit(int i)
{
  nvector<T,n> res;
  for(int j=0;j<n;j++){
    res.m_data[j]=(i==j)? T(1) : T(0);
  }
  return res;
}

template<class T,int n> 
ostream& operator<<(ostream& ost,const nvector<T,n>& v)
{
  ost << "<" << v.m_data[0];
  for(int i=1;i<n;i++){
    ost << "," << v.m_data[i];
  }
  ost << ">";
  return ost;
}