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
c_interface_base::copy_vector
static void copy_vector(const gene_vector &source, gene_vector &cible, int N)
Definition: c_interface_base.h:58
c_interface_base::matrix_from_stl
static void matrix_from_stl(gene_matrix &A, stl_matrix &A_stl)
Definition: c_interface_base.h:28
c_interface_base::real_type
real real_type
Definition: c_interface_base.h:13
c_interface_base::gene_vector
real * gene_vector
Definition: c_interface_base.h:18
B
Definition: test_numpy_dtypes.cpp:299
c_interface_base::vector_to_stl
static void vector_to_stl(gene_vector &B, stl_vector &B_stl)
Definition: c_interface_base.h:43
E1::B
@ B
c_interface_base
Definition: c_interface_base.h:8
A
Definition: test_numpy_dtypes.cpp:298
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
c_interface_base::stl_vector
std::vector< real > stl_vector
Definition: c_interface_base.h:14
E1::A
@ A
c_interface_base::free_vector
static void free_vector(gene_vector &B)
Definition: c_interface_base.h:24
c_interface_base::stl_matrix
std::vector< stl_vector > stl_matrix
Definition: c_interface_base.h:15
c_interface_base::free_matrix
static void free_matrix(gene_matrix &A, int)
Definition: c_interface_base.h:20
c_interface_base::gene_matrix
real * gene_matrix
Definition: c_interface_base.h:17
c_interface_base::matrix_to_stl
static void matrix_to_stl(gene_matrix &A, stl_matrix &A_stl)
Definition: c_interface_base.h:49
c_interface_base::copy_matrix
static void copy_matrix(const gene_matrix &source, gene_matrix &cible, int N)
Definition: c_interface_base.h:63
N
#define N
Definition: igam.h:9
c_interface_base::vector_from_stl
static void vector_from_stl(gene_vector &B, stl_vector &B_stl)
Definition: c_interface_base.h:36
real
Definition: main.h:100
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:13