bug #1004: one more rewrite of LinSpaced for floating point numbers to guarantee both interpolation and monotonicity.

This version simply does low+i*step plus a branch to return high if i==size-1.
Vectorization is accomplished with a branch and the help of pinsertlast.
Some quick benchmark revealed that the overhead is really marginal, even when filling small vectors.
This commit is contained in:
Gael Guennebaud
2016-10-25 16:53:09 +02:00
parent 13fc18d3a2
commit 58146be99b
2 changed files with 45 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ bool equalsIdentity(const MatrixType& A)
bool diagOK = (A.diagonal().array() == 1).all();
return offDiagOK && diagOK;
}
template<typename VectorType>
@@ -43,6 +44,10 @@ void testVectorType(const VectorType& base)
Scalar low = (size == 1 ? high : internal::random<Scalar>(-500,500));
if (low>high) std::swap(low,high);
// check low==high
if(internal::random<float>(0.f,1.f)<0.05f)
low = high;
const Scalar step = ((size == 1) ? 1 : (high-low)/(size-1));
// check whether the result yields what we expect it to do
@@ -77,6 +82,8 @@ void testVectorType(const VectorType& base)
}
VERIFY( m(m.size()-1) <= high );
VERIFY( (m.array() <= high).all() );
VERIFY( (m.array() >= low).all() );
VERIFY( m(m.size()-1) >= low );