YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Gsl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6/*
7 * This library provides functions for compatibility with GSL.
8 * @warning Including/linking GSL forces this library to be GPL.
9 */
10
11#include <yarp/gsl/Gsl.h>
13#include <yarp/sig/Matrix.h>
14#include <yarp/sig/Vector.h>
15
16using namespace yarp::gsl;
17using namespace yarp::sig;
18
20{
21 auto* mat = new gsl_matrix;
22 auto* bl = new gsl_block;
23
24 mat->block = bl;
25
26 //this is constant (at least for now)
27 mat->owner = 1;
28
29 gslData = mat;
30
31 auto* tmp = static_cast<gsl_matrix *>(gslData);
32 tmp->block->data = const_cast<double *>(v.data());
33 tmp->data = tmp->block->data;
34 tmp->block->size = v.rows()*v.cols();
35 tmp->owner = 1;
36 tmp->tda = v.cols();
37 tmp->size1 = v.rows();
38 tmp->size2 = v.cols();
39}
40
42{
43 auto* tmp = (gsl_matrix *)(gslData);
44
45 if (tmp != nullptr)
46 {
47 delete tmp->block;
48 delete tmp;
49 }
50
51 gslData = nullptr;
52}
53
55{
56 return gslData;
57}
58
59
60const void *GslMatrix::getGslMatrix() const
61{
62 return gslData;
63}
64
65
67{
68 auto* vect = new gsl_vector;
69 auto* bl = new gsl_block;
70
71 vect->block = bl;
72
73 //these are constant (at least for now)
74 vect->owner = 1;
75 vect->stride = 1;
76
77 gslData = vect;
78
79 auto* tmp = static_cast<gsl_vector *>(gslData);
80 tmp->block->data = const_cast<double * > (v.data());
81 tmp->data = tmp->block->data;
82 tmp->block->size = v.size();
83 tmp->owner = 1;
84 tmp->stride = 1;
85 tmp->size = tmp->block->size;
86}
87
89{
90 auto* tmp = (gsl_vector *)(gslData);
91
92 if (tmp != nullptr)
93 {
94 delete tmp->block;
95 delete tmp;
96 }
97
98 gslData = nullptr;
99}
100
102{
103 return gslData;
104}
105
106
107const void *GslVector::getGslVector() const
108{
109 return gslData;
110}
contains the definition of a Matrix type
contains the definition of a Vector type
GslMatrix(const yarp::sig::Matrix &)
Allocate from yarp Matrix.
Definition Gsl.cpp:19
void * getGslMatrix()
Return GSL compatile pointer.
Definition Gsl.cpp:54
void * getGslVector()
Definition Gsl.cpp:101
GslVector(const yarp::sig::Vector &)
Definition Gsl.cpp:66
A class for a Matrix.
Definition Matrix.h:39
size_t cols() const
Return number of columns.
Definition Matrix.h:94
double * data()
Return a pointer to the first element.
Definition Matrix.h:297
size_t rows() const
Return number of rows.
Definition Matrix.h:88
size_t size() const
Definition Vector.h:341
T * data()
Return a pointer to the first element of the vector.
Definition Vector.h:206
double * data
Definition gsl_structs.h:21
gsl_block * block
Definition gsl_structs.h:43
gsl_block * block
Definition gsl_structs.h:31