MCPcopy Create free account
hub / github.com/Derious/cuMPC / testVectorType

Function testVectorType

dependence/eigen-3.4.0/test/nullary.cpp:64–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63template<typename VectorType>
64void 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 (numext::real(low)>numext::real(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)/RealScalar(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+RealScalar(i)*step;
93 VERIFY_IS_APPROX(m,n);
94
95 CALL_SUBTEST( check_extremity_accuracy(m, low, high) );
96 }
97
98 RealScalar range_length = numext::real(high-low);
99 if((!NumTraits<Scalar>::IsInteger) || (range_length>=size && (Index(range_length)%(size-1))==0) || (Index(range_length+1)<size && (size%Index(range_length+1))==0))
100 {
101 VectorType n(size);
102 if((!NumTraits<Scalar>::IsInteger) || (range_length>=size))
103 for (int i=0; i<size; ++i)
104 n(i) = size==1 ? low : (low + ((high-low)*Scalar(i))/RealScalar(size-1));
105 else
106 for (int i=0; i<size; ++i)
107 n(i) = size==1 ? low : low + Scalar((double(range_length+1)*double(i))/double(size));
108 VERIFY_IS_APPROX(m,n);
109
110 // random access version
111 m = VectorType::LinSpaced(size,low,high);
112 VERIFY_IS_APPROX(m,n);
113 VERIFY( internal::isApprox(m(m.size()-1),high) );
114 VERIFY( size==1 || internal::isApprox(m(0),low) );
115 VERIFY_IS_EQUAL(m(m.size()-1) , high);
116 if(!NumTraits<Scalar>::IsInteger)
117 CALL_SUBTEST( check_extremity_accuracy(m, low, high) );
118 }
119
120 VERIFY( numext::real(m(m.size()-1)) <= numext::real(high) );
121 VERIFY( (m.array().real() <= numext::real(high)).all() );

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 15

check_extremity_accuracyFunction · 0.85
realMethod · 0.80
realClass · 0.70
swapFunction · 0.70
powFunction · 0.50
nFunction · 0.50
isApproxFunction · 0.50
mFunction · 0.50
sizeMethod · 0.45
allMethod · 0.45
arrayMethod · 0.45
isApproxMethod · 0.45

Tested by

no test coverage detected