eigen/doc/examples/class_Block.cpp

26 lines
746 B
C++
Raw Normal View History

#include <Eigen/Core>
#include <iostream>
template<typename Derived>
2008-01-14 07:38:48 +08:00
Eigen::Block<Derived>
topLeftCorner(Eigen::MatrixBase<Derived>& m, int rows, int cols)
{
return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
}
template<typename Derived>
2011-02-07 01:43:01 +08:00
const Eigen::Block<const Derived>
topLeftCorner(const Eigen::MatrixBase<Derived>& m, int rows, int cols)
{
2011-02-07 01:43:01 +08:00
return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
}
int main(int, char**)
{
Eigen::Matrix4d m = Eigen::Matrix4d::Identity();
std::cout << topLeftCorner(4*m, 2, 3) << std::endl; // calls the const version
2008-01-14 07:38:48 +08:00
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
return 0;
}