CPPLapack
 All Classes Files Functions Variables Friends Pages
drovector-drovector.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! drovector=drovector operator */
4 {CPPL_VERBOSE_REPORT;
5  if(array!=vec.array){ // if it is NOT self substitution
6  copy(vec);
7  }
8  return *this;
9 }
10 
11 ///////////////////////////////////////////////////////////////////////////////
12 ///////////////////////////////////////////////////////////////////////////////
13 ///////////////////////////////////////////////////////////////////////////////
14 
15 //=============================================================================
16 /*! drovector+=drovector operator */
18 {CPPL_VERBOSE_REPORT;
19 #ifdef CPPL_DEBUG
20  if( l!=vec.l ){
21  ERROR_REPORT;
22  std::cerr << "These two vectors can not make a sumation." << std::endl
23  << "Your input was (" << l << ") += (" << vec.l << ")." << std::endl;
24  exit(1);
25  }
26 #endif//CPPL_DEBUG
27 
28  for(CPPL_INT i=0; i<l; i++){ array[i]+=vec.array[i]; }
29 
30  return *this;
31 }
32 
33 //=============================================================================
34 /*! drovector operator-= */
36 {CPPL_VERBOSE_REPORT;
37 #ifdef CPPL_DEBUG
38  if( l!=vec.l ){
39  ERROR_REPORT;
40  std::cerr << "These two vectors can not make a subtraction." << std::endl
41  << "Your input was (" << l << ") -= (" << vec.l << ")." << std::endl;
42  exit(1);
43  }
44 #endif//CPPL_DEBUG
45 
46  for(CPPL_INT i=0; i<l; i++){ array[i]-=vec.array[i]; }
47 
48  return *this;
49 }
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 //=============================================================================
56 /*! drovector+drovector operator */
57 inline _drovector operator+(const drovector& vecA, const drovector& vecB)
58 {CPPL_VERBOSE_REPORT;
59 #ifdef CPPL_DEBUG
60  if(vecA.l!=vecB.l){
61  ERROR_REPORT;
62  std::cerr << "These two vectors can not make a sumation." << std::endl
63  << "Your input was (" << vecA.l << ") + (" << vecB.l << ")." << std::endl;
64  exit(1);
65  }
66 
67 #endif//CPPL_DEBUG
68 
69  drovector newvec(vecA.l);
70  for(CPPL_INT i=0; i<newvec.l; i++){
71  newvec.array[i] =vecA.array[i]+vecB.array[i];
72  }
73 
74  return _(newvec);
75 }
76 
77 //=============================================================================
78 /*! drovector-drovector operator */
79 inline _drovector operator-(const drovector& vecA, const drovector& vecB)
80 {CPPL_VERBOSE_REPORT;
81 #ifdef CPPL_DEBUG
82  if(vecA.l!=vecB.l){
83  ERROR_REPORT;
84  std::cerr << "These two vectors can not make a subtraction." << std::endl
85  << "Your input was (" << vecA.l << ") - (" << vecB.l << ")." << std::endl;
86  exit(1);
87  }
88 #endif//CPPL_DEBUG
89 
90  drovector newvec(vecA.l);
91  for(CPPL_INT i=0; i<newvec.l; i++){
92  newvec.array[i] =vecA.array[i]-vecB.array[i];
93  }
94 
95  return _(newvec);
96 }
97 
98 //=============================================================================
99 /*! drovector^T*drovector operator (inner product) */
100 inline double operator%(const drovector& vecA, const drovector& vecB)
101 {CPPL_VERBOSE_REPORT;
102 #ifdef CPPL_DEBUG
103  if(vecA.l!=vecB.l){
104  ERROR_REPORT;
105  std::cerr << "These two vectors can not make a dot product." << std::endl
106  << "Your input was (" << vecA.l << ") % (" << vecB.l << ")." << std::endl;
107  exit(1);
108  }
109 #endif//CPPL_DEBUG
110 
111  CPPL_INT inc =1;
112  double val =ddot_( &vecA.l, vecA.array, &inc, vecB.array, &inc );
113 
114  return val;
115 }
116 
117 ///////////////////////////////////////////////////////////////////////////////
118 ///////////////////////////////////////////////////////////////////////////////
119 ///////////////////////////////////////////////////////////////////////////////
120 
121 //=============================================================================
122 /*! return Hadamerd product */
123 inline _drovector hadamerd(const drovector& vecA, const drovector& vecB)
124 {CPPL_VERBOSE_REPORT;
125 #ifdef CPPL_DEBUG
126  if( vecA.l!=vecB.l ){
127  ERROR_REPORT;
128  std::cerr << "These two vectors can not make Hadamerd product." << std::endl
129  << "Your input was (" << vecA.l << ") and (" << vecB.l << ")." << std::endl;
130  exit(1);
131  }
132 #endif//CPPL_DEBUG
133 
134  drovector newvec(vecA.l);
135  for(CPPL_INT i=0; i<newvec.l; i++){
136  newvec(i) =vecA(i)*vecB(i);
137  }
138  return _(newvec);
139 }
_drovector hadamerd(const drovector &vecA, const drovector &vecB)
double * array
1D array to store vector data
Definition: drovector.hpp:11
_drovector operator+(const drovector &vecA, const drovector &vecB)
_dgematrix i(const _dgbmatrix &mat)
CPPL_INT l
vector size
Definition: drovector.hpp:9
Real Double-precision Row Vector Class.
Definition: drovector.hpp:3
(DO NOT USE) Smart-temporary Real Double-precision Row Vector Class
Definition: _drovector.hpp:3
_drovector operator-(const drovector &vecA, const drovector &vecB)
drovector & operator-=(const drovector &)
void copy(const drovector &)
drovector & operator+=(const drovector &)
_dcovector _(dcovector &vec)
drovector & operator=(const drovector &)
double operator%(const drovector &vecA, const drovector &vecB)