binary_library.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 // This C++ file compiles to binary code that can be linked to by your C program,
11 // thanks to the extern "C" syntax used in the declarations in binary_library.h.
12 
13 #include "binary_library.h"
14 
15 #include <Eigen/Core>
16 
17 using namespace Eigen;
18 
19 /************************* pointer conversion methods **********************************************/
20 
22 
23 inline MatrixXd& c_to_eigen(C_MatrixXd* ptr)
24 {
25  return *reinterpret_cast<MatrixXd*>(ptr);
26 }
27 
28 inline const MatrixXd& c_to_eigen(const C_MatrixXd* ptr)
29 {
30  return *reinterpret_cast<const MatrixXd*>(ptr);
31 }
32 
33 inline C_MatrixXd* eigen_to_c(MatrixXd& ref)
34 {
35  return reinterpret_cast<C_MatrixXd*>(&ref);
36 }
37 
38 inline const C_MatrixXd* eigen_to_c(const MatrixXd& ref)
39 {
40  return reinterpret_cast<const C_MatrixXd*>(&ref);
41 }
42 
44 
46 {
47  return *reinterpret_cast<Map<MatrixXd>*>(ptr);
48 }
49 
50 inline const Map<MatrixXd>& c_to_eigen(const C_Map_MatrixXd* ptr)
51 {
52  return *reinterpret_cast<const Map<MatrixXd>*>(ptr);
53 }
54 
56 {
57  return reinterpret_cast<C_Map_MatrixXd*>(&ref);
58 }
59 
61 {
62  return reinterpret_cast<const C_Map_MatrixXd*>(&ref);
63 }
64 
65 
66 /************************* implementation of classes **********************************************/
67 
68 
70 
71 
73 {
74  return eigen_to_c(*new MatrixXd(rows,cols));
75 }
76 
78 {
79  delete &c_to_eigen(m);
80 }
81 
83 {
84  return c_to_eigen(m).data();
85 }
86 
88 {
89  c_to_eigen(m).setZero();
90 }
91 
93 {
94  c_to_eigen(m).resize(rows,cols);
95 }
96 
97 void MatrixXd_copy(C_MatrixXd *dst, const C_MatrixXd *src)
98 {
99  c_to_eigen(dst) = c_to_eigen(src);
100 }
101 
103 {
104  c_to_eigen(dst) = c_to_eigen(src);
105 }
106 
107 void MatrixXd_set_coeff(C_MatrixXd *m, int i, int j, double coeff)
108 {
109  c_to_eigen(m)(i,j) = coeff;
110 }
111 
112 double MatrixXd_get_coeff(const C_MatrixXd *m, int i, int j)
113 {
114  return c_to_eigen(m)(i,j);
115 }
116 
118 {
119  std::cout << c_to_eigen(m) << std::endl;
120 }
121 
123 {
125 }
126 
128 {
130 }
131 
132 
133 
135 
136 
138 {
139  return eigen_to_c(*new Map<MatrixXd>(array,rows,cols));
140 }
141 
143 {
144  delete &c_to_eigen(m);
145 }
146 
148 {
149  c_to_eigen(m).setZero();
150 }
151 
153 {
154  c_to_eigen(dst) = c_to_eigen(src);
155 }
156 
158 {
159  c_to_eigen(dst) = c_to_eigen(src);
160 }
161 
162 void Map_MatrixXd_set_coeff(C_Map_MatrixXd *m, int i, int j, double coeff)
163 {
164  c_to_eigen(m)(i,j) = coeff;
165 }
166 
167 double Map_MatrixXd_get_coeff(const C_Map_MatrixXd *m, int i, int j)
168 {
169  return c_to_eigen(m)(i,j);
170 }
171 
173 {
174  std::cout << c_to_eigen(m) << std::endl;
175 }
176 
178 {
180 }
181 
183 {
185 }
Map_MatrixXd_new
C_Map_MatrixXd * Map_MatrixXd_new(double *array, int rows, int cols)
Definition: binary_library.cpp:137
MatrixXd_new
C_MatrixXd * MatrixXd_new(int rows, int cols)
Definition: binary_library.cpp:72
Map_MatrixXd_add
void Map_MatrixXd_add(const C_Map_MatrixXd *m1, const C_Map_MatrixXd *m2, C_Map_MatrixXd *result)
Definition: binary_library.cpp:182
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
C_MatrixXd
Definition: binary_library.h:22
Map_MatrixXd_set_coeff
void Map_MatrixXd_set_coeff(C_Map_MatrixXd *m, int i, int j, double coeff)
Definition: binary_library.cpp:162
Eigen::array
Definition: EmulateArray.h:21
Map_MatrixXd_copy
void Map_MatrixXd_copy(C_Map_MatrixXd *dst, const C_Map_MatrixXd *src)
Definition: binary_library.cpp:152
MatrixXd_resize
void MatrixXd_resize(C_MatrixXd *m, int rows, int cols)
Definition: binary_library.cpp:92
MatrixXd_print
void MatrixXd_print(const C_MatrixXd *m)
Definition: binary_library.cpp:117
MatrixXd_multiply
void MatrixXd_multiply(const C_MatrixXd *m1, const C_MatrixXd *m2, C_MatrixXd *result)
Definition: binary_library.cpp:122
m1
Matrix3d m1
Definition: IOFormat.cpp:2
Map_MatrixXd_print
void Map_MatrixXd_print(const C_Map_MatrixXd *m)
Definition: binary_library.cpp:172
result
Values result
Definition: OdometryOptimize.cpp:8
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
MatrixXd_copy_map
void MatrixXd_copy_map(C_MatrixXd *dst, const C_Map_MatrixXd *src)
Definition: binary_library.cpp:102
Map_MatrixXd_delete
void Map_MatrixXd_delete(C_Map_MatrixXd *m)
Definition: binary_library.cpp:142
m2
MatrixType m2(n_dims)
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
MatrixXd_copy
void MatrixXd_copy(C_MatrixXd *dst, const C_MatrixXd *src)
Definition: binary_library.cpp:97
eigen_to_c
C_MatrixXd * eigen_to_c(MatrixXd &ref)
Definition: binary_library.cpp:33
MatrixXd_get_coeff
double MatrixXd_get_coeff(const C_MatrixXd *m, int i, int j)
Definition: binary_library.cpp:112
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
binary_library.h
Map_MatrixXd_get_coeff
double Map_MatrixXd_get_coeff(const C_Map_MatrixXd *m, int i, int j)
Definition: binary_library.cpp:167
MatrixXd_data
double * MatrixXd_data(C_MatrixXd *m)
Definition: binary_library.cpp:82
Map_MatrixXd_multiply
void Map_MatrixXd_multiply(const C_Map_MatrixXd *m1, const C_Map_MatrixXd *m2, C_Map_MatrixXd *result)
Definition: binary_library.cpp:177
ref
Reference counting helper.
Definition: object.h:67
MatrixXd_set_coeff
void MatrixXd_set_coeff(C_MatrixXd *m, int i, int j, double coeff)
Definition: binary_library.cpp:107
MatrixXd_set_zero
void MatrixXd_set_zero(C_MatrixXd *m)
Definition: binary_library.cpp:87
c_to_eigen
MatrixXd & c_to_eigen(C_MatrixXd *ptr)
Definition: binary_library.cpp:23
MatrixXd_delete
void MatrixXd_delete(C_MatrixXd *m)
Definition: binary_library.cpp:77
MatrixXd_add
void MatrixXd_add(const C_MatrixXd *m1, const C_MatrixXd *m2, C_MatrixXd *result)
Definition: binary_library.cpp:127
Map_MatrixXd_set_zero
void Map_MatrixXd_set_zero(C_Map_MatrixXd *m)
Definition: binary_library.cpp:147
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Map_MatrixXd_copy_matrix
void Map_MatrixXd_copy_matrix(C_Map_MatrixXd *dst, const C_MatrixXd *src)
Definition: binary_library.cpp:157
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
C_Map_MatrixXd
Definition: binary_library.h:23
test_eigen.ref
ref
Definition: test_eigen.py:9


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:55