flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
gsl_utils.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef GSL_UTILS_H
20#define GSL_UTILS_H
21
22#include "error.hpp"
23#include "gsl_vector.hpp"
24
25#include <gsl/gsl_vector.h>
26#include <Eigen/Core>
27
28namespace flexiblesusy {
29
31bool is_finite(const gsl_vector*);
32
33template <typename Derived>
34GSL_vector to_GSL_vector(const Eigen::DenseBase<Derived>& v)
35{
36 using Index_t = typename Derived::Index;
37 GSL_vector v2(v.rows());
38
39 for (Index_t i = 0; i < v.rows(); i++) {
40 v2[i] = v(i);
41 }
42
43 return v2;
44}
45
46template <int Size>
47Eigen::Matrix<double,Size,1> to_eigen_vector(const gsl_vector* v)
48{
49 if (Size != v->size) {
50 throw OutOfBoundsError("Size of GSL_vector does not match size of Eigen vector.");
51 }
52
53 using Result_t = Eigen::Matrix<double,Size,1>;
54 using Index_t = typename Result_t::Index;
55 Result_t result;
56
57 for (Index_t i = 0; i < Size; i++) {
58 result(i) = gsl_vector_get(v, i);
59 }
60
61 return result;
62}
63
64} // namespace flexiblesusy
65
66#endif
Out of bounds access.
Definition: error.hpp:208
Eigen::Matrix< double, Size, 1 > to_eigen_vector(const gsl_vector *v)
Definition: gsl_utils.hpp:47
GSL_vector to_GSL_vector(const Eigen::DenseBase< Derived > &v)
Definition: gsl_utils.hpp:34
bool is_finite(const gsl_vector *x)
Returns true if GSL vector contains only finite elements, false otherwise.
Definition: gsl_utils.cpp:32