mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-16 14:49:39 +08:00
bug #1383: fix regression in LinSpaced for integers and high<low
This commit is contained in:
parent
296d24be4d
commit
850ca961d2
@ -93,8 +93,8 @@ struct linspaced_op_impl<Scalar,Packet,/*IsInteger*/true>
|
||||
linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
|
||||
m_low(low),
|
||||
m_multiplier((high-low)/convert_index<Scalar>(num_steps<=1 ? 1 : num_steps-1)),
|
||||
m_divisor(convert_index<Scalar>(num_steps+high-low)/((high-low+1)==0?1:(high-low+1))),
|
||||
m_use_divisor((high+1)<(low+num_steps))
|
||||
m_divisor(convert_index<Scalar>((high>=low?num_steps:-num_steps)+(high-low))/((numext::abs(high-low)+1)==0?1:(numext::abs(high-low)+1))),
|
||||
m_use_divisor(num_steps>1 && (numext::abs(high-low)+1)<num_steps)
|
||||
{}
|
||||
|
||||
template<typename IndexType>
|
||||
|
@ -175,6 +175,21 @@ void testVectorType(const VectorType& base)
|
||||
VERIFY_IS_APPROX(VectorType::LinSpaced(size,low,low),VectorType::Constant(size,low));
|
||||
m.setLinSpaced(size,low,low);
|
||||
VERIFY_IS_APPROX(m,VectorType::Constant(size,low));
|
||||
|
||||
if(NumTraits<Scalar>::IsInteger)
|
||||
{
|
||||
VERIFY_IS_APPROX( VectorType::LinSpaced(size,low,Scalar(low+size-1)), VectorType::LinSpaced(size,Scalar(low+size-1),low).reverse() );
|
||||
|
||||
if(VectorType::SizeAtCompileTime==Dynamic)
|
||||
{
|
||||
// Check negative multiplicator path:
|
||||
for(Index k=1; k<5; ++k)
|
||||
VERIFY_IS_APPROX( VectorType::LinSpaced(size,low,Scalar(low+(size-1)*k)), VectorType::LinSpaced(size,Scalar(low+(size-1)*k),low).reverse() );
|
||||
// Check negative divisor path:
|
||||
for(Index k=1; k<5; ++k)
|
||||
VERIFY_IS_APPROX( VectorType::LinSpaced(size*k,low,Scalar(low+size-1)), VectorType::LinSpaced(size*k,Scalar(low+size-1),low).reverse() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +237,8 @@ void test_nullary()
|
||||
CALL_SUBTEST_8( testVectorType(Matrix<float,8,1>()) );
|
||||
CALL_SUBTEST_8( testVectorType(Matrix<float,1,1>()) );
|
||||
|
||||
CALL_SUBTEST_9( testVectorType(VectorXi(internal::random<int>(1,300))) );
|
||||
CALL_SUBTEST_9( testVectorType(VectorXi(internal::random<int>(1,10))) );
|
||||
CALL_SUBTEST_9( testVectorType(VectorXi(internal::random<int>(9,300))) );
|
||||
CALL_SUBTEST_9( testVectorType(Matrix<int,1,1>()) );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user