mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add a generic block() method compatible with Eigen::fix
This commit is contained in:
@@ -29,6 +29,13 @@ block_real_only(const MatrixType &, Index, Index, Index, Index, const Scalar&) {
|
||||
return Scalar(0);
|
||||
}
|
||||
|
||||
// Check at compile-time that T1==T2, and at runtime-time that a==b
|
||||
template<typename T1,typename T2>
|
||||
typename internal::enable_if<internal::is_same<T1,T2>::value,bool>::type
|
||||
is_same_block(const T1& a, const T2& b)
|
||||
{
|
||||
return a.isApprox(b);
|
||||
}
|
||||
|
||||
template<typename MatrixType> void block(const MatrixType& m)
|
||||
{
|
||||
@@ -106,6 +113,11 @@ template<typename MatrixType> void block(const MatrixType& m)
|
||||
m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols)(0,3) = m1.template block<2,5>(1,1)(1,2);
|
||||
Matrix<Scalar,Dynamic,Dynamic> b2 = m1.template block<Dynamic,BlockCols>(3,3,2,5);
|
||||
VERIFY_IS_EQUAL(b2, m1.block(3,3,BlockRows,BlockCols));
|
||||
|
||||
VERIFY(is_same_block(m1.block(3,3,BlockRows,BlockCols), m1.block(3,3,fix<Dynamic>(BlockRows),fix<Dynamic>(BlockCols))));
|
||||
VERIFY(is_same_block(m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols), m1.block(1,1,fix<BlockRows>,BlockCols)));
|
||||
VERIFY(is_same_block(m1.template block<BlockRows,BlockCols>(1,1,BlockRows,BlockCols), m1.block(1,1,fix<BlockRows>(),fix<BlockCols>)));
|
||||
VERIFY(is_same_block(m1.template block<BlockRows,BlockCols>(1,1,BlockRows,BlockCols), m1.block(1,1,fix<BlockRows>,fix<BlockCols>(BlockCols))));
|
||||
}
|
||||
|
||||
if (rows>2)
|
||||
|
||||
@@ -49,7 +49,7 @@ bool match(const T& xpr, std::string ref, std::string str_xpr = "") {
|
||||
|
||||
template<typename T1,typename T2>
|
||||
typename internal::enable_if<internal::is_same<T1,T2>::value,bool>::type
|
||||
is_same_type(const T1& a, const T2& b)
|
||||
is_same_eq(const T1& a, const T2& b)
|
||||
{
|
||||
return (a == b).all();
|
||||
}
|
||||
@@ -219,25 +219,25 @@ void check_indexed_view()
|
||||
|
||||
// Check fall-back to Block
|
||||
{
|
||||
VERIFY( is_same_type(A.col(0), A(all,0)) );
|
||||
VERIFY( is_same_type(A.row(0), A(0,all)) );
|
||||
VERIFY( is_same_type(A.block(0,0,2,2), A(seqN(0,2),seq(0,1))) );
|
||||
VERIFY( is_same_type(A.middleRows(2,4), A(seqN(2,4),all)) );
|
||||
VERIFY( is_same_type(A.middleCols(2,4), A(all,seqN(2,4))) );
|
||||
VERIFY( is_same_eq(A.col(0), A(all,0)) );
|
||||
VERIFY( is_same_eq(A.row(0), A(0,all)) );
|
||||
VERIFY( is_same_eq(A.block(0,0,2,2), A(seqN(0,2),seq(0,1))) );
|
||||
VERIFY( is_same_eq(A.middleRows(2,4), A(seqN(2,4),all)) );
|
||||
VERIFY( is_same_eq(A.middleCols(2,4), A(all,seqN(2,4))) );
|
||||
|
||||
VERIFY( is_same_type(A.col(A.cols()-1), A(all,last)) );
|
||||
VERIFY( is_same_eq(A.col(A.cols()-1), A(all,last)) );
|
||||
|
||||
const ArrayXXi& cA(A);
|
||||
VERIFY( is_same_type(cA.col(0), cA(all,0)) );
|
||||
VERIFY( is_same_type(cA.row(0), cA(0,all)) );
|
||||
VERIFY( is_same_type(cA.block(0,0,2,2), cA(seqN(0,2),seq(0,1))) );
|
||||
VERIFY( is_same_type(cA.middleRows(2,4), cA(seqN(2,4),all)) );
|
||||
VERIFY( is_same_type(cA.middleCols(2,4), cA(all,seqN(2,4))) );
|
||||
VERIFY( is_same_eq(cA.col(0), cA(all,0)) );
|
||||
VERIFY( is_same_eq(cA.row(0), cA(0,all)) );
|
||||
VERIFY( is_same_eq(cA.block(0,0,2,2), cA(seqN(0,2),seq(0,1))) );
|
||||
VERIFY( is_same_eq(cA.middleRows(2,4), cA(seqN(2,4),all)) );
|
||||
VERIFY( is_same_eq(cA.middleCols(2,4), cA(all,seqN(2,4))) );
|
||||
|
||||
VERIFY( is_same_type(a.head(4), a(seq(0,3))) );
|
||||
VERIFY( is_same_type(a.tail(4), a(seqN(last-3,4))) );
|
||||
VERIFY( is_same_type(a.tail(4), a(seq(end-4,last))) );
|
||||
VERIFY( is_same_type(a.segment<4>(3), a(seqN(3,fix<4>))) );
|
||||
VERIFY( is_same_eq(a.head(4), a(seq(0,3))) );
|
||||
VERIFY( is_same_eq(a.tail(4), a(seqN(last-3,4))) );
|
||||
VERIFY( is_same_eq(a.tail(4), a(seq(end-4,last))) );
|
||||
VERIFY( is_same_eq(a.segment<4>(3), a(seqN(3,fix<4>))) );
|
||||
}
|
||||
|
||||
ArrayXXi A1=A, A2 = ArrayXXi::Random(4,4);
|
||||
@@ -275,6 +275,18 @@ void check_indexed_view()
|
||||
VERIFY_IS_APPROX( A(legacy::seq(legacy::last,2,-2), legacy::seq(legacy::last-6,7)), A(seq(last,2,-2), seq(last-6,7)) );
|
||||
VERIFY_IS_APPROX( A(seqN(legacy::last,2,-2), seqN(legacy::last-6,3)), A(seqN(last,2,-2), seqN(last-6,3)) );
|
||||
|
||||
// check extended block API
|
||||
{
|
||||
VERIFY( is_same_eq( A.block<3,4>(1,1), A.block(1,1,fix<3>,fix<4>)) );
|
||||
VERIFY( is_same_eq( A.block<3,4>(1,1,3,4), A.block(1,1,fix<3>(),fix<4>(4))) );
|
||||
VERIFY( is_same_eq( A.block<3,Dynamic>(1,1,3,4), A.block(1,1,fix<3>,4)) );
|
||||
VERIFY( is_same_eq( A.block<Dynamic,4>(1,1,3,4), A.block(1,1,fix<Dynamic>(3),fix<4>)) );
|
||||
VERIFY( is_same_eq( A.block(1,1,3,4), A.block(1,1,fix<Dynamic>(3),fix<Dynamic>(4))) );
|
||||
|
||||
const ArrayXXi& cA(A);
|
||||
VERIFY( is_same_eq( cA.block<Dynamic,4>(1,1,3,4), cA.block(1,1,fix<Dynamic>(3),fix<4>)) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test_indexed_view()
|
||||
@@ -282,5 +294,6 @@ void test_indexed_view()
|
||||
// for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_1( check_indexed_view() );
|
||||
CALL_SUBTEST_2( check_indexed_view() );
|
||||
CALL_SUBTEST_3( check_indexed_view() );
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user