Rev | Line | |
---|
[136] | 1 | #include <Eigen/Dense>
|
---|
| 2 | #include <iostream>
|
---|
| 3 |
|
---|
| 4 | using namespace Eigen;
|
---|
| 5 | using namespace std;
|
---|
| 6 |
|
---|
| 7 | int main(int, char**)
|
---|
| 8 | {
|
---|
| 9 | cout.precision(3);
|
---|
| 10 | typedef Matrix<float,1,Dynamic> MatrixType;
|
---|
| 11 | typedef Map<MatrixType> MapType;
|
---|
| 12 | typedef Map<const MatrixType> MapTypeConst; // a read-only map
|
---|
| 13 | const int n_dims = 5;
|
---|
| 14 |
|
---|
| 15 | MatrixType m1(n_dims), m2(n_dims);
|
---|
| 16 | m1.setRandom();
|
---|
| 17 | m2.setRandom();
|
---|
| 18 | float *p = &m2(0); // get the address storing the data for m2
|
---|
| 19 | MapType m2map(p,m2.size()); // m2map shares data with m2
|
---|
| 20 | MapTypeConst m2mapconst(p,m2.size()); // a read-only accessor for m2
|
---|
| 21 |
|
---|
| 22 | cout << "m1: " << m1 << endl;
|
---|
| 23 | cout << "m2: " << m2 << endl;
|
---|
| 24 | cout << "Squared euclidean distance: " << (m1-m2).squaredNorm() << endl;
|
---|
| 25 | cout << "Squared euclidean distance, using map: " <<
|
---|
| 26 | (m1-m2map).squaredNorm() << endl;
|
---|
| 27 | m2map(3) = 7; // this will change m2, since they share the same array
|
---|
| 28 | cout << "Updated m2: " << m2 << endl;
|
---|
| 29 | cout << "m2 coefficient 2, constant accessor: " << m2mapconst(2) << endl;
|
---|
| 30 | /* m2mapconst(2) = 5; */ // this yields a compile-time error
|
---|
| 31 |
|
---|
| 32 | return 0;
|
---|
| 33 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.