diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2013-02-18 17:26:03 +0000 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2013-02-18 17:26:03 +0000 |
commit | b4f6aec19561c73c09077f5aff88854b42fb4a49 (patch) | |
tree | 76cc3ad5e382f1858420361e31a955910f589ae2 | |
parent | 1a056b408db75ef082b658ba0e5ff726a99018bb (diff) |
Fix linear vectorized transversal in linspace (fixes bug #526).
-rw-r--r-- | Eigen/src/Core/Functors.h | 14 | ||||
-rw-r--r-- | test/nullary.cpp | 6 |
2 files changed, 17 insertions, 3 deletions
diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index e54a49808..f54c574e2 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -541,8 +541,11 @@ template <typename Scalar, bool RandomAccess> struct linspaced_op_impl; // linear access for packet ops: // 1) initialization // base = [low, ..., low] + ([step, ..., step] * [-size, ..., 0]) -// 2) each step +// 2) each step (where size is 1 for coeff access or PacketSize for packet access) // base += [size*step, ..., size*step] +// +// TODO: Perhaps it's better to initialize lazily (so not in the constructor but in packetOp) +// in order to avoid the padd() in operator() ? template <typename Scalar> struct linspaced_op_impl<Scalar,false> { @@ -551,10 +554,15 @@ struct linspaced_op_impl<Scalar,false> linspaced_op_impl(Scalar low, Scalar step) : m_low(low), m_step(step), m_packetStep(pset1<Packet>(packet_traits<Scalar>::size*step)), - m_base(padd(pset1<Packet>(low),pmul(pset1<Packet>(step),plset<Scalar>(-packet_traits<Scalar>::size)))) {} + m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(step),plset<Scalar>(-packet_traits<Scalar>::size)))) {} template<typename Index> - EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return m_low+i*m_step; } + EIGEN_STRONG_INLINE const Scalar operator() (Index i) const + { + m_base = padd(m_base, pset1<Packet>(m_step)); + return m_low+i*m_step; + } + template<typename Index> EIGEN_STRONG_INLINE const Packet packetOp(Index) const { return m_base = padd(m_base,m_packetStep); } diff --git a/test/nullary.cpp b/test/nullary.cpp index 1220e3f97..5408d88b2 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -91,6 +91,12 @@ void testVectorType(const VectorType& base) scalar.setLinSpaced(1,low,high); VERIFY_IS_APPROX( scalar, ScalarMatrix::Constant(high) ); VERIFY_IS_APPROX( ScalarMatrix::LinSpaced(1,low,high), ScalarMatrix::Constant(high) ); + + // regression test for bug 526 (linear vectorized transversal) + if (size > 1) { + m.tail(size-1).setLinSpaced(low, high); + VERIFY_IS_APPROX(m(size-1), high); + } } template<typename MatrixType> |