diff --git a/test/packetmath.cpp b/test/packetmath.cpp index e6d0ef7bd..9218b6736 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -29,16 +29,38 @@ template T ei_negate(const T& x) { return -x; } +template bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits::Real& refvalue) +{ + return ei_isMuchSmallerThan(a-b, refvalue); +} + +template bool areApproxAbs(const Scalar* a, const Scalar* b, int size, const typename NumTraits::Real& refvalue) +{ + for (int i=0; i bool areApprox(const Scalar* a, const Scalar* b, int size) { for (int i=0; i inline Packet load(const T* from) const { return ei_pload(from); } - + template inline void store(T* to, const Packet& x) const { ei_pstore(to,x); } }; @@ -68,7 +90,7 @@ struct packet_helper { template inline T load(const T* from) const { return *from; } - + template inline void store(T* to, const T& x) const { *to = x; } }; @@ -100,16 +122,19 @@ template void packetmath() { typedef typename ei_packet_traits::type Packet; const int PacketSize = ei_packet_traits::size; + typedef typename NumTraits::Real RealScalar; const int size = PacketSize*4; EIGEN_ALIGN16 Scalar data1[ei_packet_traits::size*4]; EIGEN_ALIGN16 Scalar data2[ei_packet_traits::size*4]; EIGEN_ALIGN16 Packet packets[PacketSize*2]; EIGEN_ALIGN16 Scalar ref[ei_packet_traits::size*4]; + RealScalar refvalue = 0; for (int i=0; i(); data2[i] = ei_random(); + refvalue = std::max(refvalue,ei_abs(data1[i])); } ei_pstore(data2, ei_pload(data1)); @@ -166,7 +191,7 @@ template void packetmath() ref[0] = 0; for (int i=0; i void packetmath() packets[j] = ei_pload(data1+j*PacketSize); } ei_pstore(data2, ei_preduxp(packets)); - VERIFY(areApprox(ref, data2, PacketSize) && "ei_preduxp"); + VERIFY(areApproxAbs(ref, data2, PacketSize, refvalue) && "ei_preduxp"); for (int i=0; i void packetmath_real() EIGEN_ALIGN16 Scalar data1[ei_packet_traits::size*4]; EIGEN_ALIGN16 Scalar data2[ei_packet_traits::size*4]; EIGEN_ALIGN16 Scalar ref[ei_packet_traits::size*4]; - + for (int i=0; i(-1e3,1e3); @@ -216,14 +241,14 @@ template void packetmath_real() } CHECK_CWISE1_IF(ei_packet_traits::HasSin, ei_sin, ei_psin); CHECK_CWISE1_IF(ei_packet_traits::HasCos, ei_cos, ei_pcos); - + for (int i=0; i(-87,88); data2[i] = ei_random(-87,88); } CHECK_CWISE1_IF(ei_packet_traits::HasExp, ei_exp, ei_pexp); - + for (int i=0; i(0,1e6); @@ -240,7 +265,7 @@ void test_packetmath() CALL_SUBTEST_2( packetmath() ); CALL_SUBTEST_3( packetmath() ); CALL_SUBTEST_1( packetmath >() ); - + CALL_SUBTEST_1( packetmath_real() ); CALL_SUBTEST_2( packetmath_real() ); }