Program listing for file kernel/src/utils/SiconosAlgebra/SiconosVector.hpp#
Return to documentation for this file
1#ifndef __SiconosVector__
2#define __SiconosVector__
3
4#include "SiconosAlgebraTypeDef.hpp"
5#include "SiconosVectorFriends.hpp"
6#include "SiconosSerialization.hpp"
7
8struct SiconosVectorIterator;
9struct SiconosVectorConstIterator;
10
11
12union VECTOR_UBLAS_TYPE
13{
14 DenseVect *Dense;
15 SparseVect *Sparse;
16};
17
18
19
20class SiconosVector : public std::enable_shared_from_this<SiconosVector>
21{
22protected:
23 ACCEPT_SERIALIZATION(SiconosVector);
24
25 bool _dense = true;
26
27
28 VECTOR_UBLAS_TYPE vect;
29
30public:
31
32
33
34
35 SiconosVector();
36
37
38 SiconosVector(unsigned row, siconos::UBLAS_TYPE type = siconos::DENSE);
39
40
41 SiconosVector(unsigned row, double val, siconos::UBLAS_TYPE type = siconos::DENSE);
42
43
44 SiconosVector(const std::vector<double>& vec, siconos::UBLAS_TYPE type = siconos::DENSE);
45
46
47 SiconosVector(const SiconosVector& v);
48
49
50 SiconosVector(const DenseVect& v);
51
52
53 SiconosVector(const SparseVect& v);
54
55
56 SiconosVector(const std::string& filename, bool is_ascii);
57
58
59 SiconosVector(const SiconosVector& v1, const SiconosVector& v2);
60
61
62 explicit SiconosVector(const BlockVector& input);
63
64
65 ~SiconosVector();
66
67
68 unsigned int size() const;
69
70
71 siconos::UBLAS_TYPE num() const
72 {
73 if (_dense) return siconos::DENSE;
74 else return siconos::SPARSE;
75 }
76
77
78 inline DenseVect* dense() const
79 {
80 return vect.Dense;
81 };
82
83
84 SparseVect* sparse() const;
85
86
87 double* getArray() const;
88
89
90 void zero();
91
92
93 void resize(unsigned int size, bool preserve= true);
94
95
96 double normInf()const;
97
98
99 double norm2() const ;
100
101
102 double vector_sum() const;
103
104
105 void display(void) const;
106
107
108 void fill(double a);
109
110
111 std::string toString() const;
112
113
114 typedef SiconosVectorIterator iterator;
115
116
117 typedef SiconosVectorConstIterator const_iterator;
118
119
120 iterator begin();
121
122
123 const_iterator begin() const;
124
125
126 iterator end();
127
128
129 const_iterator end() const;
130
131
132 operator std::vector<double>();
133
134
135
136
137 double getValue(unsigned int i) const ;
138
139
140 void setValue(unsigned int i, double value);
141
142
143 double& operator()(unsigned int i);
144
145
146 double operator()(unsigned int i) const;
147
148
149 void setBlock(unsigned int i, const SiconosVector& v);
150
151
152 void toBlock(SiconosVector& vOut, unsigned int sizeB,
153 unsigned int startIn, unsigned int startOut) const;
154
155
156 void addBlock(unsigned int i, const SiconosVector& v);
157
158
159 void subBlock(unsigned int i, const SiconosVector& v);
160
161
162 unsigned copyData(double* data) const;
163
164
165 SiconosVector& operator = (const SiconosVector& v);
166
167
168 SiconosVector& operator = (const BlockVector& b);
169
170
171 SiconosVector& operator = (const DenseVect& v);
172
173
174 SiconosVector& operator = (const SparseVect& sp);
175
176
177 SiconosVector& operator = (const double* d);
178
179
180 SiconosVector& operator +=(const SiconosVector& v);
181
182
183 SiconosVector& operator +=(const BlockVector& v);
184
185
186 SiconosVector& operator -=(const SiconosVector& v);
187
188 SiconosVector& operator -=(const BlockVector& v);
189
190
191
192
193 friend std::ostream& operator<<(std::ostream& os, const SiconosVector& sv);
194
195 friend SiconosVector& operator *= (SiconosVector& v, const double& s);
196
197 friend SiconosVector& operator /= (SiconosVector& v, const double& s);
198
199 friend bool operator ==(const SiconosVector&, const SiconosVector&);
200
201 friend SiconosVector operator * (double, const SiconosVector&);
202
203 friend SiconosVector operator * (const SiconosVector&, double);
204
205 friend SiconosVector operator / (const SiconosVector&, double);
206
207 friend SiconosVector operator + (const SiconosVector&, const SiconosVector&);
208
209 friend void add(const SiconosVector&, const SiconosVector&, SiconosVector&);
210
211 friend SiconosVector operator - (const SiconosVector&, const SiconosVector&);
212
213 friend void sub(const SiconosVector&, const SiconosVector&, SiconosVector&);
214
215 friend void axpby(double, const SiconosVector&, double, SiconosVector&);
216
217 friend void axpy(double, const SiconosVector&, SiconosVector&);
218
219 friend double inner_prod(const SiconosVector&, const SiconosVector&);
220
221 friend SimpleMatrix outer_prod(const SiconosVector&, const SiconosVector&);
222
223 friend void scal(double, const SiconosVector&, SiconosVector&, bool);
224
225 friend void subscal(double, const SiconosVector&, SiconosVector&, const Index&, bool);
226
227 friend void cross_product(const SiconosVector&, const SiconosVector&, SiconosVector&);
228
229 friend void abs_wise(const SiconosVector&, SiconosVector&);
230
231 friend void getMax(const SiconosVector&, double &, unsigned int &);
232
233 friend void getMin(const SiconosVector&, double &, unsigned int &);
234
235 friend struct IsDense;
236
237 friend struct IsSparse;
238
239 friend struct IsBlock;
240
241 friend class TestDense;
242
243
244
245
246 ACCEPT_NONVIRTUAL_VISITORS();
247
248};
249
250
251class TestDense
252{
253public:
254 bool operator()(SP::SiconosVector input) const
255 {
256 return input->_dense;
257 }
258};
259
260
261#endif