GammaLib
2.1.0.dev
|
N-dimensional array class. More...
#include <GNdarray.hpp>
Public Member Functions | |
GNdarray (void) | |
Void constructor. More... | |
GNdarray (const int &nx) | |
1-dimensional constructor More... | |
GNdarray (const int &nx, const int &ny) | |
2-dimensional constructor More... | |
GNdarray (const int &nx, const int &ny, const int &nz) | |
3-dimensional constructor More... | |
GNdarray (const std::vector< int > &n) | |
n-dimensional constructor More... | |
GNdarray (const GNdarray &array) | |
Copy constructor. More... | |
virtual | ~GNdarray (void) |
Destructor. More... | |
double & | operator() (const int &ix) |
1-dimensional array element access operator More... | |
double & | operator() (const int &ix, const int &iy) |
2-dimensional array element access operator More... | |
double & | operator() (const int &ix, const int &iy, const int &iz) |
3-dimensional array element access operator More... | |
double & | operator() (const std::vector< int > &i) |
n-dimensional array element access operator More... | |
const double & | operator() (const int &ix) const |
1-dimensional array element access operator (const variant) More... | |
const double & | operator() (const int &ix, const int &iy) const |
2-dimensional array element access operator (const variant) More... | |
const double & | operator() (const int &ix, const int &iy, const int &iz) const |
3-dimensional array element access operator (const variant) More... | |
const double & | operator() (const std::vector< int > &i) const |
n-dimensional array element access operator (const variant) More... | |
GNdarray & | operator= (const GNdarray &array) |
Assignment operator. More... | |
bool | operator== (const GNdarray &array) const |
Equality operator. More... | |
bool | operator!= (const GNdarray &array) const |
Non-equality operator. More... | |
GNdarray & | operator+= (const GNdarray &array) |
Unary addition operator. More... | |
GNdarray & | operator-= (const GNdarray &array) |
Unary subtraction operator. More... | |
GNdarray & | operator*= (const GNdarray &array) |
Unary multiplication operator. More... | |
GNdarray & | operator/= (const GNdarray &array) |
Unary division operator. More... | |
GNdarray & | operator+= (const double &value) |
Unary value addition operator. More... | |
GNdarray & | operator-= (const double &value) |
Unary value subtraction operator. More... | |
GNdarray & | operator*= (const double &value) |
Unary multiplication operator. More... | |
GNdarray & | operator/= (const double &value) |
Unary division operator. More... | |
GNdarray | operator- (void) const |
Unary minus operator. More... | |
void | clear (void) |
Clear array. More... | |
GNdarray * | clone (void) const |
Clone array. More... | |
std::string | classname (void) const |
Return class name. More... | |
int | dim (void) const |
Return dimension of array. More... | |
int | size (void) const |
Return number of elements in array. More... | |
const std::vector< int > & | shape (void) const |
Return shape of array. More... | |
const std::vector< int > & | strides (void) const |
Return strides of array. More... | |
void | shape (const std::vector< int > &shape) |
Set shape of array. More... | |
int | index (const std::vector< int > &i) const |
Compute array element index. More... | |
std::vector< int > | index (const int &index) const |
Compute index vector. More... | |
double & | at (const int &ix) |
1-dimensional array element access with range checking More... | |
double & | at (const int &ix, const int &iy) |
2-dimensional array element access with range checking More... | |
double & | at (const int &ix, const int &iy, const int &iz) |
3-dimensional array element access with range checking More... | |
double & | at (const std::vector< int > &i) |
n-dimensional array element access with range checking More... | |
const double & | at (const int &ix) const |
1-dimensional array element access with range checking (const version) More... | |
const double & | at (const int &ix, const int &iy) const |
2-dimensional array element access with range checking (const version) More... | |
const double & | at (const int &ix, const int &iy, const int &iz) const |
3-dimensional array element access with range checking (const version) More... | |
const double & | at (const std::vector< int > &i) const |
n-dimensional array element access with range checking (const version) More... | |
const double * | data (void) const |
Data access method (const version) More... | |
double * | data (void) |
Data access method. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print array information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GNdarray &array) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
bool | has_same_shape (const GNdarray &array) const |
Check if array has the same shape. More... | |
void | require_same_shape (const std::string &method, const GNdarray &array) const |
Throw exception if array shapes differ. More... | |
Protected Attributes | |
std::vector< int > | m_shape |
Array dimensions. More... | |
std::vector< int > | m_strides |
Steps in each dimension when traversing array. More... | |
std::vector< double > | m_data |
Array data. More... | |
Friends | |
double | min (const GNdarray &array) |
Computes minimum array element. More... | |
double | max (const GNdarray &array) |
Computes maximum array element. More... | |
double | sum (const GNdarray &array) |
Computes array sum. More... | |
GNdarray | acos (const GNdarray &array) |
Computes arccos of array elements. More... | |
GNdarray | acosh (const GNdarray &array) |
Computes acosh of array elements. More... | |
GNdarray | asin (const GNdarray &array) |
Computes arcsin of array elements. More... | |
GNdarray | asinh (const GNdarray &array) |
Computes asinh of array elements. More... | |
GNdarray | atan (const GNdarray &array) |
Computes arctan of array elements. More... | |
GNdarray | atanh (const GNdarray &array) |
Computes atanh of array elements. More... | |
GNdarray | cos (const GNdarray &array) |
Computes cosine of array elements. More... | |
GNdarray | cosh (const GNdarray &array) |
Computes cosh of array elements. More... | |
GNdarray | exp (const GNdarray &array) |
Computes exponential of array elements. More... | |
GNdarray | abs (const GNdarray &array) |
Computes absolute of array elements. More... | |
GNdarray | log (const GNdarray &array) |
Computes natural logarithm of array elements. More... | |
GNdarray | log10 (const GNdarray &array) |
Computes base10 logarithm of array elements. More... | |
GNdarray | sign (const GNdarray &array) |
Computes sign of array elements. More... | |
GNdarray | sin (const GNdarray &array) |
Computes sine of array elements. More... | |
GNdarray | sinh (const GNdarray &array) |
Computes sinh of array elements. More... | |
GNdarray | sqrt (const GNdarray &array) |
Computes square root of array elements. More... | |
GNdarray | tan (const GNdarray &array) |
Computes tangens of array elements. More... | |
GNdarray | tanh (const GNdarray &array) |
Computes tanh of array elements. More... | |
GNdarray | pow (const GNdarray &array, const double &power) |
Computes tanh of array elements. More... | |
N-dimensional array class.
This class implements a n-dimensional double precision floating point array.
Definition at line 44 of file GNdarray.hpp.
GNdarray::GNdarray | ( | void | ) |
Void constructor.
Definition at line 57 of file GNdarray.cpp.
References init_members().
Referenced by clone().
|
explicit |
1-dimensional constructor
[in] | nx | Array dimension. |
Constructs a 1-dimensional array.
Definition at line 74 of file GNdarray.cpp.
References init_members(), m_data, m_shape, and m_strides.
GNdarray::GNdarray | ( | const int & | nx, |
const int & | ny | ||
) |
2-dimensional constructor
[in] | nx | Array's first dimension. |
[in] | ny | Array's second dimension. |
Constructs a 2-dimensional array.
Definition at line 101 of file GNdarray.cpp.
References init_members(), m_data, m_shape, m_strides, and size().
GNdarray::GNdarray | ( | const int & | nx, |
const int & | ny, | ||
const int & | nz | ||
) |
3-dimensional constructor
[in] | nx | Array's first dimension. |
[in] | ny | Array's second dimension. |
[in] | nz | Array's third dimension. |
Constructs a 3-dimensional array.
Definition at line 134 of file GNdarray.cpp.
References init_members(), m_data, m_shape, m_strides, and size().
GNdarray::GNdarray | ( | const std::vector< int > & | n | ) |
n-dimensional constructor
[in] | n | Array dimensions. |
Constructs a n-dimensional array. If the array dimension vector n
is empty an empty n-dimensional array is constructed (similar to the void constructor).
Definition at line 169 of file GNdarray.cpp.
References init_members(), m_data, m_shape, m_strides, and size().
GNdarray::GNdarray | ( | const GNdarray & | array | ) |
Copy constructor.
[in] | array | Array. |
Definition at line 208 of file GNdarray.cpp.
References copy_members(), and init_members().
|
virtual |
|
inline |
1-dimensional array element access with range checking
[in] | ix | Element index [0,...,shape(0)-1]. |
Definition at line 335 of file GNdarray.hpp.
References at().
Referenced by at().
|
inline |
2-dimensional array element access with range checking
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
Definition at line 349 of file GNdarray.hpp.
References at().
|
inline |
3-dimensional array element access with range checking
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
[in] | iz | Index in third dimension [0,...,shape(2)-1]. |
Definition at line 364 of file GNdarray.hpp.
References at().
|
inline |
n-dimensional array element access with range checking
[in] | i | Index vector. |
Definition at line 377 of file GNdarray.hpp.
References at().
const double & GNdarray::at | ( | const int & | ix | ) | const |
1-dimensional array element access with range checking (const version)
[in] | ix | Element index [0,...,shape(0)-1]. |
GException::invalid_value | Array is not 1-dimensional. |
GException::out_of_range | Element index is out of range. |
Definition at line 604 of file GNdarray.cpp.
References G_AT1, m_shape, and gammalib::str().
const double & GNdarray::at | ( | const int & | ix, |
const int & | iy | ||
) | const |
2-dimensional array element access with range checking (const version)
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
GException::invalid_value | Array is not 2-dimensional. |
GException::out_of_range | Element index is out of range. |
Definition at line 637 of file GNdarray.cpp.
References G_AT2, m_shape, and gammalib::str().
const double & GNdarray::at | ( | const int & | ix, |
const int & | iy, | ||
const int & | iz | ||
) | const |
3-dimensional array element access with range checking (const version)
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
[in] | iz | Index in third dimension [0,...,shape(2)-1]. |
GException::invalid_value | Array is not 3-dimensional. |
GException::out_of_range | Element index is out of range. |
Definition at line 676 of file GNdarray.cpp.
References G_AT3, m_shape, and gammalib::str().
const double & GNdarray::at | ( | const std::vector< int > & | i | ) | const |
n-dimensional array element access with range checking (const version)
[in] | i | Index vector. |
GException::invalid_value | Array is not of correct dimension. |
GException::out_of_range | Element index is out of range. |
Definition at line 717 of file GNdarray.cpp.
References G_ATN, m_shape, and gammalib::str().
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 148 of file GNdarray.hpp.
|
virtual |
Clear array.
Implements GBase.
Definition at line 527 of file GNdarray.cpp.
References free_members(), and init_members().
Referenced by GModelSpectralTable::init_members(), GCOMDris::init_members(), and GSkyMap::init_members().
|
virtual |
Clone array.
Implements GBase.
Definition at line 545 of file GNdarray.cpp.
References GNdarray().
|
protected |
Copy class members.
[in] | array | Array. |
Definition at line 861 of file GNdarray.cpp.
References m_data, m_shape, and m_strides.
Referenced by GNdarray(), and operator=().
|
inline |
Data access method (const version)
Definition at line 389 of file GNdarray.hpp.
References m_data.
Referenced by GSkyMap::convolve(), GSkyMap::create_healpix_hdu(), GSkyMap::create_wcs_hdu(), GSkyMap::extract(), GSkyMap::operator()(), GSkyMap::pixels(), GSkyMap::read_healpix(), and GSkyMap::read_wcs().
|
inline |
Data access method.
Definition at line 401 of file GNdarray.hpp.
References m_data.
|
inline |
Return dimension of array.
Returns the dimension of the array.
Definition at line 280 of file GNdarray.hpp.
References m_shape.
Referenced by GFft::backward(), GModelSpectralTable::create_spec_table(), GFft::forward(), GModelSpectralTable::GModelSpectralTable(), index(), and GModelSpectralTable::print().
|
protected |
Delete class members.
Definition at line 876 of file GNdarray.cpp.
Referenced by clear(), operator=(), and ~GNdarray().
|
protected |
Check if array has the same shape.
[in] | array | Array. |
Definition at line 889 of file GNdarray.cpp.
References m_shape.
Referenced by operator==(), and require_same_shape().
int GNdarray::index | ( | const std::vector< int > & | i | ) | const |
Compute array element index.
[in] | i | Index vector. |
Computes the array element index from an index vector. The method assumes that the index vector has the same dimension as the array. If this condition is not guaranteed, the condition needs to be checked before calling the method.
Definition at line 754 of file GNdarray.cpp.
References m_shape, and m_strides.
Referenced by index(), operator()(), and GModelSpectralTable::scale_energy().
std::vector< int > GNdarray::index | ( | const int & | index | ) | const |
|
protected |
Initialise class members.
Definition at line 841 of file GNdarray.cpp.
References m_data, m_shape, and m_strides.
Referenced by clear(), GNdarray(), and operator=().
bool GNdarray::operator!= | ( | const GNdarray & | array | ) | const |
Non-equality operator.
[in] | array | Array. |
Returns true if the arrays have different shape or content.
Definition at line 304 of file GNdarray.cpp.
References operator==().
|
inline |
1-dimensional array element access operator
[in] | ix | Element index [0,...,shape(0)-1]. |
Definition at line 161 of file GNdarray.hpp.
References m_data.
|
inline |
2-dimensional array element access operator
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
Definition at line 176 of file GNdarray.hpp.
|
inline |
3-dimensional array element access operator
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
[in] | iz | Index in third dimension [0,...,shape(2)-1]. |
Definition at line 192 of file GNdarray.hpp.
|
inline |
n-dimensional array element access operator
[in] | i | Index vector. |
Definition at line 206 of file GNdarray.hpp.
|
inline |
1-dimensional array element access operator (const variant)
[in] | ix | Element index [0,...,shape(0)-1]. |
Definition at line 220 of file GNdarray.hpp.
References m_data.
|
inline |
2-dimensional array element access operator (const variant)
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
Definition at line 235 of file GNdarray.hpp.
|
inline |
3-dimensional array element access operator (const variant)
[in] | ix | Index in first dimension [0,...,shape(0)-1]. |
[in] | iy | Index in second dimension [0,...,shape(1)-1]. |
[in] | iz | Index in third dimension [0,...,shape(2)-1]. |
Definition at line 251 of file GNdarray.hpp.
|
inline |
n-dimensional array element access operator (const variant)
[in] | i | Index vector. |
Definition at line 265 of file GNdarray.hpp.
Unary multiplication operator.
[in] | array | Array. |
Multiply an array by the current array.
Definition at line 345 of file GNdarray.cpp.
References G_OP_MUL, m_data, and require_same_shape().
GNdarray & GNdarray::operator*= | ( | const double & | value | ) |
Unary multiplication operator.
[in] | value | Value. |
Multiply all array elements by a value.
Definition at line 464 of file GNdarray.cpp.
References m_data.
Unary addition operator.
[in] | array | Array. |
Adds an array to the current array.
Definition at line 322 of file GNdarray.cpp.
References G_OP_ADD, m_data, and require_same_shape().
GNdarray & GNdarray::operator+= | ( | const double & | value | ) |
Unary value addition operator.
[in] | value | Value. |
Adds a value to all array elements.
Definition at line 424 of file GNdarray.cpp.
References m_data.
GNdarray GNdarray::operator- | ( | void | ) | const |
Unary minus operator.
Negate all array elements.
Definition at line 503 of file GNdarray.cpp.
References m_data.
Unary subtraction operator.
[in] | array | Array. |
Subtracts an array from the current array.
Definition at line 401 of file GNdarray.cpp.
References G_OP_SUB, m_data, and require_same_shape().
GNdarray & GNdarray::operator-= | ( | const double & | value | ) |
Unary value subtraction operator.
[in] | value | Value. |
Subtracts a value from all array elements.
Definition at line 444 of file GNdarray.cpp.
References m_data.
Unary division operator.
[in] | array | Array. |
Divide current array by array.
Definition at line 368 of file GNdarray.cpp.
References G_OP_DIV, m_data, and require_same_shape().
GNdarray & GNdarray::operator/= | ( | const double & | value | ) |
Unary division operator.
[in] | value | Value. |
Divide all array elements by a value.
Definition at line 484 of file GNdarray.cpp.
References m_data.
Assignment operator.
[in] | array | Array. |
Definition at line 246 of file GNdarray.cpp.
References copy_members(), free_members(), and init_members().
bool GNdarray::operator== | ( | const GNdarray & | array | ) | const |
Equality operator.
[in] | array | Array. |
Returns true if the arrays have identical shape and content.
Definition at line 275 of file GNdarray.cpp.
References has_same_shape(), and m_data.
Referenced by operator!=().
Print array information.
[in] | chatter | Chattiness. |
Implements GBase.
Definition at line 806 of file GNdarray.cpp.
References m_data, SILENT, and gammalib::str().
|
protected |
Throw exception if array shapes differ.
[in] | method | Method that throws exception. |
[in] | array | Array. |
Definition at line 916 of file GNdarray.cpp.
References has_same_shape(), m_shape, and gammalib::str().
Referenced by operator*=(), operator+=(), operator-=(), and operator/=().
|
inline |
Return shape of array.
Returns the shape of the array.
Definition at line 308 of file GNdarray.hpp.
References m_shape.
Referenced by GModelSpectralTable::create_spec_table(), GModelSpectralTable::GModelSpectralTable(), GCOMDris::likelihood::likelihood(), GModelSpectralTable::print(), GFft::set_data(), shape(), GCOMDris::vetorate_fit(), GCOMDris::vetorate_save(), and GCOMDris::vetorate_update_activ().
void GNdarray::shape | ( | const std::vector< int > & | shape | ) |
Set shape of array.
[in] | shape | Shape vector. |
GException::invalid_argument | Invalid shape factorisation specified. |
Set the shape of the array. The shape specifies how the information is arranged in a n-dimensional array.
Definition at line 563 of file GNdarray.cpp.
References G_SHAPE, m_shape, shape(), size(), and gammalib::str().
|
inline |
Return number of elements in array.
Returns the number of elements in the array.
Definition at line 294 of file GNdarray.hpp.
References m_data.
Referenced by GNdarray(), GSkyMap::operator=(), GFft::set_data(), shape(), GCTAEdisp2D::smooth_array(), and GCTAEdisp2D::smoothed_array_value().
|
inline |
Return strides of array.
Returns the strides of the array.
Definition at line 322 of file GNdarray.hpp.
References m_strides.
Referenced by index(), and GFft::set_data().
Computes absolute of array elements.
[in] | array | Array. |
Definition at line 1227 of file GNdarray.cpp.
Computes arccos of array elements.
[in] | array | Array. |
Definition at line 1038 of file GNdarray.cpp.
Computes acosh of array elements.
[in] | array | Array. |
Definition at line 1059 of file GNdarray.cpp.
Computes arcsin of array elements.
[in] | array | Array. |
Definition at line 1080 of file GNdarray.cpp.
Computes asinh of array elements.
[in] | array | Array. |
Definition at line 1101 of file GNdarray.cpp.
Computes arctan of array elements.
[in] | array | Array. |
Definition at line 1122 of file GNdarray.cpp.
Computes atanh of array elements.
[in] | array | Array. |
Definition at line 1143 of file GNdarray.cpp.
Computes cosine of array elements.
[in] | array | Array. |
Definition at line 1164 of file GNdarray.cpp.
Computes cosh of array elements.
[in] | array | Array. |
Definition at line 1185 of file GNdarray.cpp.
Computes exponential of array elements.
[in] | array | Array. |
Definition at line 1206 of file GNdarray.cpp.
Computes natural logarithm of array elements.
[in] | array | Array. |
Definition at line 1248 of file GNdarray.cpp.
Computes base10 logarithm of array elements.
[in] | array | Array. |
Definition at line 1310 of file GNdarray.cpp.
|
friend |
Computes maximum array element.
[in] | array | Array. |
Definition at line 990 of file GNdarray.cpp.
|
friend |
Computes minimum array element.
[in] | array | Array. |
Definition at line 961 of file GNdarray.cpp.
Computes tanh of array elements.
[in] | array | Array. |
[in] | power | Power. |
Definition at line 1437 of file GNdarray.cpp.
Computes sign of array elements.
[in] | array | Array. |
Definition at line 1269 of file GNdarray.cpp.
Computes sine of array elements.
[in] | array | Array. |
Definition at line 1331 of file GNdarray.cpp.
Computes sinh of array elements.
[in] | array | Array. |
Definition at line 1352 of file GNdarray.cpp.
Computes square root of array elements.
[in] | array | Array. |
Definition at line 1373 of file GNdarray.cpp.
|
friend |
Computes array sum.
[in] | array | Array. |
Definition at line 1019 of file GNdarray.cpp.
Computes tangens of array elements.
[in] | array | Array. |
Definition at line 1394 of file GNdarray.cpp.
Computes tanh of array elements.
[in] | array | Array. |
Definition at line 1415 of file GNdarray.cpp.
|
protected |
Array data.
Definition at line 138 of file GNdarray.hpp.
Referenced by abs(), acos(), acosh(), asin(), asinh(), atan(), atanh(), copy_members(), cos(), cosh(), data(), exp(), GNdarray(), init_members(), log(), log10(), max(), min(), operator()(), operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator==(), pow(), print(), sign(), sin(), sinh(), size(), sqrt(), sum(), tan(), and tanh().
|
protected |
Array dimensions.
Definition at line 136 of file GNdarray.hpp.
Referenced by at(), copy_members(), dim(), GNdarray(), has_same_shape(), index(), init_members(), require_same_shape(), and shape().
|
protected |
Steps in each dimension when traversing array.
Definition at line 137 of file GNdarray.hpp.
Referenced by copy_members(), GNdarray(), index(), init_members(), operator()(), and strides().