From c6f610093bff10c5a6e4fac94bfed422ba54b39a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 5 Jul 2009 11:33:55 +0200 Subject: add a VectorBlock expr as a specialization of Block --- doc/examples/class_FixedVectorBlock.cpp | 26 ++++++++++++++++++++++++++ doc/examples/class_VectorBlock.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 doc/examples/class_FixedVectorBlock.cpp create mode 100644 doc/examples/class_VectorBlock.cpp (limited to 'doc/examples') diff --git a/doc/examples/class_FixedVectorBlock.cpp b/doc/examples/class_FixedVectorBlock.cpp new file mode 100644 index 000000000..c176be495 --- /dev/null +++ b/doc/examples/class_FixedVectorBlock.cpp @@ -0,0 +1,26 @@ +#include +USING_PART_OF_NAMESPACE_EIGEN +using namespace std; + +template +Eigen::VectorBlock +firstTwo(MatrixBase& v) +{ + return Eigen::VectorBlock(v.derived(), 0); +} + +template +const Eigen::VectorBlock +firstTwo(const MatrixBase& v) +{ + return Eigen::VectorBlock(v.derived(), 0); +} + +int main(int, char**) +{ + Matrix v; v << 1,2,3,4,5,6; + cout << firstTwo(4*v) << endl; // calls the const version + firstTwo(v) *= 2; // calls the non-const version + cout << "Now the vector v is:" << endl << v << endl; + return 0; +} diff --git a/doc/examples/class_VectorBlock.cpp b/doc/examples/class_VectorBlock.cpp new file mode 100644 index 000000000..d979f973a --- /dev/null +++ b/doc/examples/class_VectorBlock.cpp @@ -0,0 +1,26 @@ +#include +USING_PART_OF_NAMESPACE_EIGEN +using namespace std; + +template +Eigen::VectorBlock +segmentFromRange(MatrixBase& v, int start, int end) +{ + return Eigen::VectorBlock(v.derived(), start, end-start); +} + +template +const Eigen::VectorBlock +segmentFromRange(const MatrixBase& v, int start, int end) +{ + return Eigen::VectorBlock(v.derived(), start, end-start); +} + +int main(int, char**) +{ + Matrix v; v << 1,2,3,4,5,6; + cout << segmentFromRange(2*v, 2, 4) << endl; // calls the const version + segmentFromRange(v, 1, 3) *= 5; // calls the non-const version + cout << "Now the vector v is:" << endl << v << endl; + return 0; +} -- cgit v1.2.3