diff --git a/Eigen/src/Core/functors/NullaryFunctors.h b/Eigen/src/Core/functors/NullaryFunctors.h index 71629af4c..c5836d048 100644 --- a/Eigen/src/Core/functors/NullaryFunctors.h +++ b/Eigen/src/Core/functors/NullaryFunctors.h @@ -99,24 +99,24 @@ template struct linspaced_op_impl { linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) : - m_low(low), m_length(high-low), m_numSteps(num_steps), m_interPacket(plset(0)) + m_low(low), m_length(high-low), m_divisor(num_steps==1?1:num_steps-1), m_interPacket(plset(0)) {} template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { - return m_low + (m_length*Scalar(i))/(m_numSteps-1); + return m_low + (m_length*Scalar(i))/m_divisor; } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(Index i) const { return internal::padd(pset1(m_low), pdiv(pmul(pset1(m_length), padd(pset1(Scalar(i)),m_interPacket)), - pset1(m_numSteps-1))); } + pset1(m_divisor))); } const Scalar m_low; const Scalar m_length; - const Index m_numSteps; + const Index m_divisor; const Packet m_interPacket; }; diff --git a/test/nullary.cpp b/test/nullary.cpp index 8d65910eb..cb87695ee 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -130,6 +130,7 @@ void test_nullary() CALL_SUBTEST_8( testVectorType(Matrix()) ); CALL_SUBTEST_9( testVectorType(VectorXi(internal::random(1,300))) ); + CALL_SUBTEST_9( testVectorType(Matrix()) ); } #ifdef EIGEN_TEST_PART_6