Homogeneous.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef EIGEN_HOMOGENEOUS_H
  10. #define EIGEN_HOMOGENEOUS_H
  11. namespace Eigen {
  12. /** \geometry_module \ingroup Geometry_Module
  13. *
  14. * \class Homogeneous
  15. *
  16. * \brief Expression of one (or a set of) homogeneous vector(s)
  17. *
  18. * \param MatrixType the type of the object in which we are making homogeneous
  19. *
  20. * This class represents an expression of one (or a set of) homogeneous vector(s).
  21. * It is the return type of MatrixBase::homogeneous() and most of the time
  22. * this is the only way it is used.
  23. *
  24. * \sa MatrixBase::homogeneous()
  25. */
  26. namespace internal {
  27. template<typename MatrixType,int Direction>
  28. struct traits<Homogeneous<MatrixType,Direction> >
  29. : traits<MatrixType>
  30. {
  31. typedef typename traits<MatrixType>::StorageKind StorageKind;
  32. typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
  33. typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
  34. enum {
  35. RowsPlusOne = (MatrixType::RowsAtCompileTime != Dynamic) ?
  36. int(MatrixType::RowsAtCompileTime) + 1 : Dynamic,
  37. ColsPlusOne = (MatrixType::ColsAtCompileTime != Dynamic) ?
  38. int(MatrixType::ColsAtCompileTime) + 1 : Dynamic,
  39. RowsAtCompileTime = Direction==Vertical ? RowsPlusOne : MatrixType::RowsAtCompileTime,
  40. ColsAtCompileTime = Direction==Horizontal ? ColsPlusOne : MatrixType::ColsAtCompileTime,
  41. MaxRowsAtCompileTime = RowsAtCompileTime,
  42. MaxColsAtCompileTime = ColsAtCompileTime,
  43. TmpFlags = _MatrixTypeNested::Flags & HereditaryBits,
  44. Flags = ColsAtCompileTime==1 ? (TmpFlags & ~RowMajorBit)
  45. : RowsAtCompileTime==1 ? (TmpFlags | RowMajorBit)
  46. : TmpFlags
  47. };
  48. };
  49. template<typename MatrixType,typename Lhs> struct homogeneous_left_product_impl;
  50. template<typename MatrixType,typename Rhs> struct homogeneous_right_product_impl;
  51. } // end namespace internal
  52. template<typename MatrixType,int _Direction> class Homogeneous
  53. : public MatrixBase<Homogeneous<MatrixType,_Direction> >, internal::no_assignment_operator
  54. {
  55. public:
  56. typedef MatrixType NestedExpression;
  57. enum { Direction = _Direction };
  58. typedef MatrixBase<Homogeneous> Base;
  59. EIGEN_DENSE_PUBLIC_INTERFACE(Homogeneous)
  60. EIGEN_DEVICE_FUNC explicit inline Homogeneous(const MatrixType& matrix)
  61. : m_matrix(matrix)
  62. {}
  63. EIGEN_DEVICE_FUNC inline Index rows() const { return m_matrix.rows() + (int(Direction)==Vertical ? 1 : 0); }
  64. EIGEN_DEVICE_FUNC inline Index cols() const { return m_matrix.cols() + (int(Direction)==Horizontal ? 1 : 0); }
  65. EIGEN_DEVICE_FUNC const NestedExpression& nestedExpression() const { return m_matrix; }
  66. template<typename Rhs>
  67. EIGEN_DEVICE_FUNC inline const Product<Homogeneous,Rhs>
  68. operator* (const MatrixBase<Rhs>& rhs) const
  69. {
  70. eigen_assert(int(Direction)==Horizontal);
  71. return Product<Homogeneous,Rhs>(*this,rhs.derived());
  72. }
  73. template<typename Lhs> friend
  74. EIGEN_DEVICE_FUNC inline const Product<Lhs,Homogeneous>
  75. operator* (const MatrixBase<Lhs>& lhs, const Homogeneous& rhs)
  76. {
  77. eigen_assert(int(Direction)==Vertical);
  78. return Product<Lhs,Homogeneous>(lhs.derived(),rhs);
  79. }
  80. template<typename Scalar, int Dim, int Mode, int Options> friend
  81. EIGEN_DEVICE_FUNC inline const Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous >
  82. operator* (const Transform<Scalar,Dim,Mode,Options>& lhs, const Homogeneous& rhs)
  83. {
  84. eigen_assert(int(Direction)==Vertical);
  85. return Product<Transform<Scalar,Dim,Mode,Options>, Homogeneous>(lhs,rhs);
  86. }
  87. template<typename Func>
  88. EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::result_of<Func(Scalar,Scalar)>::type
  89. redux(const Func& func) const
  90. {
  91. return func(m_matrix.redux(func), Scalar(1));
  92. }
  93. protected:
  94. typename MatrixType::Nested m_matrix;
  95. };
  96. /** \geometry_module \ingroup Geometry_Module
  97. *
  98. * \returns a vector expression that is one longer than the vector argument, with the value 1 symbolically appended as the last coefficient.
  99. *
  100. * This can be used to convert affine coordinates to homogeneous coordinates.
  101. *
  102. * \only_for_vectors
  103. *
  104. * Example: \include MatrixBase_homogeneous.cpp
  105. * Output: \verbinclude MatrixBase_homogeneous.out
  106. *
  107. * \sa VectorwiseOp::homogeneous(), class Homogeneous
  108. */
  109. template<typename Derived>
  110. EIGEN_DEVICE_FUNC inline typename MatrixBase<Derived>::HomogeneousReturnType
  111. MatrixBase<Derived>::homogeneous() const
  112. {
  113. EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
  114. return HomogeneousReturnType(derived());
  115. }
  116. /** \geometry_module \ingroup Geometry_Module
  117. *
  118. * \returns an expression where the value 1 is symbolically appended as the final coefficient to each column (or row) of the matrix.
  119. *
  120. * This can be used to convert affine coordinates to homogeneous coordinates.
  121. *
  122. * Example: \include VectorwiseOp_homogeneous.cpp
  123. * Output: \verbinclude VectorwiseOp_homogeneous.out
  124. *
  125. * \sa MatrixBase::homogeneous(), class Homogeneous */
  126. template<typename ExpressionType, int Direction>
  127. EIGEN_DEVICE_FUNC inline Homogeneous<ExpressionType,Direction>
  128. VectorwiseOp<ExpressionType,Direction>::homogeneous() const
  129. {
  130. return HomogeneousReturnType(_expression());
  131. }
  132. /** \geometry_module \ingroup Geometry_Module
  133. *
  134. * \brief homogeneous normalization
  135. *
  136. * \returns a vector expression of the N-1 first coefficients of \c *this divided by that last coefficient.
  137. *
  138. * This can be used to convert homogeneous coordinates to affine coordinates.
  139. *
  140. * It is essentially a shortcut for:
  141. * \code
  142. this->head(this->size()-1)/this->coeff(this->size()-1);
  143. \endcode
  144. *
  145. * Example: \include MatrixBase_hnormalized.cpp
  146. * Output: \verbinclude MatrixBase_hnormalized.out
  147. *
  148. * \sa VectorwiseOp::hnormalized() */
  149. template<typename Derived>
  150. EIGEN_DEVICE_FUNC inline const typename MatrixBase<Derived>::HNormalizedReturnType
  151. MatrixBase<Derived>::hnormalized() const
  152. {
  153. EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived);
  154. return ConstStartMinusOne(derived(),0,0,
  155. ColsAtCompileTime==1?size()-1:1,
  156. ColsAtCompileTime==1?1:size()-1) / coeff(size()-1);
  157. }
  158. /** \geometry_module \ingroup Geometry_Module
  159. *
  160. * \brief column or row-wise homogeneous normalization
  161. *
  162. * \returns an expression of the first N-1 coefficients of each column (or row) of \c *this divided by the last coefficient of each column (or row).
  163. *
  164. * This can be used to convert homogeneous coordinates to affine coordinates.
  165. *
  166. * It is conceptually equivalent to calling MatrixBase::hnormalized() to each column (or row) of \c *this.
  167. *
  168. * Example: \include DirectionWise_hnormalized.cpp
  169. * Output: \verbinclude DirectionWise_hnormalized.out
  170. *
  171. * \sa MatrixBase::hnormalized() */
  172. template<typename ExpressionType, int Direction>
  173. EIGEN_DEVICE_FUNC inline const typename VectorwiseOp<ExpressionType,Direction>::HNormalizedReturnType
  174. VectorwiseOp<ExpressionType,Direction>::hnormalized() const
  175. {
  176. return HNormalized_Block(_expression(),0,0,
  177. Direction==Vertical ? _expression().rows()-1 : _expression().rows(),
  178. Direction==Horizontal ? _expression().cols()-1 : _expression().cols()).cwiseQuotient(
  179. Replicate<HNormalized_Factors,
  180. Direction==Vertical ? HNormalized_SizeMinusOne : 1,
  181. Direction==Horizontal ? HNormalized_SizeMinusOne : 1>
  182. (HNormalized_Factors(_expression(),
  183. Direction==Vertical ? _expression().rows()-1:0,
  184. Direction==Horizontal ? _expression().cols()-1:0,
  185. Direction==Vertical ? 1 : _expression().rows(),
  186. Direction==Horizontal ? 1 : _expression().cols()),
  187. Direction==Vertical ? _expression().rows()-1 : 1,
  188. Direction==Horizontal ? _expression().cols()-1 : 1));
  189. }
  190. namespace internal {
  191. template<typename MatrixOrTransformType>
  192. struct take_matrix_for_product
  193. {
  194. typedef MatrixOrTransformType type;
  195. EIGEN_DEVICE_FUNC static const type& run(const type &x) { return x; }
  196. };
  197. template<typename Scalar, int Dim, int Mode,int Options>
  198. struct take_matrix_for_product<Transform<Scalar, Dim, Mode, Options> >
  199. {
  200. typedef Transform<Scalar, Dim, Mode, Options> TransformType;
  201. typedef typename internal::add_const<typename TransformType::ConstAffinePart>::type type;
  202. EIGEN_DEVICE_FUNC static type run (const TransformType& x) { return x.affine(); }
  203. };
  204. template<typename Scalar, int Dim, int Options>
  205. struct take_matrix_for_product<Transform<Scalar, Dim, Projective, Options> >
  206. {
  207. typedef Transform<Scalar, Dim, Projective, Options> TransformType;
  208. typedef typename TransformType::MatrixType type;
  209. EIGEN_DEVICE_FUNC static const type& run (const TransformType& x) { return x.matrix(); }
  210. };
  211. template<typename MatrixType,typename Lhs>
  212. struct traits<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
  213. {
  214. typedef typename take_matrix_for_product<Lhs>::type LhsMatrixType;
  215. typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
  216. typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
  217. typedef typename make_proper_matrix_type<
  218. typename traits<MatrixTypeCleaned>::Scalar,
  219. LhsMatrixTypeCleaned::RowsAtCompileTime,
  220. MatrixTypeCleaned::ColsAtCompileTime,
  221. MatrixTypeCleaned::PlainObject::Options,
  222. LhsMatrixTypeCleaned::MaxRowsAtCompileTime,
  223. MatrixTypeCleaned::MaxColsAtCompileTime>::type ReturnType;
  224. };
  225. template<typename MatrixType,typename Lhs>
  226. struct homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>
  227. : public ReturnByValue<homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
  228. {
  229. typedef typename traits<homogeneous_left_product_impl>::LhsMatrixType LhsMatrixType;
  230. typedef typename remove_all<LhsMatrixType>::type LhsMatrixTypeCleaned;
  231. typedef typename remove_all<typename LhsMatrixTypeCleaned::Nested>::type LhsMatrixTypeNested;
  232. EIGEN_DEVICE_FUNC homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs)
  233. : m_lhs(take_matrix_for_product<Lhs>::run(lhs)),
  234. m_rhs(rhs)
  235. {}
  236. EIGEN_DEVICE_FUNC inline Index rows() const { return m_lhs.rows(); }
  237. EIGEN_DEVICE_FUNC inline Index cols() const { return m_rhs.cols(); }
  238. template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
  239. {
  240. // FIXME investigate how to allow lazy evaluation of this product when possible
  241. dst = Block<const LhsMatrixTypeNested,
  242. LhsMatrixTypeNested::RowsAtCompileTime,
  243. LhsMatrixTypeNested::ColsAtCompileTime==Dynamic?Dynamic:LhsMatrixTypeNested::ColsAtCompileTime-1>
  244. (m_lhs,0,0,m_lhs.rows(),m_lhs.cols()-1) * m_rhs;
  245. dst += m_lhs.col(m_lhs.cols()-1).rowwise()
  246. .template replicate<MatrixType::ColsAtCompileTime>(m_rhs.cols());
  247. }
  248. typename LhsMatrixTypeCleaned::Nested m_lhs;
  249. typename MatrixType::Nested m_rhs;
  250. };
  251. template<typename MatrixType,typename Rhs>
  252. struct traits<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
  253. {
  254. typedef typename make_proper_matrix_type<typename traits<MatrixType>::Scalar,
  255. MatrixType::RowsAtCompileTime,
  256. Rhs::ColsAtCompileTime,
  257. MatrixType::PlainObject::Options,
  258. MatrixType::MaxRowsAtCompileTime,
  259. Rhs::MaxColsAtCompileTime>::type ReturnType;
  260. };
  261. template<typename MatrixType,typename Rhs>
  262. struct homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs>
  263. : public ReturnByValue<homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
  264. {
  265. typedef typename remove_all<typename Rhs::Nested>::type RhsNested;
  266. EIGEN_DEVICE_FUNC homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs)
  267. : m_lhs(lhs), m_rhs(rhs)
  268. {}
  269. EIGEN_DEVICE_FUNC inline Index rows() const { return m_lhs.rows(); }
  270. EIGEN_DEVICE_FUNC inline Index cols() const { return m_rhs.cols(); }
  271. template<typename Dest> EIGEN_DEVICE_FUNC void evalTo(Dest& dst) const
  272. {
  273. // FIXME investigate how to allow lazy evaluation of this product when possible
  274. dst = m_lhs * Block<const RhsNested,
  275. RhsNested::RowsAtCompileTime==Dynamic?Dynamic:RhsNested::RowsAtCompileTime-1,
  276. RhsNested::ColsAtCompileTime>
  277. (m_rhs,0,0,m_rhs.rows()-1,m_rhs.cols());
  278. dst += m_rhs.row(m_rhs.rows()-1).colwise()
  279. .template replicate<MatrixType::RowsAtCompileTime>(m_lhs.rows());
  280. }
  281. typename MatrixType::Nested m_lhs;
  282. typename Rhs::Nested m_rhs;
  283. };
  284. template<typename ArgType,int Direction>
  285. struct evaluator_traits<Homogeneous<ArgType,Direction> >
  286. {
  287. typedef typename storage_kind_to_evaluator_kind<typename ArgType::StorageKind>::Kind Kind;
  288. typedef HomogeneousShape Shape;
  289. };
  290. template<> struct AssignmentKind<DenseShape,HomogeneousShape> { typedef Dense2Dense Kind; };
  291. template<typename ArgType,int Direction>
  292. struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased>
  293. : evaluator<typename Homogeneous<ArgType,Direction>::PlainObject >
  294. {
  295. typedef Homogeneous<ArgType,Direction> XprType;
  296. typedef typename XprType::PlainObject PlainObject;
  297. typedef evaluator<PlainObject> Base;
  298. EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op)
  299. : Base(), m_temp(op)
  300. {
  301. ::new (static_cast<Base*>(this)) Base(m_temp);
  302. }
  303. protected:
  304. PlainObject m_temp;
  305. };
  306. // dense = homogeneous
  307. template< typename DstXprType, typename ArgType, typename Scalar>
  308. struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
  309. {
  310. typedef Homogeneous<ArgType,Vertical> SrcXprType;
  311. EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
  312. {
  313. Index dstRows = src.rows();
  314. Index dstCols = src.cols();
  315. if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
  316. dst.resize(dstRows, dstCols);
  317. dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
  318. dst.row(dst.rows()-1).setOnes();
  319. }
  320. };
  321. // dense = homogeneous
  322. template< typename DstXprType, typename ArgType, typename Scalar>
  323. struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar,typename ArgType::Scalar>, Dense2Dense>
  324. {
  325. typedef Homogeneous<ArgType,Horizontal> SrcXprType;
  326. EIGEN_DEVICE_FUNC static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,typename ArgType::Scalar> &)
  327. {
  328. Index dstRows = src.rows();
  329. Index dstCols = src.cols();
  330. if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
  331. dst.resize(dstRows, dstCols);
  332. dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();
  333. dst.col(dst.cols()-1).setOnes();
  334. }
  335. };
  336. template<typename LhsArg, typename Rhs, int ProductTag>
  337. struct generic_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs, HomogeneousShape, DenseShape, ProductTag>
  338. {
  339. template<typename Dest>
  340. EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Homogeneous<LhsArg,Horizontal>& lhs, const Rhs& rhs)
  341. {
  342. homogeneous_right_product_impl<Homogeneous<LhsArg,Horizontal>, Rhs>(lhs.nestedExpression(), rhs).evalTo(dst);
  343. }
  344. };
  345. template<typename Lhs,typename Rhs>
  346. struct homogeneous_right_product_refactoring_helper
  347. {
  348. enum {
  349. Dim = Lhs::ColsAtCompileTime,
  350. Rows = Lhs::RowsAtCompileTime
  351. };
  352. typedef typename Rhs::template ConstNRowsBlockXpr<Dim>::Type LinearBlockConst;
  353. typedef typename remove_const<LinearBlockConst>::type LinearBlock;
  354. typedef typename Rhs::ConstRowXpr ConstantColumn;
  355. typedef Replicate<const ConstantColumn,Rows,1> ConstantBlock;
  356. typedef Product<Lhs,LinearBlock,LazyProduct> LinearProduct;
  357. typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
  358. };
  359. template<typename Lhs, typename Rhs, int ProductTag>
  360. struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, HomogeneousShape, DenseShape>
  361. : public evaluator<typename homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs>::Xpr>
  362. {
  363. typedef Product<Lhs, Rhs, LazyProduct> XprType;
  364. typedef homogeneous_right_product_refactoring_helper<typename Lhs::NestedExpression,Rhs> helper;
  365. typedef typename helper::ConstantBlock ConstantBlock;
  366. typedef typename helper::Xpr RefactoredXpr;
  367. typedef evaluator<RefactoredXpr> Base;
  368. EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
  369. : Base( xpr.lhs().nestedExpression() .lazyProduct( xpr.rhs().template topRows<helper::Dim>(xpr.lhs().nestedExpression().cols()) )
  370. + ConstantBlock(xpr.rhs().row(xpr.rhs().rows()-1),xpr.lhs().rows(), 1) )
  371. {}
  372. };
  373. template<typename Lhs, typename RhsArg, int ProductTag>
  374. struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
  375. {
  376. template<typename Dest>
  377. EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
  378. {
  379. homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, Lhs>(lhs, rhs.nestedExpression()).evalTo(dst);
  380. }
  381. };
  382. // TODO: the following specialization is to address a regression from 3.2 to 3.3
  383. // In the future, this path should be optimized.
  384. template<typename Lhs, typename RhsArg, int ProductTag>
  385. struct generic_product_impl<Lhs, Homogeneous<RhsArg,Vertical>, TriangularShape, HomogeneousShape, ProductTag>
  386. {
  387. template<typename Dest>
  388. static void evalTo(Dest& dst, const Lhs& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
  389. {
  390. dst.noalias() = lhs * rhs.eval();
  391. }
  392. };
  393. template<typename Lhs,typename Rhs>
  394. struct homogeneous_left_product_refactoring_helper
  395. {
  396. enum {
  397. Dim = Rhs::RowsAtCompileTime,
  398. Cols = Rhs::ColsAtCompileTime
  399. };
  400. typedef typename Lhs::template ConstNColsBlockXpr<Dim>::Type LinearBlockConst;
  401. typedef typename remove_const<LinearBlockConst>::type LinearBlock;
  402. typedef typename Lhs::ConstColXpr ConstantColumn;
  403. typedef Replicate<const ConstantColumn,1,Cols> ConstantBlock;
  404. typedef Product<LinearBlock,Rhs,LazyProduct> LinearProduct;
  405. typedef CwiseBinaryOp<internal::scalar_sum_op<typename Lhs::Scalar,typename Rhs::Scalar>, const LinearProduct, const ConstantBlock> Xpr;
  406. };
  407. template<typename Lhs, typename Rhs, int ProductTag>
  408. struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, HomogeneousShape>
  409. : public evaluator<typename homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression>::Xpr>
  410. {
  411. typedef Product<Lhs, Rhs, LazyProduct> XprType;
  412. typedef homogeneous_left_product_refactoring_helper<Lhs,typename Rhs::NestedExpression> helper;
  413. typedef typename helper::ConstantBlock ConstantBlock;
  414. typedef typename helper::Xpr RefactoredXpr;
  415. typedef evaluator<RefactoredXpr> Base;
  416. EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr)
  417. : Base( xpr.lhs().template leftCols<helper::Dim>(xpr.rhs().nestedExpression().rows()) .lazyProduct( xpr.rhs().nestedExpression() )
  418. + ConstantBlock(xpr.lhs().col(xpr.lhs().cols()-1),1,xpr.rhs().cols()) )
  419. {}
  420. };
  421. template<typename Scalar, int Dim, int Mode,int Options, typename RhsArg, int ProductTag>
  422. struct generic_product_impl<Transform<Scalar,Dim,Mode,Options>, Homogeneous<RhsArg,Vertical>, DenseShape, HomogeneousShape, ProductTag>
  423. {
  424. typedef Transform<Scalar,Dim,Mode,Options> TransformType;
  425. template<typename Dest>
  426. EIGEN_DEVICE_FUNC static void evalTo(Dest& dst, const TransformType& lhs, const Homogeneous<RhsArg,Vertical>& rhs)
  427. {
  428. homogeneous_left_product_impl<Homogeneous<RhsArg,Vertical>, TransformType>(lhs, rhs.nestedExpression()).evalTo(dst);
  429. }
  430. };
  431. template<typename ExpressionType, int Side, bool Transposed>
  432. struct permutation_matrix_product<ExpressionType, Side, Transposed, HomogeneousShape>
  433. : public permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
  434. {};
  435. } // end namespace internal
  436. } // end namespace Eigen
  437. #endif // EIGEN_HOMOGENEOUS_H