diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 41ae4af42..052bcc35c 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -549,6 +549,7 @@ struct ei_linspaced_op_impl template EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return m_low+i*m_step; } + template EIGEN_STRONG_INLINE const Packet packetOp(Index i) const { return ei_padd(m_lowPacket, ei_pmul(m_stepPacket, ei_padd(ei_pset1(i),m_interPacket))); } @@ -572,10 +573,31 @@ template struct ei_linspaced_op { typedef typename ei_packet_traits::type Packet; ei_linspaced_op(Scalar low, Scalar high, int num_steps) : impl(low, (high-low)/(num_steps-1)) {} + template - EIGEN_STRONG_INLINE const Scalar operator() (Index i, Index = 0) const { return impl(i); } + EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); } + + // We need this function when assigning e.g. a RowVectorXd to a MatrixXd since + // there row==0 and col is used for the actual iteration. template - EIGEN_STRONG_INLINE const Packet packetOp(Index i, Index = 0) const { return impl.packetOp(i); } + EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col) const + { + ei_assert(col==0 || row==0); + return impl(col + row); + } + + template + EIGEN_STRONG_INLINE const Packet packetOp(Index i) const { return impl.packetOp(i); } + + // We need this function when assigning e.g. a RowVectorXd to a MatrixXd since + // there row==0 and col is used for the actual iteration. + template + EIGEN_STRONG_INLINE const Packet packetOp(Index row, Index col) const + { + ei_assert(col==0 || row==0); + return impl(col + row); + } + // This proxy object handles the actual required temporaries, the different // implementations (random vs. sequential access) as well as the // correct piping to size 2/4 packet operations. diff --git a/test/nullary.cpp b/test/nullary.cpp index 78d2e9117..b0a416b25 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -71,6 +71,9 @@ void testVectorType(const VectorType& base) m = VectorType::LinSpaced(size,low,high); VERIFY( (m-n).norm() < std::numeric_limits::epsilon()*10e3 ); + // Assignment of a RowVectorXd to a MatrixXd (regression test for bug #79). + VERIFY( (MatrixXd(RowVectorXd::LinSpaced(3, 0, 1)) - RowVector3d(0, 0.5, 1)).norm() < std::numeric_limits::epsilon() ); + // These guys sometimes fail! This is not good. Any ideas how to fix them!? //VERIFY( m(m.size()-1) == high ); //VERIFY( m(0) == low );