37 #define G_OP_ADD "GNdarray::operator+=(GNdarray&)"
38 #define G_OP_SUB "GNdarray::operator-=(GNdarray&)"
39 #define G_OP_MUL "GNdarray::operator*=(GNdarray&)"
40 #define G_OP_DIV "GNdarray::operator/=(GNdarray&)"
41 #define G_SHAPE "GNdarray::shape(std::vector<int>&)"
42 #define G_AT1 "GNdarray::at(int&)"
43 #define G_AT2 "GNdarray::at(int&, int&)"
44 #define G_AT3 "GNdarray::at(int&, int&, int&)"
45 #define G_ATN "GNdarray::at(std::vector<int>&)"
140 int size = nx * ny * nz;
179 for (
int i = 1; i < n.size(); ++i) {
188 for (
int i = 0; i < n.size(); ++i) {
249 if (
this != &array) {
283 for (
int i = 0; i <
m_data.size(); ++i) {
328 for (
int i = 0; i <
m_data.size(); ++i) {
351 for (
int i = 0; i <
m_data.size(); ++i) {
374 for (
int i = 0; i <
m_data.size(); ++i) {
377 if (array.
m_data[i] != 0.0){
407 for (
int i = 0; i <
m_data.size(); ++i) {
427 for (
int i = 0; i <
m_data.size(); ++i) {
447 for (
int i = 0; i <
m_data.size(); ++i) {
467 for (
int i = 0; i <
m_data.size(); ++i) {
487 for (
int i = 0; i <
m_data.size(); ++i) {
509 for (
int i = 0; i <
m_data.size(); ++i) {
567 if (shape.size() > 0) {
569 for (
int i = 0; i < shape.size(); ++i) {
570 nelements *= shape[i];
576 if (nelements !=
size()) {
577 std::string msg =
"Number of elements "+
gammalib::str(nelements)+
578 " in specified shape is not identical to the "
608 std::string msg =
"Invalid access of "+
610 "with 1-dimensional access operator.";
615 if (ix < 0 || ix >=
m_shape[0]) {
641 std::string msg =
"Invalid access of "+
643 "with 2-dimensional access operator.";
648 if (ix < 0 || ix >=
m_shape[0]) {
652 if (iy < 0 || iy >=
m_shape[1]) {
658 return (*
this)(ix,iy);
676 const double&
GNdarray::at(
const int& ix,
const int& iy,
const int& iz)
const
680 std::string msg =
"Invalid access of "+
682 "with 3-dimensional access operator.";
687 if (ix < 0 || ix >=
m_shape[0]) {
691 if (iy < 0 || iy >=
m_shape[1]) {
695 if (iz < 0 || iz >=
m_shape[2]) {
701 return (*
this)(ix,iy,iz);
720 if (
m_shape.size() != i.size()) {
721 std::string msg =
"Invalid access of "+
730 for (
int k = 0; k <
m_shape.size(); ++k) {
731 if (i[k] < 0 || i[k] >=
m_shape[k]) {
760 for (
int k = 0; k <
m_shape.size(); ++k) {
786 std::vector<int> i(dim, 0);
789 for (
int k = dim-1; k >= 0; --k) {
792 inx -= strides * i[k];
809 std::string result =
"(";
815 for (
int i = 0; i <
m_data.size(); ++i) {
897 for (
int i = 0; i <
m_shape.size(); ++i) {
923 std::string msg =
"Incompatible array dimensions (";
924 for (
int i = 0; i <
m_shape.size(); ++i) {
931 for (
int i = 0; i < array.
m_shape.size(); ++i) {
967 if (array.
m_data.size() > 0) {
971 for (
int i = 1; i < array.
m_data.size(); ++i) {
972 if (array.
m_data[i] < result) {
996 if (array.
m_data.size() > 0) {
1000 for (
int i = 1; i < array.
m_data.size(); ++i) {
1001 if (array.
m_data[i] > result) {
1002 result = array.
m_data[i];
1022 double result = 0.0;
1023 for (
int i = 0; i < array.
m_data.size(); ++i) {
1024 result += array.
m_data[i];
1044 for (
int i = 0; i < array.
m_data.size(); ++i) {
1065 for (
int i = 0; i < array.
m_data.size(); ++i) {
1086 for (
int i = 0; i < array.
m_data.size(); ++i) {
1107 for (
int i = 0; i < array.
m_data.size(); ++i) {
1128 for (
int i = 0; i < array.
m_data.size(); ++i) {
1149 for (
int i = 0; i < array.
m_data.size(); ++i) {
1170 for (
int i = 0; i < array.
m_data.size(); ++i) {
1191 for (
int i = 0; i < array.
m_data.size(); ++i) {
1212 for (
int i = 0; i < array.
m_data.size(); ++i) {
1233 for (
int i = 0; i < array.
m_data.size(); ++i) {
1254 for (
int i = 0; i < array.
m_data.size(); ++i) {
1275 for (
int i = 0; i < array.
m_data.size(); ++i) {
1278 double content = array.
m_data[i];
1284 if (content < 0.0) {
1287 else if (content > 0.0) {
1316 for (
int i = 0; i < array.
m_data.size(); ++i) {
1337 for (
int i = 0; i < array.
m_data.size(); ++i) {
1358 for (
int i = 0; i < array.
m_data.size(); ++i) {
1379 for (
int i = 0; i < array.
m_data.size(); ++i) {
1400 for (
int i = 0; i < array.
m_data.size(); ++i) {
1421 for (
int i = 0; i < array.
m_data.size(); ++i) {
1443 for (
int i = 0; i < array.
m_data.size(); ++i) {
GVector acosh(const GVector &vector)
Computes acosh of vector elements.
const std::vector< int > & strides(void) const
Return strides of array.
GVector sinh(const GVector &vector)
Computes sinh of vector elements.
bool operator!=(const GNdarray &array) const
Non-equality operator.
void clear(void)
Clear array.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
void free_members(void)
Delete class members.
GNdarray * clone(void) const
Clone array.
double sum(const GVector &vector)
Computes vector sum.
double acos(const double &arg)
Computes acos by avoiding NaN due to rounding errors.
const std::vector< int > & shape(void) const
Return shape of array.
double min(const GVector &vector)
Computes minimum vector element.
std::vector< int > m_shape
Array dimensions.
void copy_members(const GNdarray &array)
Copy class members.
double & at(const int &ix)
1-dimensional array element access with range checking
GNdarray & operator-=(const GNdarray &array)
Unary subtraction operator.
std::vector< double > m_data
Array data.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
GNdarray & operator/=(const GNdarray &array)
Unary division operator.
GNdarray & operator=(const GNdarray &array)
Assignment operator.
void require_same_shape(const std::string &method, const GNdarray &array) const
Throw exception if array shapes differ.
GVector tan(const GVector &vector)
Computes tangens of vector elements.
N-dimensional array class interface definition.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
GNdarray sign(const GNdarray &array)
Computes sign of array elements.
std::string print(const GChatter &chatter=NORMAL) const
Print array information.
bool operator==(const GNdarray &array) const
Equality operator.
int size(void) const
Return number of elements in array.
GNdarray(void)
Void constructor.
N-dimensional array class.
double max(const GVector &vector)
Computes maximum vector element.
GVector asin(const GVector &vector)
Computes arcsin of vector elements.
GNdarray & operator*=(const GNdarray &array)
Unary multiplication operator.
GVector tanh(const GVector &vector)
Computes tanh of vector elements.
GVector atanh(const GVector &vector)
Computes atanh of vector elements.
GVector cosh(const GVector &vector)
Computes cosh of vector elements.
GVector asinh(const GVector &vector)
Computes asinh of vector elements.
int index(const std::vector< int > &i) const
Compute array element index.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
bool has_same_shape(const GNdarray &array) const
Check if array has the same shape.
GVector sin(const GVector &vector)
Computes sine of vector elements.
Exception handler interface definition.
void init_members(void)
Initialise class members.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
GNdarray & operator+=(const GNdarray &array)
Unary addition operator.
virtual ~GNdarray(void)
Destructor.
int dim(void) const
Return dimension of array.
GVector atan(const GVector &vector)
Computes arctan of vector elements.
GNdarray operator-(void) const
Unary minus operator.
std::vector< int > m_strides
Steps in each dimension when traversing array.
GVector log10(const GVector &vector)
Computes base10 logarithm of vector elements.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.