From 8f031a3cee9336ecc3fac1134da90a3d77866192 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 8 Jun 2015 15:43:41 +0200 Subject: [PATCH] bug #997: add missing evaluators for m.lazyProduct(v.homogeneous()) --- Eigen/src/Geometry/Homogeneous.h | 62 ++++++++++++++++++++++++++++++++ test/geo_homogeneous.cpp | 15 ++++++++ 2 files changed, 77 insertions(+) diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 756ecf9dc..b7f996615 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -365,6 +365,37 @@ struct generic_product_impl, Rhs, HomogeneousShap } }; +template +struct homogeneous_right_product_refactoring_helper +{ + enum { + Dim = Lhs::ColsAtCompileTime, + Rows = Lhs::RowsAtCompileTime + }; + typedef typename Rhs::template ConstNRowsBlockXpr::Type LinearBlockConst; + typedef typename remove_const::type LinearBlock; + typedef typename Rhs::ConstRowXpr ConstantColumn; + typedef Replicate ConstantBlock; + typedef Product LinearProduct; + typedef CwiseBinaryOp, const LinearProduct, const ConstantBlock> Xpr; +}; + +template +struct product_evaluator, ProductTag, HomogeneousShape, DenseShape> + : public evaluator::Xpr> +{ + typedef Product XprType; + typedef homogeneous_right_product_refactoring_helper helper; + typedef typename helper::ConstantBlock ConstantBlock; + typedef typename helper::Xpr RefactoredXpr; + typedef evaluator Base; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) + : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows(xpr.lhs().nestedExpression().cols()) ) + + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) ) + {} +}; + template struct generic_product_impl, DenseShape, HomogeneousShape, ProductTag> { @@ -375,6 +406,37 @@ struct generic_product_impl, DenseShape, Homog } }; +template +struct homogeneous_left_product_refactoring_helper +{ + enum { + Dim = Rhs::RowsAtCompileTime, + Cols = Rhs::ColsAtCompileTime + }; + typedef typename Lhs::template ConstNColsBlockXpr::Type LinearBlockConst; + typedef typename remove_const::type LinearBlock; + typedef typename Lhs::ConstColXpr ConstantColumn; + typedef Replicate ConstantBlock; + typedef Product LinearProduct; + typedef CwiseBinaryOp, const LinearProduct, const ConstantBlock> Xpr; +}; + +template +struct product_evaluator, ProductTag, DenseShape, HomogeneousShape> + : public evaluator::Xpr> +{ + typedef Product XprType; + typedef homogeneous_left_product_refactoring_helper helper; + typedef typename helper::ConstantBlock ConstantBlock; + typedef typename helper::Xpr RefactoredXpr; + typedef evaluator Base; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) + : Base( xpr.lhs().template leftCols(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() ) + + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) ) + {} +}; + template struct generic_product_impl, Homogeneous, DenseShape, HomogeneousShape, ProductTag> { diff --git a/test/geo_homogeneous.cpp b/test/geo_homogeneous.cpp index 2f9d18c0f..bf63c69ec 100644 --- a/test/geo_homogeneous.cpp +++ b/test/geo_homogeneous.cpp @@ -94,6 +94,21 @@ template void homogeneous(void) VERIFY_IS_APPROX((aff * pts2).colwise().hnormalized(), aff * pts2.colwise().hnormalized()); VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized()); VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized()); + + // Test combination of homogeneous + + VERIFY_IS_APPROX( (t2 * v0.homogeneous()).hnormalized(), + (t2.template topLeftCorner() * v0 + t2.template topRightCorner()) + / ((t2.template bottomLeftCorner<1,Size>()*v0).value() + t2(Size,Size)) ); + + VERIFY_IS_APPROX( (t2 * pts.colwise().homogeneous()).colwise().hnormalized(), + (Matrix(t2 * pts1).colwise().hnormalized()) ); + + VERIFY_IS_APPROX( (t2 .lazyProduct( v0.homogeneous() )).hnormalized(), (t2 * v0.homogeneous()).hnormalized() ); + VERIFY_IS_APPROX( (t2 .lazyProduct ( pts.colwise().homogeneous() )).colwise().hnormalized(), (t2 * pts1).colwise().hnormalized() ); + + VERIFY_IS_APPROX( (v0.transpose().homogeneous() .lazyProduct( t2 )).hnormalized(), (v0.transpose().homogeneous()*t2).hnormalized() ); + VERIFY_IS_APPROX( (pts.transpose().rowwise().homogeneous() .lazyProduct( t2 )).rowwise().hnormalized(), (pts1.transpose()*t2).rowwise().hnormalized() ); } void test_geo_homogeneous()