This bugzilla service is closed. All entries have been migrated to
Bug 1778 - Add matlab's repelem equivalent
Summary: Add matlab's repelem equivalent
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.4 (development)
Hardware: All All
: Normal Feature Request
Assignee: Nobody
Depends on:
Reported: 2019-11-14 16:41 UTC by Gael Guennebaud
Modified: 2019-12-04 18:55 UTC (History)
3 users (show)


Description Gael Guennebaud 2019-11-14 16:41:29 UTC
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(

Full demo:

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)?
Comment 1 Nobody 2019-12-04 18:55:44 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to'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:

Note You need to log in before you can comment on or make changes to this bug.