2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-06-25 18:20:29 +00:00
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
//
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-06-25 18:20:29 +00:00
|
|
|
#ifndef vtk_m_testing_TestingMath_h
|
|
|
|
#define vtk_m_testing_TestingMath_h
|
|
|
|
|
|
|
|
#include <vtkm/Math.h>
|
|
|
|
|
2019-12-05 17:55:57 +00:00
|
|
|
#include <vtkm/TypeList.h>
|
2015-06-25 18:20:29 +00:00
|
|
|
#include <vtkm/VecTraits.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
|
|
|
|
2019-03-05 16:46:32 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_MATH_ASSERT(condition, message) \
|
|
|
|
if (!(condition)) \
|
|
|
|
{ \
|
|
|
|
this->RaiseError(message); \
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace UnitTestMathNamespace
|
|
|
|
{
|
2015-06-25 18:20:29 +00:00
|
|
|
|
2017-12-05 18:42:03 +00:00
|
|
|
class Lists
|
|
|
|
{
|
|
|
|
public:
|
2018-02-21 19:51:15 +00:00
|
|
|
static constexpr vtkm::IdComponent NUM_NUMBERS = 5;
|
2017-12-05 18:42:03 +00:00
|
|
|
|
2018-02-21 19:51:15 +00:00
|
|
|
VTKM_EXEC_CONT vtkm::Float64 NumberList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 numberList[NUM_NUMBERS] = { 0.25, 0.5, 1.0, 2.0, 3.75 };
|
|
|
|
return numberList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 AngleList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 angleList[NUM_NUMBERS] = { 0.643501108793284, // angle for 3, 4, 5 triangle.
|
|
|
|
0.78539816339745, // pi/4
|
|
|
|
0.5235987755983, // pi/6
|
|
|
|
1.0471975511966, // pi/3
|
|
|
|
0.0 };
|
|
|
|
return angleList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 OppositeList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 oppositeList[NUM_NUMBERS] = { 3.0, 1.0, 1.0, 1.732050807568877 /*sqrt(3)*/, 0.0 };
|
|
|
|
return oppositeList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 AdjacentList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 adjacentList[NUM_NUMBERS] = { 4.0, 1.0, 1.732050807568877 /*sqrt(3)*/, 1.0, 1.0 };
|
|
|
|
return adjacentList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 HypotenuseList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 hypotenuseList[NUM_NUMBERS] = {
|
|
|
|
5.0, 1.414213562373095 /*sqrt(2)*/, 2.0, 2.0, 1.0
|
2017-12-05 18:42:03 +00:00
|
|
|
};
|
2018-02-21 19:51:15 +00:00
|
|
|
return hypotenuseList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 NumeratorList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 numeratorList[NUM_NUMBERS] = { 6.5, 5.8, 9.3, 77.0, 0.1 };
|
|
|
|
return numeratorList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 DenominatorList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 denominatorList[NUM_NUMBERS] = { 2.3, 1.6, 3.1, 19.0, 0.4 };
|
|
|
|
return denominatorList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 FModRemainderList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 fModRemainderList[NUM_NUMBERS] = { 1.9, 1.0, 0.0, 1.0, 0.1 };
|
|
|
|
return fModRemainderList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 RemainderList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 remainderList[NUM_NUMBERS] = { -0.4, -0.6, 0.0, 1.0, 0.1 };
|
|
|
|
return remainderList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Int64 QuotientList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Int64 quotientList[NUM_NUMBERS] = { 3, 4, 3, 4, 0 };
|
|
|
|
return quotientList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 XList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 xList[NUM_NUMBERS] = { 4.6, 0.1, 73.4, 55.0, 3.75 };
|
|
|
|
return xList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 FractionalList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 fractionalList[NUM_NUMBERS] = { 0.6, 0.1, 0.4, 0.0, 0.75 };
|
|
|
|
return fractionalList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 FloorList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 floorList[NUM_NUMBERS] = { 4.0, 0.0, 73.0, 55.0, 3.0 };
|
|
|
|
return floorList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 CeilList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 ceilList[NUM_NUMBERS] = { 5.0, 1.0, 74.0, 55.0, 4.0 };
|
|
|
|
return ceilList[i];
|
|
|
|
}
|
|
|
|
VTKM_EXEC_CONT vtkm::Float64 RoundList(vtkm::Int32 i) const
|
|
|
|
{
|
|
|
|
vtkm::Float64 roundList[NUM_NUMBERS] = { 5.0, 0.0, 73.0, 55.0, 4.0 };
|
|
|
|
return roundList[i];
|
2017-12-05 18:42:03 +00:00
|
|
|
}
|
|
|
|
};
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct ScalarFieldTests : public vtkm::exec::FunctorBase
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestPi() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing Pi" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Pi(), 3.14159265), "Pi not correct.");
|
2018-05-15 21:29:31 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Pif(), 3.14159265f), "Pif not correct.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Pi<vtkm::Float64>(), 3.14159265),
|
|
|
|
"Pi template function not correct.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestArcTan2() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing arc tan 2" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
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())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 y+ axis.");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(-1.0), T(0.0)), T(-0.5 * vtkm::Pi())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 y- axis.");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(1.0), T(1.0)), T(0.25 * vtkm::Pi())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 Quadrant 1");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(1.0), T(-1.0)), T(0.75 * vtkm::Pi())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 Quadrant 2");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(-1.0), T(-1.0)), T(-0.75 * vtkm::Pi())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 Quadrant 3");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan2(T(-1.0), T(1.0)), T(-0.25 * vtkm::Pi())),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ATan2 Quadrant 4");
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestPow() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Running power tests." << std::endl;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
T x = static_cast<T>(Lists{}.NumberList(index));
|
2015-06-25 18:20:29 +00:00
|
|
|
T powx = vtkm::Pow(x, static_cast<T>(2.0));
|
2017-05-18 14:29:41 +00:00
|
|
|
T sqrx = x * x;
|
2015-06-25 18:20:29 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(powx, sqrx), "Power gave wrong result.");
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestLog2() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// 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)),
|
2015-06-25 18:20:29 +00:00
|
|
|
"Bad value from Log2");
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestNonFinites() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing non-finites." << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
T zero = 0.0;
|
|
|
|
T finite = 1.0;
|
|
|
|
T nan = vtkm::Nan<T>();
|
|
|
|
T inf = vtkm::Infinity<T>();
|
|
|
|
T neginf = vtkm::NegativeInfinity<T>();
|
|
|
|
T epsilon = vtkm::Epsilon<T>();
|
|
|
|
|
|
|
|
// General behavior.
|
2015-08-14 21:46:21 +00:00
|
|
|
VTKM_MATH_ASSERT(nan != vtkm::Nan<T>(), "Nan not equal itself.");
|
2015-06-25 18:20:29 +00:00
|
|
|
VTKM_MATH_ASSERT(!(nan >= zero), "Nan not greater or less.");
|
|
|
|
VTKM_MATH_ASSERT(!(nan <= zero), "Nan not greater or less.");
|
|
|
|
VTKM_MATH_ASSERT(!(nan >= finite), "Nan not greater or less.");
|
|
|
|
VTKM_MATH_ASSERT(!(nan <= finite), "Nan not greater or less.");
|
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(neginf < inf, "Infinity big");
|
|
|
|
VTKM_MATH_ASSERT(zero < inf, "Infinity big");
|
|
|
|
VTKM_MATH_ASSERT(finite < inf, "Infinity big");
|
|
|
|
VTKM_MATH_ASSERT(zero > -inf, "-Infinity small");
|
|
|
|
VTKM_MATH_ASSERT(finite > -inf, "-Infinity small");
|
|
|
|
VTKM_MATH_ASSERT(zero > neginf, "-Infinity small");
|
|
|
|
VTKM_MATH_ASSERT(finite > neginf, "-Infinity small");
|
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(zero < epsilon, "Negative epsilon");
|
|
|
|
VTKM_MATH_ASSERT(finite > epsilon, "Large epsilon");
|
|
|
|
|
|
|
|
// Math check functions.
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNan(zero), "Bad IsNan check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNan(finite), "Bad IsNan check.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsNan(nan), "Bad IsNan check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNan(inf), "Bad IsNan check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNan(neginf), "Bad IsNan check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNan(epsilon), "Bad IsNan check.");
|
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsInf(zero), "Bad infinity check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsInf(finite), "Bad infinity check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsInf(nan), "Bad infinity check.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsInf(inf), "Bad infinity check.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsInf(neginf), "Bad infinity check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsInf(epsilon), "Bad infinity check.");
|
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsFinite(zero), "Bad finite check.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsFinite(finite), "Bad finite check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsFinite(nan), "Bad finite check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsFinite(inf), "Bad finite check.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsFinite(neginf), "Bad finite check.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsFinite(epsilon), "Bad finite check.");
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestRemainders() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing remainders." << std::endl;
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
T numerator = static_cast<T>(table.NumeratorList(index));
|
|
|
|
T denominator = static_cast<T>(table.DenominatorList(index));
|
|
|
|
T fmodremainder = static_cast<T>(table.FModRemainderList(index));
|
|
|
|
T remainder = static_cast<T>(table.RemainderList(index));
|
|
|
|
vtkm::Int64 quotient = table.QuotientList(index);
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::FMod(numerator, denominator), fmodremainder),
|
|
|
|
"Bad FMod remainder.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Remainder(numerator, denominator), remainder),
|
|
|
|
"Bad remainder.");
|
|
|
|
vtkm::Int64 q;
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::RemainderQuotient(numerator, denominator, q), remainder),
|
|
|
|
"Bad remainder-quotient remainder.");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(q, quotient), "Bad reminder-quotient quotient.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestRound() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing round." << std::endl;
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
T x = static_cast<T>(table.XList(index));
|
|
|
|
T fractional = static_cast<T>(table.FractionalList(index));
|
|
|
|
T floor = static_cast<T>(table.FloorList(index));
|
|
|
|
T ceil = static_cast<T>(table.CeilList(index));
|
|
|
|
T round = static_cast<T>(table.RoundList(index));
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
T intPart;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ModF(x, intPart), fractional),
|
2015-06-25 18:20:29 +00:00
|
|
|
"ModF returned wrong fractional part.");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(intPart, floor), "ModF returned wrong integral part.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Floor(x), floor), "Bad floor.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Ceil(x), ceil), "Bad ceil.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Round(x), round), "Bad round.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestIsNegative() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing SignBit and IsNegative." << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
T x = 0;
|
|
|
|
VTKM_MATH_ASSERT(vtkm::SignBit(x) == 0, "SignBit wrong for 0.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNegative(x), "IsNegative wrong for 0.");
|
|
|
|
|
|
|
|
x = 20;
|
|
|
|
VTKM_MATH_ASSERT(vtkm::SignBit(x) == 0, "SignBit wrong for 20.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNegative(x), "IsNegative wrong for 20.");
|
|
|
|
|
|
|
|
x = -20;
|
|
|
|
VTKM_MATH_ASSERT(vtkm::SignBit(x) != 0, "SignBit wrong for -20.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsNegative(x), "IsNegative wrong for -20.");
|
|
|
|
|
|
|
|
x = 0.02f;
|
|
|
|
VTKM_MATH_ASSERT(vtkm::SignBit(x) == 0, "SignBit wrong for 0.02.");
|
|
|
|
VTKM_MATH_ASSERT(!vtkm::IsNegative(x), "IsNegative wrong for 0.02.");
|
|
|
|
|
|
|
|
x = -0.02f;
|
|
|
|
VTKM_MATH_ASSERT(vtkm::SignBit(x) != 0, "SignBit wrong for -0.02.");
|
|
|
|
VTKM_MATH_ASSERT(vtkm::IsNegative(x), "IsNegative wrong for -0.02.");
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(vtkm::Id) const
|
|
|
|
{
|
|
|
|
this->TestPi();
|
|
|
|
this->TestArcTan2();
|
|
|
|
this->TestPow();
|
|
|
|
this->TestLog2();
|
|
|
|
this->TestNonFinites();
|
|
|
|
this->TestRemainders();
|
|
|
|
this->TestRound();
|
|
|
|
this->TestIsNegative();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct TryScalarFieldTests
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(const T&) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(ScalarFieldTests<T>(), 1);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename VectorType>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct ScalarVectorFieldTests : public vtkm::exec::FunctorBase
|
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using Traits = vtkm::VecTraits<VectorType>;
|
|
|
|
using ComponentType = typename Traits::ComponentType;
|
2017-05-18 14:29:41 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-06-25 18:20:29 +00:00
|
|
|
NUM_COMPONENTS = Traits::NUM_COMPONENTS
|
|
|
|
};
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestTriangleTrig() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing normal trig functions." << std::endl;
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
|
|
|
VectorType angle;
|
|
|
|
VectorType opposite;
|
|
|
|
VectorType adjacent;
|
|
|
|
VectorType hypotenuse;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
Traits::SetComponent(angle,
|
|
|
|
componentIndex,
|
|
|
|
static_cast<ComponentType>(table.AngleList(componentIndex + index)));
|
2017-12-05 18:42:03 +00:00
|
|
|
Traits::SetComponent(
|
|
|
|
opposite,
|
|
|
|
componentIndex,
|
2018-02-21 19:51:15 +00:00
|
|
|
static_cast<ComponentType>(table.OppositeList(componentIndex + index)));
|
2017-12-05 18:42:03 +00:00
|
|
|
Traits::SetComponent(
|
|
|
|
adjacent,
|
|
|
|
componentIndex,
|
2018-02-21 19:51:15 +00:00
|
|
|
static_cast<ComponentType>(table.AdjacentList(componentIndex + index)));
|
2017-12-05 18:42:03 +00:00
|
|
|
Traits::SetComponent(
|
|
|
|
hypotenuse,
|
|
|
|
componentIndex,
|
2018-02-21 19:51:15 +00:00
|
|
|
static_cast<ComponentType>(table.HypotenuseList(componentIndex + index)));
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Sin(angle), opposite / hypotenuse), "Sin failed test.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Cos(angle), adjacent / hypotenuse), "Cos failed test.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Tan(angle), opposite / adjacent), "Tan failed test.");
|
2015-06-25 18:20:29 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ASin(opposite / hypotenuse), angle),
|
|
|
|
"Arc Sin failed test.");
|
2016-10-20 19:25:14 +00:00
|
|
|
|
2016-11-10 18:48:19 +00:00
|
|
|
#if defined(VTKM_ICC)
|
2017-05-18 14:29:41 +00:00
|
|
|
// When the intel compiler has vectorization enabled ( -O2/-O3 ) it converts the
|
|
|
|
// `adjacent/hypotenuse` divide operation into reciprocal (rcpps) and
|
|
|
|
// multiply (mulps) operations. This causes a change in the expected result that
|
|
|
|
// is larger than the default tolerance of test_equal.
|
|
|
|
//
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ACos(adjacent / hypotenuse), angle, 0.0004),
|
|
|
|
"Arc Cos failed test.");
|
2016-10-20 19:25:14 +00:00
|
|
|
#else
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ACos(adjacent / hypotenuse), angle),
|
|
|
|
"Arc Cos failed test.");
|
2016-10-20 19:25:14 +00:00
|
|
|
#endif
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATan(opposite / adjacent), angle), "Arc Tan failed test.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestHyperbolicTrig() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing hyperbolic trig functions." << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
const VectorType zero(0);
|
2015-06-30 15:23:18 +00:00
|
|
|
const VectorType half(0.5);
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
|
|
|
VectorType x;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2017-05-26 17:53:28 +00:00
|
|
|
Traits::SetComponent(
|
2018-02-21 19:51:15 +00:00
|
|
|
x, componentIndex, static_cast<ComponentType>(table.AngleList(componentIndex + index)));
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const VectorType minusX = zero - x;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::SinH(x), half * (vtkm::Exp(x) - vtkm::Exp(minusX))),
|
|
|
|
"SinH does not match definition.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CosH(x), half * (vtkm::Exp(x) + vtkm::Exp(minusX))),
|
|
|
|
"SinH does not match definition.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::TanH(x), vtkm::SinH(x) / vtkm::CosH(x)),
|
|
|
|
"TanH does not match definition");
|
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ASinH(vtkm::SinH(x)), x), "SinH not inverting.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ACosH(vtkm::CosH(x)), x), "CosH not inverting.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::ATanH(vtkm::TanH(x)), x), "TanH not inverting.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FunctionType>
|
|
|
|
VTKM_EXEC void RaiseToTest(FunctionType function, ComponentType exponent) const
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
|
|
|
VectorType original;
|
|
|
|
VectorType raiseresult;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
ComponentType x = static_cast<ComponentType>(table.NumberList(componentIndex + index));
|
2015-06-25 18:20:29 +00:00
|
|
|
Traits::SetComponent(original, componentIndex, x);
|
|
|
|
Traits::SetComponent(raiseresult, componentIndex, vtkm::Pow(x, exponent));
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorType mathresult = function(original);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(mathresult, raiseresult), "Exponent functions do not agree.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct SqrtFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Sqrt(x); }
|
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestSqrt() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Sqrt" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
RaiseToTest(SqrtFunctor(), 0.5);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct RSqrtFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::RSqrt(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestRSqrt() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing RSqrt"<< std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
RaiseToTest(RSqrtFunctor(), -0.5);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct CbrtFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Cbrt(x); }
|
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestCbrt() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Cbrt" << std::endl;
|
|
|
|
RaiseToTest(CbrtFunctor(), vtkm::Float32(1.0 / 3.0));
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct RCbrtFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::RCbrt(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestRCbrt() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing RCbrt" << std::endl;
|
|
|
|
RaiseToTest(RCbrtFunctor(), vtkm::Float32(-1.0 / 3.0));
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FunctionType>
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_EXEC void RaiseByTest(FunctionType function,
|
|
|
|
ComponentType base,
|
|
|
|
ComponentType exponentbias = 0.0,
|
|
|
|
ComponentType resultbias = 0.0) const
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
|
|
|
VectorType original;
|
|
|
|
VectorType raiseresult;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
ComponentType x = static_cast<ComponentType>(table.NumberList(componentIndex + index));
|
2015-06-25 18:20:29 +00:00
|
|
|
Traits::SetComponent(original, componentIndex, x);
|
2017-05-26 17:53:28 +00:00
|
|
|
Traits::SetComponent(
|
|
|
|
raiseresult, componentIndex, vtkm::Pow(base, x + exponentbias) + resultbias);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VectorType mathresult = function(original);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(mathresult, raiseresult), "Exponent functions do not agree.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct ExpFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Exp(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestExp() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Exp" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
RaiseByTest(ExpFunctor(), vtkm::Float32(2.71828183));
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct Exp2Functor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Exp2(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestExp2() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Exp2" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
RaiseByTest(Exp2Functor(), 2.0);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct ExpM1Functor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::ExpM1(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestExpM1() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing ExpM1" << std::endl;
|
|
|
|
RaiseByTest(ExpM1Functor(), ComponentType(2.71828183), 0.0, -1.0);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct Exp10Functor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Exp10(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestExp10() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Exp10" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
RaiseByTest(Exp10Functor(), 10.0);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FunctionType>
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_EXEC void LogBaseTest(FunctionType function,
|
|
|
|
ComponentType base,
|
2017-05-18 14:29:41 +00:00
|
|
|
ComponentType bias = 0.0) const
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
Lists table;
|
2017-12-05 18:42:03 +00:00
|
|
|
for (vtkm::IdComponent index = 0; index < Lists::NUM_NUMBERS - NUM_COMPONENTS + 1; index++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
|
|
|
VectorType basevector(base);
|
|
|
|
VectorType original;
|
|
|
|
VectorType biased;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; componentIndex++)
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2018-02-21 19:51:15 +00:00
|
|
|
ComponentType x = static_cast<ComponentType>(table.NumberList(componentIndex + index));
|
2015-06-25 18:20:29 +00:00
|
|
|
Traits::SetComponent(original, componentIndex, x);
|
|
|
|
Traits::SetComponent(biased, componentIndex, x + bias);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType logresult = vtkm::Log2(biased) / vtkm::Log2(basevector);
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
VectorType mathresult = function(original);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(mathresult, logresult), "Exponent functions do not agree.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct LogFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Log(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestLog() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Log" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
LogBaseTest(LogFunctor(), vtkm::Float32(2.71828183));
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct Log10Functor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Log10(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestLog10() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Log10" << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
LogBaseTest(Log10Functor(), 10.0);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct Log1PFunctor
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
VectorType operator()(VectorType x) const { return vtkm::Log1P(x); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestLog1P() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << " Testing Log1P" << std::endl;
|
|
|
|
LogBaseTest(Log1PFunctor(), ComponentType(2.71828183), 1.0);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestCopySign() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing CopySign." << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
// Assuming all TestValues positive.
|
|
|
|
VectorType positive1 = TestValue(1, VectorType());
|
|
|
|
VectorType positive2 = TestValue(2, VectorType());
|
2015-06-30 15:23:18 +00:00
|
|
|
VectorType negative1 = -positive1;
|
|
|
|
VectorType negative2 = -positive2;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CopySign(positive1, positive2), positive1),
|
|
|
|
"CopySign failed.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CopySign(negative1, positive2), positive1),
|
|
|
|
"CopySign failed.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CopySign(positive1, negative2), negative1),
|
|
|
|
"CopySign failed.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CopySign(negative1, negative2), negative1),
|
|
|
|
"CopySign failed.");
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(vtkm::Id) const
|
|
|
|
{
|
|
|
|
this->TestTriangleTrig();
|
|
|
|
this->TestHyperbolicTrig();
|
|
|
|
this->TestSqrt();
|
|
|
|
this->TestRSqrt();
|
|
|
|
this->TestCbrt();
|
|
|
|
this->TestRCbrt();
|
|
|
|
this->TestExp();
|
|
|
|
this->TestExp2();
|
|
|
|
this->TestExpM1();
|
|
|
|
this->TestExp10();
|
|
|
|
this->TestLog();
|
|
|
|
this->TestLog10();
|
|
|
|
this->TestLog1P();
|
|
|
|
this->TestCopySign();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct TryScalarVectorFieldTests
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename VectorType>
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(const VectorType&) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(ScalarVectorFieldTests<VectorType>(), 1);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-07-22 17:27:44 +00:00
|
|
|
struct AllTypesTests : public vtkm::exec::FunctorBase
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-06-25 18:20:29 +00:00
|
|
|
void TestMinMax() const
|
|
|
|
{
|
|
|
|
T low = TestValue(2, T());
|
|
|
|
T high = TestValue(10, T());
|
2017-05-18 14:29:41 +00:00
|
|
|
// std::cout << "Testing min/max " << low << " " << high << std::endl;
|
2015-06-25 18:20:29 +00:00
|
|
|
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.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Max(high, low), high), "Wrong max.");
|
2015-07-22 17:27:44 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using Traits = vtkm::VecTraits<T>;
|
2015-07-22 17:27:44 +00:00
|
|
|
T mixed1 = low;
|
|
|
|
T mixed2 = high;
|
|
|
|
Traits::SetComponent(mixed1, 0, Traits::GetComponent(high, 0));
|
|
|
|
Traits::SetComponent(mixed2, 0, Traits::GetComponent(low, 0));
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Min(mixed1, mixed2), low), "Wrong min.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Min(mixed2, mixed1), low), "Wrong min.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Max(mixed1, mixed2), high), "Wrong max.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Max(mixed2, mixed1), high), "Wrong max.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
void operator()(vtkm::Id) const { this->TestMinMax(); }
|
2015-06-25 18:20:29 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-07-22 17:27:44 +00:00
|
|
|
struct TryAllTypesTests
|
2015-06-25 18:20:29 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(const T&) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(AllTypesTests<T>(), 1);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct AbsTests : public vtkm::exec::FunctorBase
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
void operator()(vtkm::Id index) const
|
|
|
|
{
|
|
|
|
// std::cout << "Testing Abs." << std::endl;
|
|
|
|
T positive = TestValue(index, T()); // Assuming all TestValues positive.
|
2015-06-30 15:23:18 +00:00
|
|
|
T negative = -positive;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Abs(positive), positive), "Abs returned wrong value.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::Abs(negative), positive), "Abs returned wrong value.");
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-06-25 18:20:29 +00:00
|
|
|
struct TryAbsTests
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-06-25 18:20:29 +00:00
|
|
|
void operator()(const T&) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(AbsTests<T>(), 10);
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-05 17:55:57 +00:00
|
|
|
using TypeListAbs =
|
|
|
|
vtkm::ListAppend<vtkm::List<vtkm::Int32, vtkm::Int64>, vtkm::TypeListIndex, vtkm::TypeListField>;
|
2015-06-25 18:20:29 +00:00
|
|
|
|
2019-03-05 16:46:32 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static constexpr vtkm::Id BitOpSamples = 1024 * 1024;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct BitOpTests : public vtkm::exec::FunctorBase
|
|
|
|
{
|
|
|
|
static constexpr T MaxT = std::numeric_limits<T>::max();
|
|
|
|
static constexpr T Offset = MaxT / BitOpSamples;
|
|
|
|
|
|
|
|
VTKM_EXEC void operator()(vtkm::Id i) const
|
|
|
|
{
|
|
|
|
const T idx = static_cast<T>(i);
|
|
|
|
const T word = idx * this->Offset;
|
|
|
|
|
|
|
|
TestWord(word - idx);
|
|
|
|
TestWord(word);
|
|
|
|
TestWord(word + idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC void TestWord(T word) const
|
|
|
|
{
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::CountSetBits(word), this->DumbCountBits(word)),
|
|
|
|
"CountBits returned wrong value.");
|
|
|
|
VTKM_MATH_ASSERT(test_equal(vtkm::FindFirstSetBit(word), this->DumbFindFirstSetBit(word)),
|
|
|
|
"FindFirstSetBit returned wrong value.")
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC vtkm::Int32 DumbCountBits(T word) const
|
|
|
|
{
|
|
|
|
vtkm::Int32 bits = 0;
|
|
|
|
while (word)
|
|
|
|
{
|
|
|
|
if (word & 0x1)
|
|
|
|
{
|
|
|
|
++bits;
|
|
|
|
}
|
|
|
|
word >>= 1;
|
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC vtkm::Int32 DumbFindFirstSetBit(T word) const
|
|
|
|
{
|
|
|
|
if (word == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::Int32 bit = 1;
|
|
|
|
while ((word & 0x1) == 0)
|
|
|
|
{
|
|
|
|
word >>= 1;
|
|
|
|
++bit;
|
|
|
|
}
|
|
|
|
return bit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Device>
|
|
|
|
struct TryBitOpTests
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
void operator()(const T&) const
|
|
|
|
{
|
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(BitOpTests<T>(), BitOpSamples);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-05 02:17:19 +00:00
|
|
|
using TypeListBitOp = vtkm::List<vtkm::UInt32, vtkm::UInt64>;
|
2019-03-05 16:46:32 +00:00
|
|
|
|
2015-06-25 18:20:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-06-25 18:20:29 +00:00
|
|
|
void RunMathTests()
|
|
|
|
{
|
|
|
|
std::cout << "Tests for scalar types." << std::endl;
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryScalarFieldTests<Device>(), vtkm::TypeListFieldScalar());
|
2015-06-25 18:20:29 +00:00
|
|
|
std::cout << "Test for scalar and vector types." << std::endl;
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryScalarVectorFieldTests<Device>(), vtkm::TypeListField());
|
2016-08-24 22:02:18 +00:00
|
|
|
std::cout << "Test for exemplar types." << std::endl;
|
|
|
|
vtkm::testing::Testing::TryTypes(TryAllTypesTests<Device>());
|
2015-06-25 18:20:29 +00:00
|
|
|
std::cout << "Test all Abs types" << std::endl;
|
2019-12-05 02:17:19 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryAbsTests<Device>(), TypeListAbs());
|
2019-03-05 16:46:32 +00:00
|
|
|
std::cout << "Test all bit operations" << std::endl;
|
2019-12-05 02:17:19 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryBitOpTests<Device>(), TypeListBitOp());
|
2015-06-25 18:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace UnitTestMathNamespace
|
|
|
|
|
|
|
|
#endif //vtk_m_testing_TestingMath_h
|