Isis 3 Programmer Reference
GSLUtility.h
Go to the documentation of this file.
1 #ifndef GSLUtility_h
2 #define GSLUtility_h
3 
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 #include <vector>
31 #include <algorithm>
32 
33 #include <QString>
34 
35 #include <tnt/tnt_array1d.h>
36 #include <tnt/tnt_array1d_utils.h>
37 #include <tnt/tnt_array2d.h>
38 #include <tnt/tnt_array2d_utils.h>
39 
40 #include <gsl/gsl_vector.h>
41 #include <gsl/gsl_matrix.h>
42 
43 // Some GSL optimization on by default, off if DEBUG or SAFE_GSL is defined
44 #ifndef DEBUG
45 #ifndef SAFE_GSL
46 #define GSL_RANGE_CHECK_OFF 1
47 #endif
48 #endif
49 
50 #include "IException.h"
51 
52 namespace Isis {
53  namespace GSL {
54 
86  class GSLUtility {
87  public:
88  typedef TNT::Array1D<double> GSLVector;
89  typedef TNT::Array2D<double> GSLMatrix;
90 
91  static GSLUtility *getInstance();
92 
94  inline bool success(int status) const {
95  return (status == GSL_SUCCESS);
96  }
97 
104  inline QString status(int gsl_errno) const {
105  return (QString(gsl_strerror(gsl_errno)));
106  }
107 
108  void check(int gsl_status, const char *src = __FILE__, int line = __LINE__)
109  const;
110 
111 
112  size_t Rows(const gsl_matrix *m) const;
113  size_t Columns(const gsl_matrix *m) const;
114 
115  size_t Rows(const GSLMatrix &m) const;
116  size_t Columns(const GSLMatrix &m) const;
117 
118  size_t size(const gsl_vector *v) const;
119  size_t size(const gsl_matrix *m) const;
120 
121  gsl_vector *vector(size_t n, bool zero = false) const;
122  gsl_matrix *matrix(size_t n1, size_t n2, bool zero = false) const;
123  gsl_matrix *identity(size_t n1, size_t n2) const;
124  void setIdentity(gsl_matrix *m) const;
125 
126  void free(gsl_vector *v) const;
127  void free(gsl_matrix *m) const;
128 
129  GSLVector gslToGSL(const gsl_vector *v) const;
130  GSLMatrix gslToGSL(const gsl_matrix *m) const;
131  gsl_vector *GSLTogsl(const GSLVector &v, gsl_vector *gv = 0) const;
132  gsl_matrix *GSLTogsl(const GSLMatrix &m, gsl_matrix *gm = 0) const;
133 
134 
135  private:
136  // Private Constructor/Destructor makes this a singleton
137  GSLUtility();
138  ~GSLUtility() { }
139 
141 
142  static void handler(const char *reason, const char *file, int line,
143  int gsl_errno);
144 
145 
146  };
147 
148  } // namespace GSL
149 } // namespace Isis
150 #endif
151 
GSLVector gslToGSL(const gsl_vector *v) const
Converts a GSL vector to a TNT-based vector.
Definition: GSLUtility.cpp:188
size_t Rows(const gsl_matrix *m) const
Returns number of rows in a GSL matrix.
Definition: GSLUtility.cpp:284
static GSLUtility * getInstance()
Return a reference to the GSL (singleton) object.
Definition: GSLUtility.cpp:66
void free(gsl_vector *v) const
Frees a GSL vector.
Definition: GSLUtility.cpp:158
bool success(int status) const
Tests if status is success.
Definition: GSLUtility.h:94
static void handler(const char *reason, const char *file, int line, int gsl_errno)
Special GSL errror handler.
Definition: GSLUtility.cpp:348
size_t Columns(const gsl_matrix *m) const
Returns the number of coulumns in a GSL matrix.
Definition: GSLUtility.cpp:289
static GSLUtility * _instance
Singleton self-reference pointer.
Definition: GSLUtility.h:140
QString status(int gsl_errno) const
Returns GSL specific error text.
Definition: GSLUtility.h:104
gsl_vector * GSLTogsl(const GSLVector &v, gsl_vector *gv=0) const
Converts TNT-based vector to GSL vector.
Definition: GSLUtility.cpp:229
GSLUtility()
Contructs a GSLUtility object with an error handler.
Definition: GSLUtility.cpp:52
gsl_matrix * matrix(size_t n1, size_t n2, bool zero=false) const
Creates a GSL matrix.
Definition: GSLUtility.cpp:110
void check(int gsl_status, const char *src=__FILE__, int line=__LINE__) const
Performs a check on GSL library function return status.
Definition: GSLUtility.cpp:324
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
size_t size(const gsl_vector *v) const
Returns the size of a GSL vector.
Definition: GSLUtility.cpp:304
gsl_vector * vector(size_t n, bool zero=false) const
Creates a GSL vector.
Definition: GSLUtility.cpp:87
gsl_matrix * identity(size_t n1, size_t n2) const
Returns a GSL identity matrix of the specified size.
Definition: GSLUtility.cpp:131
void setIdentity(gsl_matrix *m) const
Initializes an existing GSL matrix to the identity matrix.
Definition: GSLUtility.cpp:142
GSLUtility Provides top level interface to the GNU GSL.
Definition: GSLUtility.h:86