| 62 | |
| 63 | template<typename VectorType> |
| 64 | void testVectorType(const VectorType& base) |
| 65 | { |
| 66 | typedef typename VectorType::Scalar Scalar; |
| 67 | typedef typename VectorType::RealScalar RealScalar; |
| 68 | |
| 69 | const Index size = base.size(); |
| 70 | |
| 71 | Scalar high = internal::random<Scalar>(-500,500); |
| 72 | Scalar low = (size == 1 ? high : internal::random<Scalar>(-500,500)); |
| 73 | if (low>high) std::swap(low,high); |
| 74 | |
| 75 | // check low==high |
| 76 | if(internal::random<float>(0.f,1.f)<0.05f) |
| 77 | low = high; |
| 78 | // check abs(low) >> abs(high) |
| 79 | else if(size>2 && std::numeric_limits<RealScalar>::max_exponent10>0 && internal::random<float>(0.f,1.f)<0.1f) |
| 80 | low = -internal::random<Scalar>(1,2) * RealScalar(std::pow(RealScalar(10),std::numeric_limits<RealScalar>::max_exponent10/2)); |
| 81 | |
| 82 | const Scalar step = ((size == 1) ? 1 : (high-low)/(size-1)); |
| 83 | |
| 84 | // check whether the result yields what we expect it to do |
| 85 | VectorType m(base); |
| 86 | m.setLinSpaced(size,low,high); |
| 87 | |
| 88 | if(!NumTraits<Scalar>::IsInteger) |
| 89 | { |
| 90 | VectorType n(size); |
| 91 | for (int i=0; i<size; ++i) |
| 92 | n(i) = low+i*step; |
| 93 | VERIFY_IS_APPROX(m,n); |
| 94 | |
| 95 | CALL_SUBTEST( check_extremity_accuracy(m, low, high) ); |
| 96 | } |
| 97 | |
| 98 | if((!NumTraits<Scalar>::IsInteger) || ((high-low)>=size && (Index(high-low)%(size-1))==0) || (Index(high-low+1)<size && (size%Index(high-low+1))==0)) |
| 99 | { |
| 100 | VectorType n(size); |
| 101 | if((!NumTraits<Scalar>::IsInteger) || (high-low>=size)) |
| 102 | for (int i=0; i<size; ++i) |
| 103 | n(i) = size==1 ? low : (low + ((high-low)*Scalar(i))/(size-1)); |
| 104 | else |
| 105 | for (int i=0; i<size; ++i) |
| 106 | n(i) = size==1 ? low : low + Scalar((double(high-low+1)*double(i))/double(size)); |
| 107 | VERIFY_IS_APPROX(m,n); |
| 108 | |
| 109 | // random access version |
| 110 | m = VectorType::LinSpaced(size,low,high); |
| 111 | VERIFY_IS_APPROX(m,n); |
| 112 | VERIFY( internal::isApprox(m(m.size()-1),high) ); |
| 113 | VERIFY( size==1 || internal::isApprox(m(0),low) ); |
| 114 | VERIFY_IS_EQUAL(m(m.size()-1) , high); |
| 115 | if(!NumTraits<Scalar>::IsInteger) |
| 116 | CALL_SUBTEST( check_extremity_accuracy(m, low, high) ); |
| 117 | } |
| 118 | |
| 119 | VERIFY( m(m.size()-1) <= high ); |
| 120 | VERIFY( (m.array() <= high).all() ); |
| 121 | VERIFY( (m.array() >= low).all() ); |