30 #include <gsl/gsl_errno.h> 
   41     GSLUtility *GSLUtility::_instance = 0;
 
   52     GSLUtility::GSLUtility() {
 
   53       gsl_set_error_handler(handler);
 
   87     gsl_vector *GSLUtility::vector(
size_t n, 
bool zero)
 const {
 
   89         return (gsl_vector_calloc(n));
 
   92         return (gsl_vector_alloc(n));
 
  110     gsl_matrix *GSLUtility::matrix(
size_t n1, 
size_t n2, 
bool zero)
 const {
 
  112         return (gsl_matrix_calloc(n1, n2));
 
  115         return (gsl_matrix_alloc(n1, n2));
 
  131     gsl_matrix *GSLUtility::identity(
size_t n1, 
size_t n2)
 const {
 
  132       gsl_matrix *i = gsl_matrix_alloc(n1, n2);
 
  133       gsl_matrix_set_identity(i);
 
  142     void GSLUtility::setIdentity(gsl_matrix *m)
 const {
 
  143       gsl_matrix_set_identity(m);
 
  158     void GSLUtility::free(gsl_vector *v)
 const {
 
  174     void GSLUtility::free(gsl_matrix *m)
 const {
 
  188     GSLUtility::GSLVector GSLUtility::gslToGSL(
const gsl_vector *v)
 const {
 
  191       for(
size_t i = 0 ; i < n ; i++) {
 
  192         Nv[i] = gsl_vector_get(v, i);
 
  206     GSLUtility::GSLMatrix GSLUtility::gslToGSL(
const gsl_matrix *m)
 const {
 
  207       size_t nrows = Rows(m);
 
  208       size_t ncols = Columns(m);
 
  209       GSLMatrix Nm(nrows, ncols);
 
  210       for(
size_t i = 0 ; i < nrows ; i++) {
 
  211         for(
size_t j = 0 ; j < ncols ; j++) {
 
  212           Nm[i][j] = gsl_matrix_get(m, i, j);
 
  229     gsl_vector *GSLUtility::GSLTogsl(
const GSLUtility::GSLVector &v,
 
  230                                      gsl_vector *gv)
 const {
 
  232         gv = gsl_vector_alloc(v.dim());
 
  234       else if(size(gv) != (size_t) v.dim()) {
 
  236         mess << 
"Size of NL vector (" << v.dim() << 
") not same as GSL vector (" 
  243       for(
int i = 0 ; i < v.dim() ; i++) {
 
  244         gsl_vector_set(gv, i, v[i]);
 
  259     gsl_matrix *GSLUtility::GSLTogsl(
const GSLUtility::GSLMatrix &m,
 
  260                                      gsl_matrix *gm)
 const {
 
  262         gm = gsl_matrix_alloc(m.dim1(), m.dim2());
 
  264       else if((Rows(gm) != (
size_t) m.dim1()) &&
 
  265               (Columns(gm) != (size_t) m.dim2())) {
 
  267         mess << 
"Size of NL matrix (" << m.dim1() << 
"," << m.dim2()
 
  268              << 
") not same as GSL matrix (" << Rows(gm) << 
"," << Columns(gm)
 
  275       for(
int i = 0 ; i < m.dim1() ; i++) {
 
  276         for(
int j = 0 ; j < m.dim2() ; j++) {
 
  277           gsl_matrix_set(gm, i, j, m[i][j]);
 
  284     size_t GSLUtility::Rows(
const gsl_matrix *m)
 const {
 
  289     size_t GSLUtility::Columns(
const gsl_matrix *m)
 const {
 
  294     size_t GSLUtility::Columns(
const GSLMatrix &m)
 const {
 
  299     size_t GSLUtility::Rows(
const GSLMatrix &m)
 const {
 
  304     size_t GSLUtility::size(
const gsl_vector *v)
 const {
 
  309     size_t GSLUtility::size(
const gsl_matrix *m)
 const {
 
  310       return (Rows(m) * Columns(m));
 
  324     void GSLUtility::check(
int gsl_status, 
const char *src, 
int line)
 const {
 
  325       if(gsl_status != GSL_SUCCESS) {
 
  326         string msg = 
"GSL error occured: " + string(gsl_strerror(gsl_status));
 
  327         throw IException(IException::Programmer, msg.c_str(), src, line);
 
  348     void GSLUtility::handler(
const char *reason, 
const char *file, 
int line,
 
  351       mess << 
"GSLError (" << gsl_errno << 
") -> " << reason;
 
  352       throw IException(IException::Programmer, mess.str().c_str(),
 
#define _FILEINFO_
Macro for the filename and line number. 
 
GSLUtility Provides top level interface to the GNU GSL.