This is a frequently asked feature. Thanks to IndexedView, we can easily implement it as: template<typename XprType, typename RowFactorType, typename ColFactorType> auto repelem(const XprType &xpr, RowFactorType row_factor, ColFactorType col_factor) { using namespace Eigen; const int RowFactor = internal::get_fixed_value<RowFactorType>::value; const int ColFactor = internal::get_fixed_value<ColFactorType>::value; const int NRows = XprType::RowsAtCompileTime == Dynamic || RowFactor == Dynamic ? Dynamic : XprType::RowsAtCompileTime*RowFactor; const int NCols = XprType::ColsAtCompileTime == Dynamic || ColFactor == Dynamic ? Dynamic : XprType::ColsAtCompileTime*ColFactor; const int nrows = internal::get_runtime_value(row_factor) * xpr.rows(); const int ncols = internal::get_runtime_value(col_factor) * xpr.cols(); return xpr( Array<int,NRows,1>::LinSpaced(nrows,0,xpr.rows()-1), Array<int,NCols,1>::LinSpaced(ncols,0,xpr.cols()-1) ); } Full demo: https://godbolt.org/z/rYgDxF This can easily be turned as a member function and specialized for Horizontal or Vertical replication only. What would be a good name given that we already have "replicate" as an equivalent to "repmat" ? Can we do better than the above implementation if using a dedicated expression (as for replicate)?
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1778.