My Project
dcovector-dcovector.hpp
1 //=============================================================================
3 inline dcovector& dcovector::operator=(const dcovector& vec)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dcovector::operator=(const dcovector&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  if(Array!=vec.Array){ // if it is NOT self substitution
11  copy(vec);
12  }
13  return *this;
14 }
15 
19 
20 //=============================================================================
22 inline dcovector& dcovector::operator+=(const dcovector& vec)
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] dcovector::operator+=(const dcovector&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if( L!=vec.L ){
31  std::cerr << "[ERROR] dcovector::operator+=(const dcovector&)" << std::endl
32  << "These two vectors can not make a sumation." << std::endl
33  << "Your input was (" << L << ") += (" << vec.L << ")."
34  << std::endl;
35  exit(1);
36  }
37 #endif//CPPL_DEBUG
38 
39  for(long i=0; i<L; i++){ Array[i]+=vec.Array[i]; }
40 
41  return *this;
42 }
43 
44 //=============================================================================
46 inline dcovector& dcovector::operator-=(const dcovector& vec)
47 {
48 #ifdef CPPL_VERBOSE
49  std::cerr << "# [MARK] dcovector::operator-=(const dcovector&)"
50  << std::endl;
51 #endif//CPPL_VERBOSE
52 
53 #ifdef CPPL_DEBUG
54  if( L!=vec.L ){
55  std::cerr << "[ERROR] dcovector::operator-=(const dcovector&)" << std::endl
56  << "These two vectors can not make a subtraction." << std::endl
57  << "Your input was (" << L << ") -= (" << vec.L << ")."
58  << std::endl;
59  exit(1);
60  }
61 #endif//CPPL_DEBUG
62 
63  for(long i=0; i<L; i++){ Array[i]-=vec.Array[i]; }
64 
65  return *this;
66 }
67 
71 
72 //=============================================================================
74 inline _dcovector operator+(const dcovector& vecA, const dcovector& vecB)
75 {
76 #ifdef CPPL_VERBOSE
77  std::cerr << "# [MARK] operator+(const dcovector&, const dcovector&)"
78  << std::endl;
79 #endif//CPPL_VERBOSE
80 
81 #ifdef CPPL_DEBUG
82  if(vecA.L!=vecB.L){
83  std::cerr << "[ERROR] operator+(const dcovector&, const dcovector&)"
84  << std::endl
85  << "These two vectors can not make a sumation." << std::endl
86  << "Your input was (" << vecA.L << ") + (" << vecB.L << ")."
87  << std::endl;
88  exit(1);
89  }
90 
91 #endif//CPPL_DEBUG
92 
93  dcovector newvec(vecA.L);
94  for(long i=0; i<newvec.L; i++){
95  newvec.array[i] =vecA.Array[i]+vecB.Array[i];
96  }
97 
98  return _(newvec);
99 }
100 
101 //=============================================================================
103 inline _dcovector operator-(const dcovector& vecA, const dcovector& vecB)
104 {
105 #ifdef CPPL_VERBOSE
106  std::cerr << "# [MARK] operator-(const dcovector&, const dcovector&)"
107  << std::endl;
108 #endif//CPPL_VERBOSE
109 
110 #ifdef CPPL_DEBUG
111  if(vecA.L!=vecB.L){
112  std::cerr << "[ERROR] operator-(const dcovector&, const dcovector&)"
113  << std::endl
114  << "These two vectors can not make a subtraction." << std::endl
115  << "Your input was (" << vecA.L << ") - (" << vecB.L << ")."
116  << std::endl;
117  exit(1);
118  }
119 #endif//CPPL_DEBUG
120 
121  dcovector newvec(vecA.L);
122  for(long i=0; i<newvec.L; i++){
123  newvec.array[i] =vecA.Array[i]-vecB.Array[i];
124  }
125 
126  return _(newvec);
127 }
128 
129 //=============================================================================
131 inline double operator%(const dcovector& vecA, const dcovector& vecB)
132 {
133 #ifdef CPPL_VERBOSE
134  std::cerr << "# [MARK] operator%(const dcovector&, const dcovector&)"
135  << std::endl;
136 #endif//CPPL_VERBOSE
137 
138 #ifdef CPPL_DEBUG
139  if(vecA.L!=vecB.L){
140  std::cerr << "[ERROR] operator%(const dcovector&, const dcovector&)"
141  << std::endl
142  << "These two vectors can not make a dot product." << std::endl
143  << "Your input was (" << vecA.L << ") % (" << vecB.L << ")."
144  << std::endl;
145  exit(1);
146  }
147 #endif//CPPL_DEBUG
148 
149  double val( ddot_( vecA.L, vecA.Array, 1, vecB.Array, 1 ) );
150 
151  return val;
152 }
dcovector & operator=(const dcovector &)
Definition: dcovector-dcovector.hpp:3
dcovector & operator+=(const dcovector &)
Definition: dcovector-dcovector.hpp:22
void copy(const dcovector &)
Definition: dcovector-misc.hpp:47
Real Double-precision Column Vector Class.
Definition: dcovector.hpp:3
(DO NOT USE) Smart-temporary Real Double-precision Column Vector Class
Definition: _dcovector.hpp:3
dcovector & operator-=(const dcovector &)
Definition: dcovector-dcovector.hpp:46