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) {
778 std::string result =
"(";
784 for (
int i = 0; i <
m_data.size(); ++i) {
866 for (
int i = 0; i <
m_shape.size(); ++i) {
892 std::string msg =
"Incompatible array dimensions (";
893 for (
int i = 0; i <
m_shape.size(); ++i) {
900 for (
int i = 0; i < array.
m_shape.size(); ++i) {
936 if (array.
m_data.size() > 0) {
940 for (
int i = 1; i < array.
m_data.size(); ++i) {
941 if (array.
m_data[i] < result) {
965 if (array.
m_data.size() > 0) {
969 for (
int i = 1; i < array.
m_data.size(); ++i) {
970 if (array.
m_data[i] > result) {
992 for (
int i = 0; i < array.
m_data.size(); ++i) {
993 result += array.
m_data[i];
1013 for (
int i = 0; i < array.
m_data.size(); ++i) {
1034 for (
int i = 0; i < array.
m_data.size(); ++i) {
1055 for (
int i = 0; i < array.
m_data.size(); ++i) {
1076 for (
int i = 0; i < array.
m_data.size(); ++i) {
1097 for (
int i = 0; i < array.
m_data.size(); ++i) {
1118 for (
int i = 0; i < array.
m_data.size(); ++i) {
1139 for (
int i = 0; i < array.
m_data.size(); ++i) {
1160 for (
int i = 0; i < array.
m_data.size(); ++i) {
1181 for (
int i = 0; i < array.
m_data.size(); ++i) {
1202 for (
int i = 0; i < array.
m_data.size(); ++i) {
1223 for (
int i = 0; i < array.
m_data.size(); ++i) {
1244 for (
int i = 0; i < array.
m_data.size(); ++i) {
1247 double content = array.
m_data[i];
1253 if (content < 0.0) {
1256 else if (content > 0.0) {
1285 for (
int i = 0; i < array.
m_data.size(); ++i) {
1306 for (
int i = 0; i < array.
m_data.size(); ++i) {
1327 for (
int i = 0; i < array.
m_data.size(); ++i) {
1348 for (
int i = 0; i < array.
m_data.size(); ++i) {
1369 for (
int i = 0; i < array.
m_data.size(); ++i) {
1390 for (
int i = 0; i < array.
m_data.size(); ++i) {
1412 for (
int i = 0; i < array.
m_data.size(); ++i) {
GVector acosh(const GVector &vector)
Computes acosh of vector elements.
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.
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.