GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_linalg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_linalg.cpp - linalg exception handlers *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2012 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GException_linalg.cpp
23  * @brief Exception handlers for linear algebra module
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #include "GException.hpp"
29 #include "GTools.hpp"
30 
31 
32 /***********************************************************************//**
33  * @brief Empty object exception
34  *
35  * @param[in] origin Method throwing the exception.
36  ***************************************************************************/
37 GException::empty::empty(std::string origin)
38 {
39  // Set origin
40  m_origin = origin;
41 
42  // Set message
43  m_message = "Zero-size allocation.";
44 
45  // Return
46  return;
47 }
48 
49 
50 /***********************************************************************//**
51  * @brief Index is out of range
52  *
53  * @param[in] origin Method throwing the exception.
54  * @param[in] inx Index.
55  * @param[in] min Minimum of valid range.
56  * @param[in] max Maximum of valid range.
57  ***************************************************************************/
59  int inx,
60  int min,
61  int max)
62 {
63  // Set origin
64  m_origin = origin;
65 
66  // Set message
67  m_message = "Index " + gammalib::str(inx) + " out of range [" + gammalib::str(min) +
68  "," + gammalib::str(max) + "].";
69 
70  // Return
71  return;
72 }
73 
74 
75 /***********************************************************************//**
76  * @brief Value is out of range
77  *
78  * @param[in] origin Method throwing the exception.
79  * @param[in] value Value.
80  * @param[in] min Minimum of valid range.
81  * @param[in] max Maximum of valid range.
82  ***************************************************************************/
84  double value,
85  double min,
86  double max)
87 {
88  // Set origin
89  m_origin = origin;
90 
91  // Set message
92  m_message = "Value " + gammalib::str(value) + " out of range [" + gammalib::str(min) +
93  "," + gammalib::str(max) + "].";
94 
95  // Return
96  return;
97 }
98 
99 
100 /***********************************************************************//**
101  * @brief Vector index is out of range
102  *
103  * @param[in] origin Method throwing the exception.
104  * @param[in] inx Index.
105  * @param[in] elements Number of vector elements.
106  ***************************************************************************/
108  int inx,
109  int elements)
110 {
111  // Set origin
112  m_origin = origin;
113 
114  // Set message
115  if (elements > 0) {
116  m_message = "Vector index " + gammalib::str(inx) + " out of range [0," +
117  gammalib::str(elements-1) + "].";
118  }
119  else {
120  m_message = "Empty vector cannot be indexed.";
121  }
122 
123  // Return
124  return;
125 }
126 
127 
128 /***********************************************************************//**
129  * @brief Matrix index is out of range
130  *
131  * @param[in] origin Method throwing the exception.
132  * @param[in] row Row index.
133  * @param[in] col Column index.
134  * @param[in] rows Number of rows in matrix.
135  * @param[in] cols Number of columns in matrix.
136  ***************************************************************************/
138  int row,
139  int col,
140  int rows,
141  int cols)
142 {
143  // Set origin
144  m_origin = origin;
145 
146  // Set message
147  if (rows > 0 && cols > 0) {
148  m_message = "Matrix element (" + gammalib::str(row) + "," + gammalib::str(col) +
149  ") out of range ([0," + gammalib::str(rows-1) + "], [0," +
150  gammalib::str(cols-1) + "])";
151  }
152  else {
153  m_message = "Empty matrix cannot be indexed.";
154  }
155 
156  // Return
157  return;
158 }
159 
160 
161 /***********************************************************************//**
162  * @brief Vector dimensions differ
163  *
164  * @param[in] origin Method throwing the exception.
165  * @param[in] size1 Size of first vector.
166  * @param[in] size2 Size of second vector.
167  ***************************************************************************/
168 GException::vector_mismatch::vector_mismatch(std::string origin, int size1,
169  int size2)
170 {
171  // Set origin
172  m_origin = origin;
173 
174  // Set message
175  m_message = "Vector dimensions differ (" + gammalib::str(size1) + " <-> " +
176  gammalib::str(size2) + ").";
177 
178  // Return
179  return;
180 }
181 
182 
183 /***********************************************************************//**
184  * @brief Invalid vector dimension for cross product
185  *
186  * @param[in] origin Method throwing the exception.
187  * @param[in] elements Size of vector.
188  ***************************************************************************/
190  int elements)
191 {
192  // Set origin
193  m_origin = origin;
194 
195  // Set message
196  m_message = "Vector cross product only defined for 3 dimensions but"
197  " vector size is " + gammalib::str(elements) +".";
198 
199  // Return
200  return;
201 }
202 
203 
204 /***********************************************************************//**
205  * @brief Mismatch between matrix and vector
206  *
207  * @param[in] origin Method throwing the exception.
208  * @param[in] num Vector length.
209  * @param[in] rows Number of matrix rows.
210  * @param[in] cols Number of matrix columns.
211  ***************************************************************************/
213  int num,
214  int rows,
215  int cols)
216 {
217  // Set origin
218  m_origin = origin;
219 
220  // Set message
221  m_message = "Vector length " + gammalib::str(num) +
222  " is incompatible with matrix size (" +
223  gammalib::str(rows) + "," + gammalib::str(cols) + ").";
224 
225  // Return
226  return;
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Mismatch between matrices
232  *
233  * @param[in] origin Method throwing the exception.
234  * @param[in] rows1 Number of rows in first matrix.
235  * @param[in] cols1 Number of columns in first matrix.
236  * @param[in] rows2 Number of rows in second matrix.
237  * @param[in] cols2 Number of columns in second matrix.
238  ***************************************************************************/
239 GException::matrix_mismatch::matrix_mismatch(std::string origin, int rows1,
240  int cols1, int rows2, int cols2)
241 {
242  // Set origin
243  m_origin = origin;
244 
245  // Set message
246  m_message = "Matrices are incompatible for operation.";
247  m_message += "Matrix size ";
248  m_message += "(" + gammalib::str(rows1) + "," + gammalib::str(cols1) + ")";
249  m_message += " differs from matrix size ";
250  m_message += "(" + gammalib::str(rows2) + "," + gammalib::str(cols2) + ").";
251 
252  // Return
253  return;
254 }
255 
256 
257 /***********************************************************************//**
258  * @brief Matrix not square
259  *
260  * @param[in] origin Method throwing the exception.
261  * @param[in] rows Number of matrix rows.
262  * @param[in] cols Number of matrix columns.
263  ***************************************************************************/
265  int rows,
266  int cols)
267 {
268  // Set origin
269  m_origin = origin;
270 
271  // Set message
272  m_message = "Matrix of size (" + gammalib::str(rows) + "," + gammalib::str(cols) + ")";
273  m_message += " is not square.";
274 
275  // Return
276  return;
277 }
278 
279 
280 /***********************************************************************//**
281  * @brief Matrix is not positive definite
282  *
283  * @param[in] origin Method throwing the exception.
284  * @param[in] row Matrix row.
285  * @param[in] sum Row sum.
286  ***************************************************************************/
288  int row, double sum)
289 {
290  // Set origin
291  m_origin = origin;
292 
293  // Set message
294  m_message = "Matrix is not positive definite (sum " + gammalib::str(sum) +
295  " occured in row/column " + gammalib::str(row) + ").";
296 
297  // Return
298  return;
299 }
300 
301 
302 /***********************************************************************//**
303  * @brief Matrix is not symmetric
304  *
305  * @param[in] origin Method throwing the exception.
306  * @param[in] rows Number of rows.
307  * @param[in] cols Number of columns.
308  ***************************************************************************/
310  int rows, int cols)
311 {
312  // Set origin
313  m_origin = origin;
314 
315  // Set message
316  m_message = "Matrix (" + gammalib::str(rows) + "," + gammalib::str(cols) + ") is not symmetric.";
317 
318  // Return
319  return;
320 }
321 
322 
323 /***********************************************************************//**
324  * @brief Matrix has not been factorised
325  *
326  * @param[in] origin Method throwing the exception.
327  * @param[in] type Factorisation type.
328  ***************************************************************************/
330  std::string type)
331 {
332  // Set origin
333  m_origin = origin;
334 
335  // Set message
336  m_message = "Matrix has not been factorised using " + type;
337 
338  // Return
339  return;
340 }
341 
342 
343 /***********************************************************************//**
344  * @brief All matrix elements are zero
345  *
346  * @param[in] origin Method throwing the exception.
347  ***************************************************************************/
349 {
350  // Set origin
351  m_origin = origin;
352 
353  // Set message
354  m_message = "All matrix elements are zero.";
355 
356  // Return
357  return;
358 }
359 
360 
361 /***********************************************************************//**
362  * @brief Invalid ordering scheme requested
363  *
364  * @param[in] origin Method throwing the exception.
365  * @param[in] order Ordering scheme.
366  * @param[in] min_order Minimum ordering scheme.
367  * @param[in] max_order Maximum ordering scheme.
368  ***************************************************************************/
369 GException::invalid_order::invalid_order(std::string origin, int order,
370  int min_order, int max_order)
371 {
372  // Set origin
373  m_origin = origin;
374 
375  // Set message
376  m_message = "Invalid ordering type " + gammalib::str(order) +
377  "requested; must be comprised in [" + gammalib::str(min_order) +
378  "," + gammalib::str(max_order) + "]";
379 
380  // Return
381  return;
382 }
invalid_order(std::string origin, int order, int min_order, int max_order)
Invalid ordering scheme requested.
empty(std::string origin)
Empty object exception.
vector_mismatch(std::string origin, int size1, int size2)
Vector dimensions differ.
double sum(const GVector &vector)
Computes vector sum.
Definition: GVector.cpp:923
Gammalib tools definition.
matrix_vector_mismatch(std::string origin, int num, int rows, int cols)
Mismatch between matrix and vector.
double min(const GVector &vector)
Computes minimum vector element.
Definition: GVector.cpp:865
matrix_mismatch(std::string origin, int rows1, int cols1, int rows2, int cols2)
Mismatch between matrices.
matrix_zero(std::string origin)
All matrix elements are zero.
vector_bad_cross_dim(std::string origin, int elements)
Invalid vector dimension for cross product.
std::string m_message
Definition: GException.hpp:51
double max(const GVector &vector)
Computes maximum vector element.
Definition: GVector.cpp:894
matrix_not_square(std::string origin, int rows, int cols)
Matrix not square.
matrix_not_factorised(std::string origin, std::string type)
Matrix has not been factorised.
Exception handler interface definition.
std::string m_origin
Definition: GException.hpp:50
matrix_not_pos_definite(std::string origin, int row, double sum)
Matrix is not positive definite.
out_of_range(std::string origin, int inx, int min, int max)
Index is out of range.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:457
matrix_not_symmetric(std::string origin, int cols, int rows)
Matrix is not symmetric.