diff options
author | Hauke Heibel <hauke.heibel@gmail.com> | 2010-03-13 14:33:39 +0100 |
---|---|---|
committer | Hauke Heibel <hauke.heibel@gmail.com> | 2010-03-13 14:33:39 +0100 |
commit | fc20e6fd5579bd88d519083037376bd1f96781cd (patch) | |
tree | 6867e1b83b80e57c4feee568fe657c3d4e9d3caf /Eigen | |
parent | b9644f332330a7242fa13e8194e87ba4b5678f58 (diff) |
Try to avoid modulo operations in Replicate if possible.
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Array/Replicate.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Eigen/src/Array/Replicate.h b/Eigen/src/Array/Replicate.h index cd23e0d6f..31fc28c35 100644 --- a/Eigen/src/Array/Replicate.h +++ b/Eigen/src/Array/Replicate.h @@ -76,7 +76,7 @@ template<typename MatrixType,int RowFactor,int ColFactor> class Replicate THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) ei_assert(RowFactor!=Dynamic && ColFactor!=Dynamic); } - + template<typename OriginalMatrixType> inline Replicate(const OriginalMatrixType& matrix, int rowFactor, int colFactor) : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) @@ -90,7 +90,14 @@ template<typename MatrixType,int RowFactor,int ColFactor> class Replicate inline Scalar coeff(int row, int col) const { - return m_matrix.coeff(row%m_matrix.rows(), col%m_matrix.cols()); + // try to avoid using modulo; this is a pure optimization strategy + // - it is assumed unlikely that RowFactor==1 && ColFactor==1 + if (RowFactor==1) + return m_matrix.coeff(m_matrix.rows(), col%m_matrix.cols()); + else if (ColFactor==1) + return m_matrix.coeff(row%m_matrix.rows(), m_matrix.cols()); + else + return m_matrix.coeff(row%m_matrix.rows(), col%m_matrix.cols()); } protected: |