diff options
author | Gael Guennebaud <g.gael@free.fr> | 2016-02-06 22:49:18 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2016-02-06 22:49:18 +0100 |
commit | 010afe1619c9200b885f74d3c3937e000ec76b1d (patch) | |
tree | c8e8fbbc9137501aac17bb7b7acf78db8754331b /doc/snippets | |
parent | 8e599bc098cef7030004489dca2b9dab920f2cc8 (diff) |
Add exemples for reshaping/slicing with Map.
Diffstat (limited to 'doc/snippets')
-rw-r--r-- | doc/snippets/Tutorial_ReshapeMat2Mat.cpp | 6 | ||||
-rw-r--r-- | doc/snippets/Tutorial_ReshapeMat2Vec.cpp | 11 | ||||
-rw-r--r-- | doc/snippets/Tutorial_SlicingCol.cpp | 11 | ||||
-rw-r--r-- | doc/snippets/Tutorial_SlicingVec.cpp | 4 |
4 files changed, 32 insertions, 0 deletions
diff --git a/doc/snippets/Tutorial_ReshapeMat2Mat.cpp b/doc/snippets/Tutorial_ReshapeMat2Mat.cpp new file mode 100644 index 000000000..f84d6e76d --- /dev/null +++ b/doc/snippets/Tutorial_ReshapeMat2Mat.cpp @@ -0,0 +1,6 @@ +MatrixXf M1(2,6); // Column-major storage +M1 << 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12; + +Map<MatrixXf> M2(M1.data(), 6,2); +cout << "M2:" << endl << M2 << endl;
\ No newline at end of file diff --git a/doc/snippets/Tutorial_ReshapeMat2Vec.cpp b/doc/snippets/Tutorial_ReshapeMat2Vec.cpp new file mode 100644 index 000000000..95bd4e0e6 --- /dev/null +++ b/doc/snippets/Tutorial_ReshapeMat2Vec.cpp @@ -0,0 +1,11 @@ +MatrixXf M1(3,3); // Column-major storage +M1 << 1, 2, 3, + 4, 5, 6, + 7, 8, 9; + +Map<RowVectorXf> v1(M1.data(), M1.size()); +cout << "v1:" << endl << v1 << endl; + +Matrix<float,Dynamic,Dynamic,RowMajor> M2(M1); +Map<RowVectorXf> v2(M2.data(), M2.size()); +cout << "v2:" << endl << v2 << endl;
\ No newline at end of file diff --git a/doc/snippets/Tutorial_SlicingCol.cpp b/doc/snippets/Tutorial_SlicingCol.cpp new file mode 100644 index 000000000..f667ff689 --- /dev/null +++ b/doc/snippets/Tutorial_SlicingCol.cpp @@ -0,0 +1,11 @@ +MatrixXf M1 = MatrixXf::Random(3,8); +cout << "Column major input:" << endl << M1 << "\n"; +Map<MatrixXf,0,OuterStride<> > M2(M1.data(), M1.rows(), (M1.cols()+2)/3, OuterStride<>(M1.outerStride()*3)); +cout << "1 column over 3:" << endl << M2 << "\n"; + +typedef Matrix<float,Dynamic,Dynamic,RowMajor> RowMajorMatrixXf; +RowMajorMatrixXf M3(M1); +cout << "Row major input:" << endl << M3 << "\n"; +Map<RowMajorMatrixXf,0,Stride<Dynamic,3> > M4(M3.data(), M3.rows(), (M3.cols()+2)/3, + Stride<Dynamic,3>(M3.outerStride(),3)); +cout << "1 column over 3:" << endl << M4 << "\n";
\ No newline at end of file diff --git a/doc/snippets/Tutorial_SlicingVec.cpp b/doc/snippets/Tutorial_SlicingVec.cpp new file mode 100644 index 000000000..07e10bf69 --- /dev/null +++ b/doc/snippets/Tutorial_SlicingVec.cpp @@ -0,0 +1,4 @@ +RowVectorXf v = RowVectorXf::LinSpaced(20,0,19); +cout << "Input:" << endl << v << endl; +Map<RowVectorXf,0,InnerStride<2> > v2(v.data(), v.size()/2); +cout << "Even:" << v2 << endl;
\ No newline at end of file |