gtsam
3rdparty
Eigen
doc
snippets
Tutorial_Map_using.cpp
Go to the documentation of this file.
1
typedef
Matrix<float,1,Dynamic>
MatrixType
;
2
typedef
Map<MatrixType>
MapType
;
3
typedef
Map<const MatrixType>
MapTypeConst
;
// a read-only map
4
const
int
n_dims
= 5;
5
6
MatrixType
m1
(
n_dims
),
m2
(
n_dims
);
7
m1
.setRandom();
8
m2
.setRandom();
9
float
*
p
= &
m2
(0);
// get the address storing the data for m2
10
MapType
m2map
(
p
,
m2
.size());
// m2map shares data with m2
11
MapTypeConst
m2mapconst
(
p
,
m2
.size());
// a read-only accessor for m2
12
13
cout <<
"m1: "
<<
m1
<< endl;
14
cout <<
"m2: "
<<
m2
<< endl;
15
cout <<
"Squared euclidean distance: "
<< (
m1
-
m2
).squaredNorm() << endl;
16
cout <<
"Squared euclidean distance, using map: "
<<
17
(
m1
-
m2map
).squaredNorm() << endl;
18
m2map
(3) = 7;
// this will change m2, since they share the same array
19
cout <<
"Updated m2: "
<<
m2
<< endl;
20
cout <<
"m2 coefficient 2, constant accessor: "
<<
m2mapconst
(2) << endl;
21
/* m2mapconst(2) = 5; */
// this yields a compile-time error
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
n_dims
const int n_dims
Definition:
Tutorial_Map_using.cpp:4
MapTypeConst
Map< const MatrixType > MapTypeConst
Definition:
Tutorial_Map_using.cpp:3
m2
MatrixType m2(n_dims)
m2mapconst
MapTypeConst m2mapconst(p, m2.size())
MatrixType
Matrix< float, 1, Dynamic > MatrixType
Definition:
Tutorial_Map_using.cpp:1
m2map
MapType m2map(p, m2.size())
p
float * p
Definition:
Tutorial_Map_using.cpp:9
MapType
Map< MatrixType > MapType
Definition:
Tutorial_Map_using.cpp:2
m1
MatrixType m1(n_dims)
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:18:19