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 {
124  c_to_eigen(result) = c_to_eigen(m1) * c_to_eigen(m2);
125 }
126 
128 {
129  c_to_eigen(result) = c_to_eigen(m1) + c_to_eigen(m2);
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 {
179  c_to_eigen(result) = c_to_eigen(m1) * c_to_eigen(m2);
180 }
181 
183 {
184  c_to_eigen(result) = c_to_eigen(m1) + c_to_eigen(m2);
185 }
Matrix3f m
void MatrixXd_set_coeff(C_MatrixXd *m, int i, int j, double coeff)
void MatrixXd_add(const C_MatrixXd *m1, const C_MatrixXd *m2, C_MatrixXd *result)
C_MatrixXd * eigen_to_c(MatrixXd &ref)
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
MatrixType m2(n_dims)
void Map_MatrixXd_copy_matrix(C_Map_MatrixXd *dst, const C_MatrixXd *src)
C_Map_MatrixXd * Map_MatrixXd_new(double *array, int rows, int cols)
C_MatrixXd * MatrixXd_new(int rows, int cols)
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
void Map_MatrixXd_set_zero(C_Map_MatrixXd *m)
void Map_MatrixXd_copy(C_Map_MatrixXd *dst, const C_Map_MatrixXd *src)
double MatrixXd_get_coeff(const C_MatrixXd *m, int i, int j)
void MatrixXd_copy(C_MatrixXd *dst, const C_MatrixXd *src)
void MatrixXd_print(const C_MatrixXd *m)
Values result
void MatrixXd_delete(C_MatrixXd *m)
Matrix3d m1
Definition: IOFormat.cpp:2
void MatrixXd_resize(C_MatrixXd *m, int rows, int cols)
void MatrixXd_multiply(const C_MatrixXd *m1, const C_MatrixXd *m2, C_MatrixXd *result)
MatrixXd & c_to_eigen(C_MatrixXd *ptr)
Reference counting helper.
Definition: object.h:67
double Map_MatrixXd_get_coeff(const C_Map_MatrixXd *m, int i, int j)
void Map_MatrixXd_multiply(const C_Map_MatrixXd *m1, const C_Map_MatrixXd *m2, C_Map_MatrixXd *result)
void Map_MatrixXd_add(const C_Map_MatrixXd *m1, const C_Map_MatrixXd *m2, C_Map_MatrixXd *result)
void Map_MatrixXd_print(const C_Map_MatrixXd *m)
void MatrixXd_set_zero(C_MatrixXd *m)
void MatrixXd_copy_map(C_MatrixXd *dst, const C_Map_MatrixXd *src)
void Map_MatrixXd_set_coeff(C_Map_MatrixXd *m, int i, int j, double coeff)
void Map_MatrixXd_delete(C_Map_MatrixXd *m)
std::ptrdiff_t j
double * MatrixXd_data(C_MatrixXd *m)


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