diff options
author | Gael Guennebaud <g.gael@free.fr> | 2010-03-15 10:39:00 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2010-03-15 10:39:00 +0100 |
commit | d536fef1bb44280bb96bbdc5418c033f17f982a8 (patch) | |
tree | cb8cdba4febc72697afefc65d6f55def16c4e798 /Eigen | |
parent | d68b85744f82e879b555e72d90cc8feefd96c2c0 (diff) |
fix and extend replicate optimization, and add the packet method though it is currently disabled
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Array/Replicate.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/Eigen/src/Array/Replicate.h b/Eigen/src/Array/Replicate.h index 31fc28c35..661a7b561 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) @@ -91,15 +91,29 @@ template<typename MatrixType,int RowFactor,int ColFactor> class Replicate inline Scalar coeff(int row, int col) const { // 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()); + const int actual_row = ei_traits<MatrixType>::RowsAtCompileTime==1 ? 0 + : RowFactor==1 ? row + : row%m_matrix.rows(); + const int actual_col = ei_traits<MatrixType>::ColsAtCompileTime==1 ? 0 + : ColFactor==1 ? col + : col%m_matrix.cols(); + + return m_matrix.coeff(actual_row, actual_col); + } + template<int LoadMode> + inline PacketScalar packet(int row, int col) const + { + const int actual_row = ei_traits<MatrixType>::RowsAtCompileTime==1 ? 0 + : RowFactor==1 ? row + : row%m_matrix.rows(); + const int actual_col = ei_traits<MatrixType>::ColsAtCompileTime==1 ? 0 + : ColFactor==1 ? col + : col%m_matrix.cols(); + + return m_matrix.template packet<LoadMode>(actual_row, actual_col); } + protected: const typename MatrixType::Nested m_matrix; const ei_int_if_dynamic<RowFactor> m_rowFactor; |