YARP
Yet Another Robot Platform
Gsl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /*
20  * This library provides functions for compatibility with GSL.
21  * @warning Including/linking GSL forces this library to be GPL.
22  */
23 
24 #include <yarp/gsl/Gsl.h>
26 #include <yarp/sig/Matrix.h>
27 #include <yarp/sig/Vector.h>
28 
29 using namespace yarp::gsl;
30 using namespace yarp::sig;
31 
33 {
34  auto* mat = new gsl_matrix;
35  auto* bl = new gsl_block;
36 
37  mat->block = bl;
38 
39  //this is constant (at least for now)
40  mat->owner = 1;
41 
42  gslData = mat;
43 
44  auto* tmp = static_cast<gsl_matrix *>(gslData);
45  tmp->block->data = const_cast<double *>(v.data());
46  tmp->data = tmp->block->data;
47  tmp->block->size = v.rows()*v.cols();
48  tmp->owner = 1;
49  tmp->tda = v.cols();
50  tmp->size1 = v.rows();
51  tmp->size2 = v.cols();
52 }
53 
55 {
56  auto* tmp = (gsl_matrix *)(gslData);
57 
58  if (tmp != nullptr)
59  {
60  delete tmp->block;
61  delete tmp;
62  }
63 
64  gslData = nullptr;
65 }
66 
68 {
69  return gslData;
70 }
71 
72 
73 const void *GslMatrix::getGslMatrix() const
74 {
75  return gslData;
76 }
77 
78 
80 {
81  auto* vect = new gsl_vector;
82  auto* bl = new gsl_block;
83 
84  vect->block = bl;
85 
86  //these are constant (at least for now)
87  vect->owner = 1;
88  vect->stride = 1;
89 
90  gslData = vect;
91 
92  auto* tmp = static_cast<gsl_vector *>(gslData);
93  tmp->block->data = const_cast<double * > (v.data());
94  tmp->data = tmp->block->data;
95  tmp->block->size = v.size();
96  tmp->owner = 1;
97  tmp->stride = 1;
98  tmp->size = tmp->block->size;
99 }
100 
102 {
103  auto* tmp = (gsl_vector *)(gslData);
104 
105  if (tmp != nullptr)
106  {
107  delete tmp->block;
108  delete tmp;
109  }
110 
111  gslData = nullptr;
112 }
113 
115 {
116  return gslData;
117 }
118 
119 
120 const void *GslVector::getGslVector() const
121 {
122  return gslData;
123 }
yarp::gsl::GslVector::GslVector
GslVector(const yarp::sig::Vector &)
Definition: Gsl.cpp:79
gsl_block::data
double * data
Definition: gsl_structs.h:34
Vector.h
contains the definition of a Vector type
yarp::sig
Signal processing.
Definition: Image.h:25
yarp::sig::Matrix::rows
size_t rows() const
Return number of rows.
Definition: Matrix.h:95
Matrix.h
contains the definition of a Matrix type
yarp::gsl::GslVector::getGslVector
void * getGslVector()
Definition: Gsl.cpp:114
yarp::gsl::GslMatrix::GslMatrix
GslMatrix(const yarp::sig::Matrix &)
Allocate from yarp Matrix.
Definition: Gsl.cpp:32
yarp::sig::VectorOf< double >
gsl_vector
Definition: gsl_structs.h:40
gsl_structs.h
gsl_vector::block
gsl_block * block
Definition: gsl_structs.h:44
gsl_block
Definition: gsl_structs.h:32
yarp::gsl::GslVector::~GslVector
~GslVector()
Definition: Gsl.cpp:101
yarp::gsl::GslMatrix::~GslMatrix
~GslMatrix()
Definition: Gsl.cpp:54
yarp::gsl::GslMatrix::getGslMatrix
void * getGslMatrix()
Return GSL compatile pointer.
Definition: Gsl.cpp:67
yarp::sig::Matrix::cols
size_t cols() const
Return number of columns.
Definition: Matrix.h:101
yarp::sig::VectorOf::data
T * data()
Return a pointer to the first element of the vector.
Definition: Vector.h:239
yarp::sig::Matrix::data
double * data()
Return a pointer to the first element.
Definition: Matrix.h:304
Gsl.h
gsl_matrix
Definition: gsl_structs.h:51
yarp::gsl
A library for interoperability with the GSL library.
Definition: Gsl.h:38
yarp::sig::VectorOf::size
size_t size() const
Definition: Vector.h:355
gsl_matrix::block
gsl_block * block
Definition: gsl_structs.h:56
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46