diff options
author | Gael Guennebaud <g.gael@free.fr> | 2015-06-08 15:43:41 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2015-06-08 15:43:41 +0200 |
commit | 8f031a3cee9336ecc3fac1134da90a3d77866192 (patch) | |
tree | 2e111171cdce6cd1ee1263e4d44026f969b89951 | |
parent | e6c5723dcdf81154c9d1bc0f7e4a1a18f2a4ef98 (diff) |
bug #997: add missing evaluators for m.lazyProduct(v.homogeneous())
-rw-r--r-- | Eigen/src/Geometry/Homogeneous.h | 62 | ||||
-rw-r--r-- | test/geo_homogeneous.cpp | 15 |
2 files changed, 77 insertions, 0 deletions
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<Homogeneous<LhsArg,Horizontal>, Rhs, HomogeneousShap } }; +template<typename Lhs,typename Rhs> +struct homogeneous_right_product_refactoring_helper +{ + enum { + Dim = Lhs::ColsAtCompileTime, + Rows = Lhs::RowsAtCompileTime + }; + typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst; + typedef typename remove_const<LinearBlockConst>::type LinearBlock; + typedef typename Rhs::ConstRowXpr ConstantColumn; + typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock; + typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct; + typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr; +}; + +template<typename Lhs, typename Rhs, int ProductTag> +struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape> + : public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr> +{ + typedef Product<Lhs, Rhs, LazyProduct> XprType; + typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper; + typedef typename helper::ConstantBlock ConstantBlock; + typedef typename helper::Xpr RefactoredXpr; + typedef evaluator<RefactoredXpr> Base; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) + : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols()) ) + + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) ) + {} +}; + template<typename Lhs, typename RhsArg, int ProductTag> struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag> { @@ -375,6 +406,37 @@ struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, Homog } }; +template<typename Lhs,typename Rhs> +struct homogeneous_left_product_refactoring_helper +{ + enum { + Dim = Rhs::RowsAtCompileTime, + Cols = Rhs::ColsAtCompileTime + }; + typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst; + typedef typename remove_const<LinearBlockConst>::type LinearBlock; + typedef typename Lhs::ConstColXpr ConstantColumn; + typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock; + typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct; + typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr; +}; + +template<typename Lhs, typename Rhs, int ProductTag> +struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape> + : public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr> +{ + typedef Product<Lhs, Rhs, LazyProduct> XprType; + typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper; + typedef typename helper::ConstantBlock ConstantBlock; + typedef typename helper::Xpr RefactoredXpr; + typedef evaluator<RefactoredXpr> Base; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) + : Base( xpr.lhs().template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() ) + + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) ) + {} +}; + template<typename Scalar, int Dim, int Mode,int Options, typename RhsArg, int ProductTag> struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,Vertical>, 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<typename Scalar,int Size> 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<Size,Size>() * v0 + t2.template topRightCorner<Size,1>()) + / ((t2.template bottomLeftCorner<1,Size>()*v0).value() + t2(Size,Size)) ); + + VERIFY_IS_APPROX( (t2 * pts.colwise().homogeneous()).colwise().hnormalized(), + (Matrix<Scalar, Size+1, Dynamic>(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() |