mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-18 14:34:17 +08:00
Improved the unit tests for setLinSpaced.
Provide a default constructed step size as opposed to an int when the size is 1.
This commit is contained in:
parent
ef022da28e
commit
c08521ea6b
@ -628,7 +628,7 @@ template <typename Scalar, bool RandomAccess> struct functor_traits< linspaced_o
|
||||
template <typename Scalar, bool RandomAccess> struct linspaced_op
|
||||
{
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
linspaced_op(Scalar low, Scalar high, int num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? 1 : (high-low)/(num_steps-1))) {}
|
||||
linspaced_op(Scalar low, Scalar high, int num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/(num_steps-1))) {}
|
||||
|
||||
template<typename Index>
|
||||
EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); }
|
||||
|
@ -52,11 +52,14 @@ void testVectorType(const VectorType& base)
|
||||
{
|
||||
typedef typename internal::traits<VectorType>::Index Index;
|
||||
typedef typename internal::traits<VectorType>::Scalar Scalar;
|
||||
Scalar low = internal::random<Scalar>(-500,500);
|
||||
Scalar high = internal::random<Scalar>(-500,500);
|
||||
if (low>high) std::swap(low,high);
|
||||
|
||||
const Index size = base.size();
|
||||
const Scalar step = (high-low)/(size-1);
|
||||
|
||||
Scalar high = internal::random<Scalar>(-500,500);
|
||||
Scalar low = (size == 1 ? high : internal::random<Scalar>(-500,500));
|
||||
if (low>high) std::swap(low,high);
|
||||
|
||||
const Scalar step = ((size == 1) ? 1 : (high-low)/(size-1));
|
||||
|
||||
// check whether the result yields what we expect it to do
|
||||
VectorType m(base);
|
||||
@ -130,5 +133,6 @@ void test_nullary()
|
||||
CALL_SUBTEST_6( testVectorType(Vector3d()) );
|
||||
CALL_SUBTEST_7( testVectorType(VectorXf(internal::random<int>(1,300))) );
|
||||
CALL_SUBTEST_8( testVectorType(Vector3f()) );
|
||||
CALL_SUBTEST_8( testVectorType(Matrix<float,1,1>()) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user