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



Attachments

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(
        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)?
Comment 1 Nobody 2019-12-04 18:55:44 UTC
-- 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.

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