From d536fef1bb44280bb96bbdc5418c033f17f982a8 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 15 Mar 2010 10:39:00 +0100 Subject: [PATCH] fix and extend replicate optimization, and add the packet method though it is currently disabled --- Eigen/src/Array/Replicate.h | 30 ++++++++++++++++++++++-------- 1 file 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 class Replicate THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) ei_assert(RowFactor!=Dynamic && ColFactor!=Dynamic); } - + template inline Replicate(const OriginalMatrixType& matrix, int rowFactor, int colFactor) : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) @@ -91,14 +91,28 @@ template 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::RowsAtCompileTime==1 ? 0 + : RowFactor==1 ? row + : row%m_matrix.rows(); + const int actual_col = ei_traits::ColsAtCompileTime==1 ? 0 + : ColFactor==1 ? col + : col%m_matrix.cols(); + + return m_matrix.coeff(actual_row, actual_col); } + template + inline PacketScalar packet(int row, int col) const + { + const int actual_row = ei_traits::RowsAtCompileTime==1 ? 0 + : RowFactor==1 ? row + : row%m_matrix.rows(); + const int actual_col = ei_traits::ColsAtCompileTime==1 ? 0 + : ColFactor==1 ? col + : col%m_matrix.cols(); + + return m_matrix.template packet(actual_row, actual_col); + } + protected: const typename MatrixType::Nested m_matrix;