GammaLib
2.0.0
|
Vector class. More...
#include <GVector.hpp>
Public Member Functions | |
GVector (void) | |
Void vector constructor. More... | |
GVector (const int &num) | |
Vector constructor. More... | |
GVector (const double &a) | |
Single element vector constructor. More... | |
GVector (const double &a, const double &b) | |
Two elements vector constructor. More... | |
GVector (const double &a, const double &b, const double &c) | |
Three elements vector constructor. More... | |
GVector (const GVector &vector) | |
Copy constructor. More... | |
virtual | ~GVector (void) |
Destructor. More... | |
double & | operator[] (const int &index) |
Vector element access operator. More... | |
const double & | operator[] (const int &index) const |
Vector element access operator (const variant) More... | |
bool | operator== (const GVector &vector) const |
Equality operator. More... | |
bool | operator!= (const GVector &vector) const |
Non-equality operator. More... | |
GVector & | operator= (const GVector &vector) |
Assignment operator. More... | |
GVector & | operator+= (const GVector &vector) |
Unary addition operator. More... | |
GVector & | operator-= (const GVector &vector) |
Unary subtraction operator. More... | |
GVector & | operator= (const double &scalar) |
Scalar assignment operator. More... | |
GVector & | operator+= (const double &scalar) |
Scalar unary addition operator. More... | |
GVector & | operator-= (const double &scalar) |
Scalar unary subtraction operator. More... | |
GVector & | operator*= (const double &scalar) |
Scalar unary multiplication operator. More... | |
GVector & | operator/= (const double &scalar) |
Scalar unary division operator. More... | |
GVector | operator- (void) const |
Unary minus operator. More... | |
void | clear (void) |
Clear vector. More... | |
GVector * | clone (void) const |
Clone vector. More... | |
std::string | classname (void) const |
Return class name. More... | |
const int & | size (void) const |
Return size of vector. More... | |
double & | at (const int &index) |
Vector element access with range checking. More... | |
const double & | at (const int &index) const |
Vector element access with range checking (const variant) More... | |
int | non_zeros (void) const |
Returns number of non-zero elements in vector. More... | |
int | first_nonzero (void) const |
Return the index of the first non-zero element in a vector. More... | |
int | last_nonzero (void) const |
Return the index of the last non-zero element in a vector. More... | |
GVector | slice (const int &start, const int &stop) const |
Vector slice operator. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print vector information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Private Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | alloc_members (void) |
Allocate vector. More... | |
void | copy_members (const GVector &vector) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
Private Attributes | |
int | m_num |
Number of elements in vector. More... | |
double * | m_data |
Vector array. More... | |
Friends | |
GVector | cross (const GVector &a, const GVector &b) |
Vector cross product. More... | |
double | operator* (const GVector &a, const GVector &b) |
Vector scalar product. More... | |
double | norm (const GVector &vector) |
Computes vector norm. More... | |
double | min (const GVector &vector) |
Computes minimum vector element. More... | |
double | max (const GVector &vector) |
Computes maximum vector element. More... | |
double | sum (const GVector &vector) |
Computes vector sum. More... | |
double | angle (const GVector &a, const GVector &b) |
Computes angle between vectors. More... | |
GVector | perm (const GVector &vector, const int *p) |
Computes vector permutation. More... | |
GVector | iperm (const GVector &vector, const int *p) |
Computes vector inverse permutation. More... | |
GVector | acos (const GVector &vector) |
Computes arccos of vector elements. More... | |
GVector | acosh (const GVector &vector) |
Computes acosh of vector elements. More... | |
GVector | asin (const GVector &vector) |
Computes arcsin of vector elements. More... | |
GVector | asinh (const GVector &vector) |
Computes asinh of vector elements. More... | |
GVector | atan (const GVector &vector) |
Computes arctan of vector elements. More... | |
GVector | atanh (const GVector &vector) |
Computes atanh of vector elements. More... | |
GVector | cos (const GVector &vector) |
Computes cosine of vector elements. More... | |
GVector | cosh (const GVector &vector) |
Computes cosh of vector elements. More... | |
GVector | exp (const GVector &vector) |
Computes exponential of vector elements. More... | |
GVector | abs (const GVector &vector) |
Computes absolute of vector elements. More... | |
GVector | log (const GVector &vector) |
Computes natural logarithm of vector elements. More... | |
GVector | log10 (const GVector &vector) |
Computes base10 logarithm of vector elements. More... | |
GVector | sin (const GVector &vector) |
Computes sine of vector elements. More... | |
GVector | sinh (const GVector &vector) |
Computes sinh of vector elements. More... | |
GVector | sqrt (const GVector &vector) |
Computes square root of vector elements. More... | |
GVector | tan (const GVector &vector) |
Computes tangens of vector elements. More... | |
GVector | tanh (const GVector &vector) |
Computes tanh of vector elements. More... | |
GVector | pow (const GVector &vector, const double &power) |
Computes tanh of vector elements. More... | |
Vector class.
This class implement a double precision floating point vector class that is intended to be used for numerical computation (it is not meant to replace the std::vector template class).
Definition at line 46 of file GVector.hpp.
GVector::GVector | ( | void | ) |
Void vector constructor.
Definition at line 54 of file GVector.cpp.
References init_members().
Referenced by clone().
|
explicit |
Vector constructor.
[in] | num | Number of elements in vector [>=0]. |
GException::invalid_argument | Number of elements is negative. |
Initialises a vector with num
elements. All vector elements will be set to 0.
Definition at line 75 of file GVector.cpp.
References alloc_members(), G_CONSTRUCTOR, init_members(), m_num, and gammalib::str().
|
explicit |
Single element vector constructor.
[in] | a | Vector element. |
Initialises a vector with a single element.
Definition at line 109 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
|
explicit |
Two elements vector constructor.
[in] | a | First vector element. |
[in] | b | Second vector element. |
Initialises a vector with two elements.
Definition at line 136 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
|
explicit |
Three elements vector constructor.
[in] | a | First vector element. |
[in] | b | Second vector element. |
[in] | c | Third vector element. |
Initialises a vector with three elements.
Definition at line 165 of file GVector.cpp.
References alloc_members(), init_members(), m_data, and m_num.
GVector::GVector | ( | const GVector & | vector | ) |
Copy constructor.
[in] | vector | Vector. |
Definition at line 190 of file GVector.cpp.
References copy_members(), and init_members().
|
virtual |
|
private |
double & GVector::at | ( | const int & | index | ) |
Vector element access with range checking.
[in] | index | Element index [0,...,size()[. |
GException::out_of_range | Element index is out of range. |
Definition at line 522 of file GVector.cpp.
const double & GVector::at | ( | const int & | index | ) | const |
Vector element access with range checking (const variant)
[in] | index | Element index [0,...,size()[. |
GException::out_of_range | Element index is out of range. |
Definition at line 542 of file GVector.cpp.
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 136 of file GVector.hpp.
|
virtual |
Clear vector.
Implements GBase.
Definition at line 489 of file GVector.cpp.
References free_members(), and init_members().
Referenced by GCOMBvc::init_members(), and GIntegrals::init_members().
|
virtual |
Clone vector.
Implements GBase.
Definition at line 507 of file GVector.cpp.
References GVector().
|
private |
Copy class members.
[in] | vector | Vector from which members should be copied. |
Definition at line 735 of file GVector.cpp.
Referenced by GVector(), and operator=().
int GVector::first_nonzero | ( | void | ) | const |
Return the index of the first non-zero element in a vector.
Returns the index of the first non-zero element. If all elements are zero the method will return -1.
Definition at line 583 of file GVector.cpp.
|
private |
Delete class members.
Definition at line 761 of file GVector.cpp.
References m_data.
Referenced by clear(), operator=(), and ~GVector().
|
private |
Initialise class members.
Definition at line 696 of file GVector.cpp.
Referenced by clear(), GVector(), and operator=().
int GVector::last_nonzero | ( | void | ) | const |
Return the index of the last non-zero element in a vector.
Returns the index of the last non-zero element. If all elements are zero the method will return -1.
Definition at line 609 of file GVector.cpp.
int GVector::non_zeros | ( | void | ) | const |
Returns number of non-zero elements in vector.
Definition at line 559 of file GVector.cpp.
Referenced by GMatrixSparse::add_to_column(), and GResponseVectorCache::set().
bool GVector::operator!= | ( | const GVector & | vector | ) | const |
Non-equality operator.
[in] | vector | Vector. |
Definition at line 284 of file GVector.cpp.
References operator==().
GVector & GVector::operator*= | ( | const double & | scalar | ) |
Scalar unary multiplication operator.
[in] | scalar | Scalar. |
Multiply all vector elements by scalar.
Definition at line 426 of file GVector.cpp.
Unary addition operator.
[in] | vector | Vector. |
GException::invalid_argument | Vectors have not the same size. |
Adds vector.
Definition at line 305 of file GVector.cpp.
References G_OP_ADD, m_data, m_num, and gammalib::str().
GVector & GVector::operator+= | ( | const double & | scalar | ) |
Scalar unary addition operator.
[in] | scalar | Scalar. |
Adds scalar to all vector elements.
Definition at line 386 of file GVector.cpp.
GVector GVector::operator- | ( | void | ) | const |
Unary minus operator.
Negate all vector elements.
Definition at line 465 of file GVector.cpp.
Unary subtraction operator.
[in] | vector | Vector. |
GException::vector_mismatch | Vectors have not the same size. |
Subtracts vector.
Definition at line 337 of file GVector.cpp.
References G_OP_SUB, m_data, m_num, and gammalib::str().
GVector & GVector::operator-= | ( | const double & | scalar | ) |
Scalar unary subtraction operator.
[in] | scalar | Scalar. |
Subtract scalar to all vector elements.
Definition at line 406 of file GVector.cpp.
GVector & GVector::operator/= | ( | const double & | scalar | ) |
Scalar unary division operator.
[in] | scalar | Scalar. |
Divide all vector elements by scalar.
Definition at line 446 of file GVector.cpp.
Assignment operator.
[in] | vector | Vector. |
Definition at line 228 of file GVector.cpp.
References copy_members(), free_members(), and init_members().
GVector & GVector::operator= | ( | const double & | scalar | ) |
Scalar assignment operator.
[in] | scalar | Scalar. |
Subtracts vector.
Definition at line 366 of file GVector.cpp.
bool GVector::operator== | ( | const GVector & | vector | ) | const |
Equality operator.
[in] | vector | Vector. |
Returns true if vectors are identical. Vectors are considered identical if they have the same size and if all their elements are identical.
Definition at line 258 of file GVector.cpp.
Referenced by operator!=().
|
inline |
Vector element access operator.
[in] | index | Element index [0,...,size()-1] |
Definition at line 149 of file GVector.hpp.
References m_data.
|
inline |
Vector element access operator (const variant)
[in] | index | Element index [0,...,size()-1] |
Definition at line 163 of file GVector.hpp.
References m_data.
Print vector information.
[in] | chatter | Chattiness. |
Implements GBase.
Definition at line 661 of file GVector.cpp.
References m_num, SILENT, and gammalib::str().
Referenced by GIntegrals::print(), GIntegrals::romberg(), and GIntegrals::trapzd().
|
inline |
Return size of vector.
Returns the number of elements in the vector.
Definition at line 178 of file GVector.hpp.
References m_num.
Referenced by GMatrixSymmetric::add_to_column(), GMatrix::add_to_column(), GMatrixSparse::add_to_column(), GMatrixSymmetric::add_to_row(), GMatrix::add_to_row(), at(), GRan::cdf(), GMatrixSymmetric::cholesky_solver(), GMatrixSparse::cholesky_solver(), GMatrixSymmetric::column(), GMatrix::column(), GMatrixSparse::column(), GResponseVectorCache::contains(), GMatrixSparse::insert_row(), GObservation::likelihood_gaussian_binned(), GObservation::likelihood_poisson_binned(), GObservation::likelihood_poisson_unbinned(), GObservation::model(), GNodeArray::nodes(), GObservation::npred(), GMatrixSymmetric::operator*(), GMatrix::operator*(), GMatrixSparse::operator*(), GIntegrals::polint(), GMatrix::row(), GResponseVectorCache::set(), com_radial_kerns_rho::size(), com_radial_kerns_omega::size(), com_elliptical_kerns_rho::size(), com_elliptical_kerns_omega::size(), GMatrixSparse::solve(), GMatrixSparse::stack_push_column(), and GIntegrals::trapzd().
GVector GVector::slice | ( | const int & | start, |
const int & | stop | ||
) | const |
Vector slice operator.
Definition at line 634 of file GVector.cpp.
References m_data.
Computes absolute of vector elements.
[in] | vector | Vector. |
Definition at line 1253 of file GVector.cpp.
Computes arccos of vector elements.
[in] | vector | Vector. |
Definition at line 1064 of file GVector.cpp.
Computes acosh of vector elements.
[in] | vector | Vector. |
Definition at line 1085 of file GVector.cpp.
Computes angle between vectors.
[in] | a | Vector. |
[in] | b | Vector. |
a
and b
in radians.GException::invalid_argument | Mismatch between vector size. |
Returns the angle \(\alpha\) between vector a
and b
in radians. The computation is done using
\[ \alpha = \arccos{\frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|}} \]
Definition at line 974 of file GVector.cpp.
Computes arcsin of vector elements.
[in] | vector | Vector. |
Definition at line 1106 of file GVector.cpp.
Computes asinh of vector elements.
[in] | vector | Vector. |
Definition at line 1127 of file GVector.cpp.
Computes arctan of vector elements.
[in] | vector | Vector. |
Definition at line 1148 of file GVector.cpp.
Computes atanh of vector elements.
[in] | vector | Vector. |
Definition at line 1169 of file GVector.cpp.
Computes cosine of vector elements.
[in] | vector | Vector. |
Definition at line 1190 of file GVector.cpp.
Computes cosh of vector elements.
[in] | vector | Vector. |
Definition at line 1211 of file GVector.cpp.
Vector cross product.
[in] | a | Vector. |
[in] | b | Vector. |
GException::invalid_argument | Mismatch between vector size or vector not of size 3. |
Computes the cross product between two 3-element vectors (note that the cross product is only defined for 3-element vectors).
Definition at line 793 of file GVector.cpp.
Computes exponential of vector elements.
[in] | vector | Vector. |
Definition at line 1232 of file GVector.cpp.
Computes vector inverse permutation.
[in] | vector | Vector. |
[in] | p | Permutation array. |
Definition at line 1038 of file GVector.cpp.
Computes natural logarithm of vector elements.
[in] | vector | Vector. |
Definition at line 1274 of file GVector.cpp.
Computes base10 logarithm of vector elements.
[in] | vector | Vector. |
Definition at line 1295 of file GVector.cpp.
|
friend |
Computes maximum vector element.
[in] | vector | Vector. |
Definition at line 915 of file GVector.cpp.
|
friend |
Computes minimum vector element.
[in] | vector | Vector. |
Definition at line 886 of file GVector.cpp.
|
friend |
Computes vector norm.
[in] | vector | Vector. |
Definition at line 864 of file GVector.cpp.
Vector scalar product.
[in] | a | Vector. |
[in] | b | Vector. |
a
and b
.GException::invalid_argument | Mismatch between vector size. |
Returns the scalar product between vector a
and b
.
Definition at line 836 of file GVector.cpp.
Computes vector permutation.
[in] | vector | Vector. |
[in] | p | Permutation array. |
Definition at line 1011 of file GVector.cpp.
Computes tanh of vector elements.
[in] | vector | Vector. |
[in] | power | Power. |
Definition at line 1422 of file GVector.cpp.
Computes sine of vector elements.
[in] | vector | Vector. |
Definition at line 1316 of file GVector.cpp.
Computes sinh of vector elements.
[in] | vector | Vector. |
Definition at line 1337 of file GVector.cpp.
Computes square root of vector elements.
[in] | vector | Vector. |
Definition at line 1358 of file GVector.cpp.
|
friend |
Computes vector sum.
[in] | vector | Vector. |
Definition at line 944 of file GVector.cpp.
Computes tangens of vector elements.
[in] | vector | Vector. |
Definition at line 1379 of file GVector.cpp.
Computes tanh of vector elements.
[in] | vector | Vector. |
Definition at line 1400 of file GVector.cpp.
|
private |
Vector array.
Definition at line 126 of file GVector.hpp.
Referenced by abs(), acos(), acosh(), alloc_members(), asin(), asinh(), at(), atan(), atanh(), copy_members(), cos(), cosh(), cross(), exp(), first_nonzero(), free_members(), GVector(), init_members(), iperm(), last_nonzero(), log(), log10(), max(), min(), non_zeros(), norm(), operator*(), operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), operator==(), operator[](), perm(), pow(), sin(), sinh(), slice(), sqrt(), sum(), tan(), and tanh().
|
private |
Number of elements in vector.
Definition at line 125 of file GVector.hpp.
Referenced by abs(), acos(), acosh(), alloc_members(), angle(), asin(), asinh(), atan(), atanh(), copy_members(), cos(), cosh(), cross(), exp(), first_nonzero(), GVector(), init_members(), iperm(), last_nonzero(), log(), log10(), max(), min(), non_zeros(), norm(), operator*(), operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator=(), operator==(), perm(), pow(), print(), sin(), sinh(), size(), sqrt(), sum(), tan(), and tanh().