c_interface_base.h
Go to the documentation of this file.
1 
2 #ifndef BTL_C_INTERFACE_BASE_H
3 #define BTL_C_INTERFACE_BASE_H
4 
5 #include "utilities.h"
6 #include <vector>
7 
8 template<class real> class c_interface_base
9 {
10 
11 public:
12 
13  typedef real real_type;
14  typedef std::vector<real> stl_vector;
15  typedef std::vector<stl_vector > stl_matrix;
16 
17  typedef real* gene_matrix;
18  typedef real* gene_vector;
19 
20  static void free_matrix(gene_matrix & A, int /*N*/){
21  delete[] A;
22  }
23 
24  static void free_vector(gene_vector & B){
25  delete[] B;
26  }
27 
28  static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
29  int N = A_stl.size();
30  A = new real[N*N];
31  for (int j=0;j<N;j++)
32  for (int i=0;i<N;i++)
33  A[i+N*j] = A_stl[j][i];
34  }
35 
36  static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
37  int N = B_stl.size();
38  B = new real[N];
39  for (int i=0;i<N;i++)
40  B[i] = B_stl[i];
41  }
42 
43  static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
44  int N = B_stl.size();
45  for (int i=0;i<N;i++)
46  B_stl[i] = B[i];
47  }
48 
49  static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
50  int N = A_stl.size();
51  for (int j=0;j<N;j++){
52  A_stl[j].resize(N);
53  for (int i=0;i<N;i++)
54  A_stl[j][i] = A[i+N*j];
55  }
56  }
57 
58  static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
59  for (int i=0;i<N;i++)
60  cible[i]=source[i];
61  }
62 
63  static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
64  for (int j=0;j<N;j++){
65  for (int i=0;i<N;i++){
66  cible[i+N*j] = source[i+N*j];
67  }
68  }
69  }
70 
71 };
72 
73 #endif
std::vector< real > stl_vector
std::vector< stl_vector > stl_matrix
static void matrix_to_stl(gene_matrix &A, stl_matrix &A_stl)
#define N
Definition: gksort.c:12
Definition: main.h:100
static void copy_vector(const gene_vector &source, gene_vector &cible, int N)
static void copy_matrix(const gene_matrix &source, gene_matrix &cible, int N)
static void free_matrix(gene_matrix &A, int)
static void free_vector(gene_vector &B)
static void matrix_from_stl(gene_matrix &A, stl_matrix &A_stl)
static void vector_to_stl(gene_vector &B, stl_vector &B_stl)
std::ptrdiff_t j
static void vector_from_stl(gene_vector &B, stl_vector &B_stl)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:59