queso-0.55.0
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-2015 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 
56  GslVector(const BaseEnvironment& env, const Map& map);
57  GslVector(const BaseEnvironment& env, const Map& map, double value);
58  GslVector(const BaseEnvironment& env, double d1, double d2, const Map& map); // MATLAB linspace
59 
61  GslVector(const GslVector& v, double start, double end);
62  GslVector(const GslVector& y);
63 
65  ~GslVector();
67 
69 
70  GslVector& operator= (const GslVector& rhs);
72 
74  GslVector& operator*=(double a);
75 
77  GslVector& operator/=(double a);
78 
80  GslVector& operator*=(const GslVector& rhs);
81 
83  GslVector& operator/=(const GslVector& rhs);
84 
86  GslVector& operator+=(const GslVector& rhs);
87 
89  GslVector& operator-=(const GslVector& rhs);
91 
93 
94 
96  double& operator[](unsigned int i);
97 
99 
101  const double& operator[](unsigned int i) const;
103 
105 
106  unsigned int sizeLocal () const;
108 
110  unsigned int sizeGlobal () const;
112 
114 
115  double norm2Sq () const;
117 
119  double norm2 () const;
120 
122  double norm1 () const;
123 
125  double normInf () const;
126 
128  double sumOfComponents () const;
130 
132 
133  void cwSet (double value);
135 
137  void cwSetGaussian (double mean, double stdDev);
138 
140  void cwSetGaussian (const GslVector& meanVec, const GslVector& stdDevVec);
141 
143  void cwSetUniform (const GslVector& aVec, const GslVector& bVec);
144 
146  void cwSetBeta (const GslVector& alpha, const GslVector& beta);
147 
149  void cwSetGamma (const GslVector& a, const GslVector& b);
150 
152  void cwSetInverseGamma(const GslVector& alpha, const GslVector& beta);
153 
155  void cwSetConcatenated(const GslVector& v1, const GslVector& v2);
156 
158  void cwSetConcatenated(const std::vector<const GslVector* >& vecs);
159 
161  void cwSet (unsigned int initialPos, const GslVector& vec);
162 
164  void cwExtract (unsigned int initialPos, GslVector& vec) const;
165 
167  void cwInvert ();
168 
170  void cwSqrt ();
172 
174 
175  void print (std::ostream& os) const;
178 
180  void sort ();
181 
182  void matlabDiff (unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector& outputVec) const;
183  void matlabLinearInterpExtrap(const GslVector& x1Vec, const GslVector& y1Vec, const GslVector& x2Vec);
184  void mpiBcast (int srcRank, const MpiComm& bcastComm);
185  void mpiAllReduce (RawType_MPI_Op mpiOperation, const MpiComm& opComm, GslVector& resultVec) const;
186  void mpiAllQuantile (double probability, const MpiComm& opComm, GslVector& resultVec) const;
187  void subWriteContents (const std::string& varNamePrefix,
188  const std::string& fileName,
189  const std::string& fileType,
190  const std::set<unsigned int>& allowedSubEnvIds) const;
191  void subReadContents (const std::string& fileName,
192  const std::string& fileType,
193  const std::set<unsigned int>& allowedSubEnvIds);
194 
196 
197  bool atLeastOneComponentSmallerThan (const GslVector& rhs) const;
199 
201  bool atLeastOneComponentBiggerThan (const GslVector& rhs) const;
202 
204  bool atLeastOneComponentSmallerOrEqualThan(const GslVector& rhs) const;
205 
207  bool atLeastOneComponentBiggerOrEqualThan (const GslVector& rhs) const;
209 
210  // Necessary for GslMatrix::invertMultiply() and GslMatrix::setRow/Column
211  gsl_vector* data () const;
212 
214 
215  double getMaxValue () const;
217 
219  double getMinValue () const;
220 
222  int getMaxValueIndex () const;
223 
225  int getMinValueIndex () const;
226 
228  void getMaxValueAndIndex( double& value, int& index );
229 
231  void getMinValueAndIndex( double& value, int& index );
232 
234  GslVector abs() const;
236 private:
238 
239  GslVector();
240 
242  void copy (const GslVector& src);
243 
245  gsl_vector* m_vec;
246 };
247 
248 // Comments in this part of file don't appear in the doxygen docs.
249 
250 GslVector operator/ ( double a, const GslVector& x );
251 GslVector operator/ (const GslVector& x, const GslVector& y );
252 GslVector operator* ( double a, const GslVector& x );
253 GslVector operator* (const GslVector& x, const GslVector& y );
254 double scalarProduct(const GslVector& x, const GslVector& y );
255 GslVector operator+ (const GslVector& x, const GslVector& y );
256 GslVector operator- (const GslVector& x, const GslVector& y );
257 bool operator== (const GslVector& lhs, const GslVector& rhs);
258 std::ostream& operator<< (std::ostream& os, const GslVector& obj);
259 
260 
261 inline
262 double&
263 GslVector::operator[](unsigned int i)
264 {
265  return *gsl_vector_ptr(m_vec,i);
266 }
267 
268 
269 inline
270 const double&
271 GslVector::operator[](unsigned int i) const
272 {
273  return *gsl_vector_const_ptr(m_vec,i);
274 }
275 
276 
277 } // End namespace QUESO
278 
279 #endif // UQ_GSL_VECTOR_H
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
Definition: GslVector.C:842
void cwSetConcatenated(const GslVector &v1, const GslVector &v2)
This function concatenates GslVector v1 and GslVector v2 into this.
Definition: GslVector.C:448
Class for vector operations (virtual).
Definition: Vector.h:47
void cwSqrt()
This function returns component-wise the square-root of this.
Definition: GslVector.C:520
void sort()
This function sorts the elements of the vector this in ascending numerical order. ...
Definition: GslVector.C:626
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:422
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:975
GslVector & operator+=(const GslVector &rhs)
Stores in this the coordinate-wise addition of this and rhs.
Definition: GslVector.C:210
double getMinValue() const
Returns minimum value in the vector this.
Definition: GslVector.C:1045
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:435
void getMaxValueAndIndex(double &value, int &index)
This function returns maximum value in the vector this and its the index.
Definition: GslVector.C:1063
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:365
A class for partitioning vectors and matrices.
Definition: Map.h:49
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:495
GslVector & operator-=(const GslVector &rhs)
Stores in this the coordinate-wise subtraction of this by rhs.
Definition: GslVector.C:219
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:1023
void matlabLinearInterpExtrap(const GslVector &x1Vec, const GslVector &y1Vec, const GslVector &x2Vec)
Definition: GslVector.C:556
GslVector()
Default Constructor.
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:1947
unsigned int sizeGlobal() const
Returns the global length of this vector.
Definition: GslVector.C:266
double getMaxValue() const
Returns the maximum value in the vector this.
Definition: GslVector.C:1039
void mpiAllQuantile(double probability, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:710
void cwSet(double value)
Component-wise sets all values to this with value.
Definition: GslVector.C:326
GslVector operator/(double a, const GslVector &x)
Definition: GslVector.C:1103
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
GslVector abs() const
This function returns absolute value of elements in this.
Definition: GslVector.C:1081
double norm2Sq() const
Returns the 2-norm squared of this vector.
Definition: GslVector.C:274
~GslVector()
Destructor.
Definition: GslVector.C:143
const Map & map() const
Definition: Vector.C:61
GslVector & operator=(const GslVector &rhs)
Copies values from vector rhs to this.
Definition: GslVector.C:149
int getMaxValueIndex() const
This function returns the index of the maximum value in the vector this.
Definition: GslVector.C:1051
double & operator[](unsigned int i)
Element access method (non-const).
Definition: GslVector.h:263
void mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm &opComm, GslVector &resultVec) const
Definition: GslVector.C:689
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
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:742
double sumOfComponents() const
Returns the sum of the components of the vector.
Definition: GslVector.C:314
int getMinValueIndex() const
This function returns the index of the minimum value in the vector this.
Definition: GslVector.C:1057
gsl_vector * data() const
Definition: GslVector.C:969
GslVector & operator/=(double a)
Stores in this the coordinate-wise division of this by a.
Definition: GslVector.C:174
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:240
GslVector & operator*=(double a)
Stores in this the coordinate-wise multiplication of this and a.
Definition: GslVector.C:165
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:1994
void copy(const GslVector &src)
This function copies the elements of the vector src into this.
Definition: GslVector.C:229
void cwInvert()
This function inverts component-wise the element values of this.
Definition: GslVector.C:509
double normInf() const
Returns the infinity-norm (maximum norm) of the vector.
Definition: GslVector.C:299
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:1987
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:991
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:1007
gsl_vector * m_vec
GSL vector.
Definition: GslVector.h:245
Class for vector operations using GSL library.
Definition: GslVector.h:49
double norm1() const
Returns the 1-norm of the vector.
Definition: GslVector.C:286
bool operator==(const GslVector &lhs, const GslVector &rhs)
Definition: GslVector.C:1167
void subWriteContents(const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const
Definition: GslVector.C:802
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void matlabDiff(unsigned int firstPositionToStoreDiff, double valueForRemainderPosition, GslVector &outputVec) const
Definition: GslVector.C:531
const BaseEnvironment & env() const
Definition: Vector.C:54
void mpiBcast(int srcRank, const MpiComm &bcastComm)
Definition: GslVector.C:634
void getMinValueAndIndex(double &value, int &index)
This function returns minimum value in the vector this and its the index.
Definition: GslVector.C:1072
int RawType_MPI_Op
Definition: MpiComm.h:61
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:356
double norm2() const
Returns the 2-norm (Euclidean norm) of the vector.
Definition: GslVector.C:280
void cwSetGaussian(double mean, double stdDev)
This function sets component-wise Gaussian random variates, with mean mean and standard deviation std...
Definition: GslVector.C:337
double scalarProduct(const GslVector &x, const GslVector &y)
Definition: GslVector.C:1136

Generated on Fri Jun 17 2016 14:17:40 for queso-0.55.0 by  doxygen 1.8.5