Isis Developer Reference
GSLUtility.h
Go to the documentation of this file.
1#ifndef GSLUtility_h
2#define GSLUtility_h
8/* SPDX-License-Identifier: CC0-1.0 */
9
10#include <iostream>
11#include <sstream>
12#include <string>
13#include <vector>
14#include <algorithm>
15
16#include <QString>
17
18#include <tnt/tnt_array1d.h>
19#include <tnt/tnt_array1d_utils.h>
20#include <tnt/tnt_array2d.h>
21#include <tnt/tnt_array2d_utils.h>
22
23#include <gsl/gsl_vector.h>
24#include <gsl/gsl_matrix.h>
25
26// Some GSL optimization on by default, off if DEBUG or SAFE_GSL is defined
27#ifndef DEBUG
28#ifndef SAFE_GSL
29#define GSL_RANGE_CHECK_OFF 1
30#endif
31#endif
32
33#include "IException.h"
34
35namespace Isis {
36 namespace GSL {
37
69 class GSLUtility {
70 public:
71 typedef TNT::Array1D<double> GSLVector;
72 typedef TNT::Array2D<double> GSLMatrix;
73
74 static GSLUtility *getInstance();
75
77 inline bool success(int status) const {
78 return (status == GSL_SUCCESS);
79 }
80
87 inline QString status(int gsl_errno) const {
88 return (QString(gsl_strerror(gsl_errno)));
89 }
90
91 void check(int gsl_status, const char *src = __FILE__, int line = __LINE__)
92 const;
93
94
95 size_t Rows(const gsl_matrix *m) const;
96 size_t Columns(const gsl_matrix *m) const;
97
98 size_t Rows(const GSLMatrix &m) const;
99 size_t Columns(const GSLMatrix &m) const;
100
101 size_t size(const gsl_vector *v) const;
102 size_t size(const gsl_matrix *m) const;
103
104 gsl_vector *vector(size_t n, bool zero = false) const;
105 gsl_matrix *matrix(size_t n1, size_t n2, bool zero = false) const;
106 gsl_matrix *identity(size_t n1, size_t n2) const;
107 void setIdentity(gsl_matrix *m) const;
108
109 void free(gsl_vector *v) const;
110 void free(gsl_matrix *m) const;
111
112 GSLVector gslToGSL(const gsl_vector *v) const;
113 GSLMatrix gslToGSL(const gsl_matrix *m) const;
114 gsl_vector *GSLTogsl(const GSLVector &v, gsl_vector *gv = 0) const;
115 gsl_matrix *GSLTogsl(const GSLMatrix &m, gsl_matrix *gm = 0) const;
116
117
118 private:
119 // Private Constructor/Destructor makes this a singleton
120 GSLUtility();
121 ~GSLUtility() { }
122
123 static GSLUtility *_instance;
124
125 static void handler(const char *reason, const char *file, int line,
126 int gsl_errno);
127
128
129 };
130
131 } // namespace GSL
132} // namespace Isis
133#endif
134
GSLUtility Provides top level interface to the GNU GSL.
Definition GSLUtility.h:69
TNT::Array2D< double > GSLMatrix
Definition GSLUtility.h:72
size_t Rows(const gsl_matrix *m) const
Returns number of rows in a GSL matrix.
Definition GSLUtility.cpp:267
void free(gsl_vector *v) const
Frees a GSL vector.
Definition GSLUtility.cpp:141
size_t size(const gsl_vector *v) const
Returns the size of a GSL vector.
Definition GSLUtility.cpp:287
GSLVector gslToGSL(const gsl_vector *v) const
Converts a GSL vector to a TNT-based vector.
Definition GSLUtility.cpp:171
void setIdentity(gsl_matrix *m) const
Initializes an existing GSL matrix to the identity matrix.
Definition GSLUtility.cpp:125
gsl_vector * GSLTogsl(const GSLVector &v, gsl_vector *gv=0) const
Converts TNT-based vector to GSL vector.
Definition GSLUtility.cpp:212
bool success(int status) const
Tests if status is success.
Definition GSLUtility.h:77
TNT::Array1D< double > GSLVector
Definition GSLUtility.h:71
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:307
gsl_matrix * matrix(size_t n1, size_t n2, bool zero=false) const
Creates a GSL matrix.
Definition GSLUtility.cpp:93
static GSLUtility * getInstance()
Return a reference to the GSL (singleton) object.
Definition GSLUtility.cpp:49
QString status(int gsl_errno) const
Returns GSL specific error text.
Definition GSLUtility.h:87
size_t Columns(const gsl_matrix *m) const
Returns the number of coulumns in a GSL matrix.
Definition GSLUtility.cpp:272
gsl_vector * vector(size_t n, bool zero=false) const
Creates a GSL vector.
Definition GSLUtility.cpp:70
gsl_matrix * identity(size_t n1, size_t n2) const
Returns a GSL identity matrix of the specified size.
Definition GSLUtility.cpp:114
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16