queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
GslVector.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 //--------------------------------------------------------------------------
25 
26 #ifndef UQ_GSL_VECTOR_H
27 #define UQ_GSL_VECTOR_H
28 
33 #include <queso/Defines.h>
34 #include <queso/Vector.h>
35 
36 #include <gsl/gsl_vector.h>
37 
38 namespace QUESO {
39 
49 class GslVector : public Vector
50 {
51 public:
52 
54 
55 
57  GslVector(const BaseEnvironment& env, const Map& map);
58 
60  GslVector(const BaseEnvironment& env, const Map& map, double value);
61 
63  // like MATLAB linspace does.
64  GslVector(const BaseEnvironment& env, double d1, double d2, const Map& map);
65 
67  GslVector(const GslVector& v, double start, double end);
68 
70  GslVector(const GslVector& y);
71 
73  ~GslVector();
75 
77 
78  GslVector& operator= (const GslVector& rhs);
80 
82  GslVector& operator*=(double a);
83 
85  GslVector& operator/=(double a);
86 
88  GslVector& operator*=(const GslVector& rhs);
89 
91  GslVector& operator/=(const GslVector& rhs);
92 
94  GslVector& operator+=(const GslVector& rhs);
95 
97  GslVector& operator-=(const GslVector& rhs);
99 
101 
102 
104  double& operator[](unsigned int i);
105 
107 
109  const double& operator[](unsigned int i) const;
111 
113 
114  unsigned int sizeLocal () const;
116 
118  unsigned int sizeGlobal () const;
120 
122 
123  double norm2Sq () const;
125 
127  double norm2 () const;
128 
130  double norm1 () const;
131 
133  double normInf () const;
134 
136  double sumOfComponents () const;
138 
140 
141  void cwSet (double value);
143 
145  void cwSetGaussian (double mean, double stdDev);
146 
148  void cwSetGaussian (const GslVector& meanVec, const GslVector& stdDevVec);
149 
151  void cwSetUniform (const GslVector& aVec, const GslVector& bVec);
152 
154  void cwSetBeta (const GslVector& alpha, const GslVector& beta);
155 
157  void cwSetGamma (const GslVector& a, const GslVector& b);
158 
160  void cwSetInverseGamma(const GslVector& alpha, const GslVector& beta);
161 
163  void cwSetConcatenated(const GslVector& v1, const GslVector& v2);
164 
166  void cwSetConcatenated(const std::vector<const GslVector* >& vecs);
167 
169  void cwSet (unsigned int initialPos, const GslVector& vec);
170 
172  void cwExtract (unsigned int initialPos, GslVector& vec) const;
173 
175  void cwInvert ();
176 
178  void cwSqrt ();
180 
182 
183  void print (std::ostream& os) const;
186 
188  void sort ();
189 
190  void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector& outputVec) const;
191  void matlabLinearInterpExtrap(const GslVector& x1Vec, const GslVector& y1Vec, const GslVector& x2Vec);
192  void mpiBcast (int srcRank, const MpiComm& bcastComm);
193  void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm& opComm, GslVector& resultVec) const;
194  void mpiAllQuantile (double probability, const MpiComm& opComm, GslVector& resultVec) const;
195  void subWriteContents (const std::string& varNamePrefix,
196  const std::string& fileName,
197  const std::string& fileType,
198  const std::set<unsigned int>& allowedSubEnvIds) const;
199  void subReadContents (const std::string& fileName,
200  const std::string& fileType,
201  const std::set<unsigned int>& allowedSubEnvIds);
202 
204 
205  bool atLeastOneComponentSmallerThan (const GslVector& rhs) const;
207 
209  bool atLeastOneComponentBiggerThan (const GslVector& rhs) const;
210 
212  bool atLeastOneComponentSmallerOrEqualThan(const GslVector& rhs) const;
213 
215  bool atLeastOneComponentBiggerOrEqualThan (const GslVector& rhs) const;
217 
218  // Necessary for GslMatrix::invertMultiply() and GslMatrix::setRow/Column
219  gsl_vector* data () const;
220 
222 
223  double getMaxValue () const;
225 
227  double getMinValue () const;
228 
230  int getMaxValueIndex () const;
231 
233  int getMinValueIndex () const;
234 
236  void getMaxValueAndIndex( double& value, int& index );
237 
239  void getMinValueAndIndex( double& value, int& index );
240 
242  GslVector abs() const;
244 private:
246 
247  GslVector();
248 
250  void copy (const GslVector& src);
251 
253  gsl_vector* m_vec;
254 };
255 
256 // Comments in this part of file don't appear in the doxygen docs.
257 
258 GslVector operator/ ( double a, const GslVector& x );
259 GslVector operator/ (const GslVector& x, const GslVector& y );
260 GslVector operator* ( double a, const GslVector& x );
261 GslVector operator* (const GslVector& x, const GslVector& y );
262 double scalarProduct(const GslVector& x, const GslVector& y );
263 GslVector operator+ (const GslVector& x, const GslVector& y );
264 GslVector operator- (const GslVector& x, const GslVector& y );
265 bool operator== (const GslVector& lhs, const GslVector& rhs);
266 std::ostream& operator<< (std::ostream& os, const GslVector& obj);
267 
268 
269 inline
270 double&
271 GslVector::operator[](unsigned int i)
272 {
273  return *gsl_vector_ptr(m_vec,i);
274 }
275 
276 
277 inline
278 const double&
279 GslVector::operator[](unsigned int i) const
280 {
281  return *gsl_vector_const_ptr(m_vec,i);
282 }
283 
284 
285 } // End namespace QUESO
286 
287 #endif // UQ_GSL_VECTOR_H
GslVector()
Default Constructor.
void mpiBcast(int srcRank, const MpiComm &bcastComm)
Definition: GslVector.C:635
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:327
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
Definition: GslVector.C:843
GslVector & operator/=(double a)
Stores in this the coordinate-wise division of this by a.
Definition: GslVector.C:175
GslVector abs() const
This function returns absolute value of elements in this.
Definition: GslVector.C:1082
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
Definition: GslVector.C:1052
A class for partitioning vectors and matrices.
Definition: Map.h:49
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
bool atLeastOneComponentBiggerOrEqualThan(const GslVector &rhs) const
This function returns true if at least one component of this is bigger than or equal to the respectiv...
Definition: GslVector.C:1024
void matlabDiff(unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector &outputVec) const
Definition: GslVector.C:532
void cwSqrt()
This function returns component-wise the square-root of this.
Definition: GslVector.C:521
unsigned int sizeGlobal() const
Returns the global length of this vector.
Definition: GslVector.C:267
bool atLeastOneComponentSmallerThan(const GslVector &rhs) const
This function returns true if at least one component of this is smaller than the respective component...
Definition: GslVector.C:976
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
void cwSetConcatenated(const GslVector &v1, const GslVector &v2)
This function concatenates GslVector v1 and GslVector v2 into this.
Definition: GslVector.C:449
void getMaxValueAndIndex(double &value, int &index)
This function returns maximum value in the vector this and its the index.
Definition: GslVector.C:1064
double & operator[](unsigned int i)
Element access method (non-const).
Definition: GslVector.h:271
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2029
void mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:690
double getMaxValue() const
Returns the maximum value in the vector this.
Definition: GslVector.C:1040
double normInf() const
Returns the infinity-norm (maximum norm) of the vector.
Definition: GslVector.C:300
double getMinValue() const
Returns minimum value in the vector this.
Definition: GslVector.C:1046
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1137
bool operator==(const GslVector &lhs, const GslVector &rhs)
Definition: GslVector.C:1168
void cwSetGamma(const GslVector &a, const GslVector &b)
This function returns a random variate from the gamma distribution with vector parameters a and b...
Definition: GslVector.C:423
Class for vector operations (virtual).
Definition: Vector.h:47
void cwExtract(unsigned int initialPos, GslVector &vec) const
This function sets the values of this starting at position initialPos ans saves them in vector vec...
Definition: GslVector.C:496
~GslVector()
Destructor.
Definition: GslVector.C:144
GslVector & operator*=(double a)
Stores in this the coordinate-wise multiplication of this and a.
Definition: GslVector.C:166
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:1982
void cwInvert()
This function inverts component-wise the element values of this.
Definition: GslVector.C:510
gsl_vector * data() const
Definition: GslVector.C:970
void matlabLinearInterpExtrap(const GslVector &x1Vec, const GslVector &y1Vec, const GslVector &x2Vec)
Definition: GslVector.C:557
Class for vector operations using GSL library.
Definition: GslVector.h:49
const BaseEnvironment & env() const
Definition: Vector.C:54
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
Definition: GslVector.C:1058
const Map & map() const
Definition: Vector.C:61
GslVector operator/(double a, const GslVector &x)
Definition: GslVector.C:1104
bool atLeastOneComponentBiggerThan(const GslVector &rhs) const
This function returns true if at least one component of this is bigger than the respective component ...
Definition: GslVector.C:992
void cwSetUniform(const GslVector &aVec, const GslVector &bVec)
This function sets component-wise a number uniformly distributed in the range of elements of [aVec...
Definition: GslVector.C:357
MPI_Op RawType_MPI_Op
Definition: MpiComm.h:45
void mpiAllQuantile(double probability, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:711
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
bool atLeastOneComponentSmallerOrEqualThan(const GslVector &rhs) const
This function returns true if at least one component of this is smaller than or equal to the respecti...
Definition: GslVector.C:1008
void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream &lt;&lt; operator inherited from the Object class...
Definition: GslVector.C:743
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:241
double sumOfComponents() const
Returns the sum of the components of the vector.
Definition: GslVector.C:315
void cwSetInverseGamma(const GslVector &alpha, const GslVector &beta)
This function returns a random variate from the inverse gamma distribution with vector parameters alp...
Definition: GslVector.C:436
double norm1() const
Returns the 1-norm of the vector.
Definition: GslVector.C:287
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:230
GslVector & operator=(const GslVector &rhs)
Copies values from vector rhs to this.
Definition: GslVector.C:150
GslVector & operator+=(const GslVector &rhs)
Stores in this the coordinate-wise addition of this and rhs.
Definition: GslVector.C:211
double norm2Sq() const
Returns the 2-norm squared of this vector.
Definition: GslVector.C:275
void cwSetGaussian(double mean, double stdDev)
This function sets component-wise Gaussian random variates, with mean mean and standard deviation std...
Definition: GslVector.C:338
GslVector & operator-=(const GslVector &rhs)
Stores in this the coordinate-wise subtraction of this by rhs.
Definition: GslVector.C:220
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:253
void getMinValueAndIndex(double &value, int &index)
This function returns minimum value in the vector this and its the index.
Definition: GslVector.C:1073
void sort()
This function sorts the elements of the vector this in ascending numerical order. ...
Definition: GslVector.C:627
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Definition: GslVector.C:803
void cwSetBeta(const GslVector &alpha, const GslVector &beta)
This function returns a random variate from the beta distribution, with vector parameters alpha and b...
Definition: GslVector.C:366
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2022
double norm2() const
Returns the 2-norm (Euclidean norm) of the vector.
Definition: GslVector.C:281

Generated on Tue Jun 5 2018 19:48:54 for queso-0.57.1 by  doxygen 1.8.5