Speed up UnitTestMath.

This commit is contained in:
Nick Thompson 2021-04-09 19:21:25 -04:00
parent 1b11348cc3
commit bdc73333c9

@ -130,8 +130,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestArcTan2() const
{
// std::cout << "Testing arc tan 2" << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(0.0), T(1.0)), T(0.0)), "ATan2 x+ axis.");
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(1.0), T(0.0)), T(0.5 * vtkm::Pi())),
"ATan2 y+ axis.");
@ -151,7 +149,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestPow() const
{
// std::cout << "Running power tests." << std::endl;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
T x = static_cast<T>(Lists{}.NumberList(index));
@ -164,7 +161,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestLog2() const
{
// std::cout << "Testing Log2" << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::Log2(T(0.25)), T(-2.0)), "Bad value from Log2");
VTKM_MATH_ASSERT(test_equal(vtkm::Log2(vtkm::Vec<T, 4>(0.5, 1.0, 2.0, 4.0)),
vtkm::Vec<T, 4>(-1.0, 0.0, 1.0, 2.0)),
@ -174,8 +170,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestNonFinites() const
{
// std::cout << "Testing non-finites." << std::endl;
T zero = 0.0;
T finite = 1.0;
T nan = vtkm::Nan<T>();
@ -227,7 +221,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestRemainders() const
{
// std::cout << "Testing remainders." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
@ -251,7 +244,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestRound() const
{
// std::cout << "Testing round." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
{
@ -274,7 +266,6 @@ struct ScalarFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestIsNegative() const
{
// std::cout << "Testing SignBit and IsNegative." << std::endl;
T x = 0;
VTKM_MATH_ASSERT(vtkm::SignBit(x) == 0, "SignBit wrong for 0.");
VTKM_MATH_ASSERT(!vtkm::IsNegative(x), "IsNegative wrong for 0.");
@ -333,7 +324,6 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestTriangleTrig() const
{
// std::cout << "Testing normal trig functions." << std::endl;
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
{
@ -386,8 +376,6 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void TestHyperbolicTrig() const
{
// std::cout << "Testing hyperbolic trig functions." << std::endl;
const VectorType zero(0);
Lists table;
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
@ -441,11 +429,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Sqrt(x); }
};
VTKM_EXEC
void TestSqrt() const
{
// std::cout << " Testing Sqrt" << std::endl;
RaiseToTest(SqrtFunctor(), 0.5);
}
void TestSqrt() const { RaiseToTest(SqrtFunctor(), 0.5); }
struct RSqrtFunctor
{
@ -453,11 +437,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::RSqrt(x); }
};
VTKM_EXEC
void TestRSqrt() const
{
// std::cout << " Testing RSqrt"<< std::endl;
RaiseToTest(RSqrtFunctor(), -0.5);
}
void TestRSqrt() const { RaiseToTest(RSqrtFunctor(), -0.5); }
struct CbrtFunctor
{
@ -465,11 +445,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Cbrt(x); }
};
VTKM_EXEC
void TestCbrt() const
{
// std::cout << " Testing Cbrt" << std::endl;
RaiseToTest(CbrtFunctor(), vtkm::Float32(1.0 / 3.0));
}
void TestCbrt() const { RaiseToTest(CbrtFunctor(), vtkm::Float32(1.0 / 3.0)); }
struct RCbrtFunctor
{
@ -477,11 +453,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::RCbrt(x); }
};
VTKM_EXEC
void TestRCbrt() const
{
// std::cout << " Testing RCbrt" << std::endl;
RaiseToTest(RCbrtFunctor(), vtkm::Float32(-1.0 / 3.0));
}
void TestRCbrt() const { RaiseToTest(RCbrtFunctor(), vtkm::Float32(-1.0 / 3.0)); }
template <typename FunctionType>
VTKM_EXEC void RaiseByTest(FunctionType function,
@ -514,11 +486,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp(x); }
};
VTKM_EXEC
void TestExp() const
{
// std::cout << " Testing Exp" << std::endl;
RaiseByTest(ExpFunctor(), vtkm::Float32(2.71828183));
}
void TestExp() const { RaiseByTest(ExpFunctor(), vtkm::Float32(2.71828183)); }
struct Exp2Functor
{
@ -526,11 +494,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp2(x); }
};
VTKM_EXEC
void TestExp2() const
{
// std::cout << " Testing Exp2" << std::endl;
RaiseByTest(Exp2Functor(), 2.0);
}
void TestExp2() const { RaiseByTest(Exp2Functor(), 2.0); }
struct ExpM1Functor
{
@ -538,11 +502,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::ExpM1(x); }
};
VTKM_EXEC
void TestExpM1() const
{
// std::cout << " Testing ExpM1" << std::endl;
RaiseByTest(ExpM1Functor(), ComponentType(2.71828183), 0.0, -1.0);
}
void TestExpM1() const { RaiseByTest(ExpM1Functor(), ComponentType(2.71828183), 0.0, -1.0); }
struct Exp10Functor
{
@ -550,11 +510,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Exp10(x); }
};
VTKM_EXEC
void TestExp10() const
{
// std::cout << " Testing Exp10" << std::endl;
RaiseByTest(Exp10Functor(), 10.0);
}
void TestExp10() const { RaiseByTest(Exp10Functor(), 10.0); }
template <typename FunctionType>
VTKM_EXEC void LogBaseTest(FunctionType function,
@ -588,11 +544,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log(x); }
};
VTKM_EXEC
void TestLog() const
{
// std::cout << " Testing Log" << std::endl;
LogBaseTest(LogFunctor(), vtkm::Float32(2.71828183));
}
void TestLog() const { LogBaseTest(LogFunctor(), vtkm::Float32(2.71828183)); }
struct Log10Functor
{
@ -600,11 +552,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log10(x); }
};
VTKM_EXEC
void TestLog10() const
{
// std::cout << " Testing Log10" << std::endl;
LogBaseTest(Log10Functor(), 10.0);
}
void TestLog10() const { LogBaseTest(Log10Functor(), 10.0); }
struct Log1PFunctor
{
@ -612,16 +560,11 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
VectorType operator()(VectorType x) const { return vtkm::Log1P(x); }
};
VTKM_EXEC
void TestLog1P() const
{
// std::cout << " Testing Log1P" << std::endl;
LogBaseTest(Log1PFunctor(), ComponentType(2.71828183), 1.0);
}
void TestLog1P() const { LogBaseTest(Log1PFunctor(), ComponentType(2.71828183), 1.0); }
VTKM_EXEC
void TestCopySign() const
{
// std::cout << "Testing CopySign." << std::endl;
// Assuming all TestValues positive.
VectorType positive1 = TestValue(1, VectorType());
VectorType positive2 = TestValue(2, VectorType());
@ -713,7 +656,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
// Now test x = y:
vtkm::Float64 x = -1;
for (int i = 0; i < 500; ++i)
for (int i = 0; i < 50; ++i)
{
dist = vtkm::FloatDistance(x, x);
VTKM_MATH_ASSERT(test_equal(vtkm::UInt64(0), dist),
@ -840,7 +783,7 @@ struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
// Now test x = y:
vtkm::Float32 x = -1;
for (int i = 0; i < 500; ++i)
for (int i = 0; i < 50; ++i)
{
dist = vtkm::FloatDistance(x, x);
VTKM_MATH_ASSERT(test_equal(vtkm::UInt64(0), dist),
@ -1001,7 +944,6 @@ struct AllTypesTests : public vtkm::exec::FunctorBase
{
T low = TestValue(2, T());
T high = TestValue(10, T());
// std::cout << "Testing min/max " << low << " " << high << std::endl;
VTKM_MATH_ASSERT(test_equal(vtkm::Min(low, high), low), "Wrong min.");
VTKM_MATH_ASSERT(test_equal(vtkm::Min(high, low), low), "Wrong min.");
VTKM_MATH_ASSERT(test_equal(vtkm::Max(low, high), high), "Wrong max.");
@ -1038,7 +980,6 @@ struct AbsTests : public vtkm::exec::FunctorBase
VTKM_EXEC
void operator()(vtkm::Id index) const
{
// std::cout << "Testing Abs." << std::endl;
T positive = TestValue(index, T()); // Assuming all TestValues positive.
T negative = -positive;
@ -1060,7 +1001,7 @@ using TypeListAbs =
vtkm::ListAppend<vtkm::List<vtkm::Int32, vtkm::Int64>, vtkm::TypeListIndex, vtkm::TypeListField>;
//-----------------------------------------------------------------------------
static constexpr vtkm::Id BitOpSamples = 1024 * 1024;
static constexpr vtkm::Id BitOpSamples = 128 * 128;
template <typename T>
struct BitOpTests : public vtkm::exec::FunctorBase
@ -1131,15 +1072,10 @@ using TypeListBitOp = vtkm::List<vtkm::UInt32, vtkm::UInt64>;
//-----------------------------------------------------------------------------
void RunMathTests()
{
std::cout << "Tests for scalar types." << std::endl;
vtkm::testing::Testing::TryTypes(TryScalarFieldTests(), vtkm::TypeListFieldScalar());
std::cout << "Test for scalar and vector types." << std::endl;
vtkm::testing::Testing::TryTypes(TryScalarVectorFieldTests(), vtkm::TypeListField());
std::cout << "Test for exemplar types." << std::endl;
vtkm::testing::Testing::TryTypes(TryAllTypesTests());
std::cout << "Test all Abs types" << std::endl;
vtkm::testing::Testing::TryTypes(TryAbsTests(), TypeListAbs());
std::cout << "Test all bit operations" << std::endl;
vtkm::testing::Testing::TryTypes(TryBitOpTests(), TypeListBitOp());
}