ublas_interface.hh
Go to the documentation of this file.
1 //=====================================================
2 // File : ublas_interface.hh
3 // Author : L. Plagne <laurent.plagne@edf.fr)>
4 // Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002
5 //=====================================================
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 //
20 #ifndef UBLAS_INTERFACE_HH
21 #define UBLAS_INTERFACE_HH
22 
23 #include <boost/numeric/ublas/vector.hpp>
24 #include <boost/numeric/ublas/matrix.hpp>
25 #include <boost/numeric/ublas/io.hpp>
26 #include <boost/numeric/ublas/triangular.hpp>
27 
28 using namespace boost::numeric;
29 
30 template <class real>
32 
33 public :
34 
35  typedef real real_type ;
36 
37  typedef std::vector<real> stl_vector;
38  typedef std::vector<stl_vector> stl_matrix;
39 
40  typedef typename boost::numeric::ublas::matrix<real,boost::numeric::ublas::column_major> gene_matrix;
41  typedef typename boost::numeric::ublas::vector<real> gene_vector;
42 
43  static inline std::string name( void ) { return "ublas"; }
44 
45  static void free_matrix(gene_matrix & A, int N) {}
46 
47  static void free_vector(gene_vector & B) {}
48 
49  static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
50  A.resize(A_stl.size(),A_stl[0].size());
51  for (int j=0; j<A_stl.size() ; j++)
52  for (int i=0; i<A_stl[j].size() ; i++)
53  A(i,j)=A_stl[j][i];
54  }
55 
56  static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
57  B.resize(B_stl.size());
58  for (int i=0; i<B_stl.size() ; i++)
59  B(i)=B_stl[i];
60  }
61 
62  static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
63  for (int i=0; i<B_stl.size() ; i++)
64  B_stl[i]=B(i);
65  }
66 
67  static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
68  int N=A_stl.size();
69  for (int j=0;j<N;j++)
70  {
71  A_stl[j].resize(N);
72  for (int i=0;i<N;i++)
73  A_stl[j][i]=A(i,j);
74  }
75  }
76 
77  static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
78  for (int i=0;i<N;i++){
79  cible(i) = source(i);
80  }
81  }
82 
83  static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
84  for (int i=0;i<N;i++){
85  for (int j=0;j<N;j++){
86  cible(i,j) = source(i,j);
87  }
88  }
89  }
90 
91  static inline void matrix_vector_product_slow(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
92  X = prod(A,B);
93  }
94 
95  static inline void matrix_matrix_product_slow(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){
96  X = prod(A,B);
97  }
98 
99  static inline void axpy_slow(const real coef, const gene_vector & X, gene_vector & Y, int N){
100  Y+=coef*X;
101  }
102 
103  // alias free assignments
104 
105  static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
106  X.assign(prod(A,B));
107  }
108 
109  static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
110  X.assign(prod(trans(A),B));
111  }
112 
113  static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){
114  X.assign(prod(A,B));
115  }
116 
117  static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
118  Y.plus_assign(coef*X);
119  }
120 
121  static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
122  Y = a*X + b*Y;
123  }
124 
125  static inline void ata_product(gene_matrix & A, gene_matrix & X, int N){
126  // X = prod(trans(A),A);
127  X.assign(prod(trans(A),A));
128  }
129 
130  static inline void aat_product(gene_matrix & A, gene_matrix & X, int N){
131  // X = prod(A,trans(A));
132  X.assign(prod(A,trans(A)));
133  }
134 
135  static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
136  X = solve(L, B, ublas::lower_tag ());
137  }
138 
139 };
140 
141 #endif
ublas_interface
Definition: ublas_interface.hh:31
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
ublas_interface::matrix_vector_product_slow
static void matrix_vector_product_slow(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: ublas_interface.hh:91
ublas_interface::axpy_slow
static void axpy_slow(const real coef, const gene_vector &X, gene_vector &Y, int N)
Definition: ublas_interface.hh:99
ublas_interface::axpby
static void axpby(real a, const gene_vector &X, real b, gene_vector &Y, int N)
Definition: ublas_interface.hh:121
b
Scalar * b
Definition: benchVecAdd.cpp:17
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
ublas_interface::matrix_vector_product
static void matrix_vector_product(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: ublas_interface.hh:105
ublas_interface::stl_vector
std::vector< real > stl_vector
Definition: ublas_interface.hh:37
trans
static char trans
Definition: blas_interface.hh:58
X
#define X
Definition: icosphere.cpp:20
ublas_interface::trisolve_lower
static void trisolve_lower(const gene_matrix &L, const gene_vector &B, gene_vector &X, int N)
Definition: ublas_interface.hh:135
ublas_interface::vector_from_stl
static void vector_from_stl(gene_vector &B, stl_vector &B_stl)
Definition: ublas_interface.hh:56
ublas_interface::matrix_to_stl
static void matrix_to_stl(gene_matrix &A, stl_matrix &A_stl)
Definition: ublas_interface.hh:67
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
ublas_interface::name
static std::string name(void)
Definition: ublas_interface.hh:43
ublas_interface::atv_product
static void atv_product(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: ublas_interface.hh:109
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
ublas_interface::copy_vector
static void copy_vector(const gene_vector &source, gene_vector &cible, int N)
Definition: ublas_interface.hh:77
ublas_interface::free_matrix
static void free_matrix(gene_matrix &A, int N)
Definition: ublas_interface.hh:45
ublas_interface::copy_matrix
static void copy_matrix(const gene_matrix &source, gene_matrix &cible, int N)
Definition: ublas_interface.hh:83
ublas_interface::stl_matrix
std::vector< stl_vector > stl_matrix
Definition: ublas_interface.hh:38
L
MatrixXd L
Definition: LLT_example.cpp:6
ublas_interface::matrix_matrix_product_slow
static void matrix_matrix_product_slow(gene_matrix &A, gene_matrix &B, gene_matrix &X, int N)
Definition: ublas_interface.hh:95
ublas_interface::ata_product
static void ata_product(gene_matrix &A, gene_matrix &X, int N)
Definition: ublas_interface.hh:125
ublas_interface::vector_to_stl
static void vector_to_stl(gene_vector &B, stl_vector &B_stl)
Definition: ublas_interface.hh:62
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
ublas_interface::matrix_matrix_product
static void matrix_matrix_product(gene_matrix &A, gene_matrix &B, gene_matrix &X, int N)
Definition: ublas_interface.hh:113
ublas_interface::real_type
real real_type
Definition: ublas_interface.hh:35
ublas_interface::matrix_from_stl
static void matrix_from_stl(gene_matrix &A, stl_matrix &A_stl)
Definition: ublas_interface.hh:49
ublas_interface::aat_product
static void aat_product(gene_matrix &A, gene_matrix &X, int N)
Definition: ublas_interface.hh:130
N
#define N
Definition: igam.h:9
ublas_interface::gene_vector
boost::numeric::ublas::vector< real > gene_vector
Definition: ublas_interface.hh:41
ublas_interface::gene_matrix
boost::numeric::ublas::matrix< real, boost::numeric::ublas::column_major > gene_matrix
Definition: ublas_interface.hh:40
prod
EIGEN_DONT_INLINE void prod(const Lhs &a, const Rhs &b, Res &c)
Definition: product_threshold.cpp:39
ublas_interface::free_vector
static void free_vector(gene_vector &B)
Definition: ublas_interface.hh:47
real
Definition: main.h:100
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
ublas_interface::axpy
static void axpy(const real coef, const gene_vector &X, gene_vector &Y, int N)
Definition: ublas_interface.hh:117


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:37