Commit 7f94eafc authored by Kenneth Moreland's avatar Kenneth Moreland

Remove vtkm::Scalar and vtkm::Vector# types

Providing these types tends to "lock in" the precision of the algorithms
used in VTK-m. Since we are using templating anyway, our templates
should be generic enough to handle difference precision in the data.
Usually the appropriate type can be determined by the data provided. In
the case where there is no hint on the precision of data to use (for
example, in the code that provides coordinates for uniform data), there
is a vtkm::FloatDefault.
parent 4881ed4d
......@@ -111,28 +111,12 @@ VTKM_BASIC_INTEGER_TYPE(vtkm::UInt64);
#undef VTKM_BASIC_REAL_TYPE
#undef VTKM_BASIC_INTEGER_TYPE
#define VTKM_VECTOR_TYPE(T, NTag) \
template<> struct TypeTraits<T> { \
typedef NTag NumericTag; \
typedef TypeTraitsVectorTag DimensionalityTag; \
}
/// Traits for vector types.
///
VTKM_VECTOR_TYPE(vtkm::Id3, TypeTraitsIntegerTag);
VTKM_VECTOR_TYPE(vtkm::Vector2, TypeTraitsRealTag);
VTKM_VECTOR_TYPE(vtkm::Vector3, TypeTraitsRealTag);
VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag);
#undef VTKM_VECTOR_TYPE
/// Traits for tuples.
/// Traits for Vec types.
///
template<typename T, vtkm::IdComponent Size>
struct TypeTraits<vtkm::Vec<T, Size> >
struct TypeTraits<vtkm::Vec<T,Size> >
{
typedef typename TypeTraits<T>::NumericTag NumericTag;
typedef typename vtkm::TypeTraits<T>::NumericTag NumericTag;
typedef TypeTraitsVectorTag DimensionalityTag;
};
......
......@@ -156,13 +156,13 @@ typedef vtkm::Int32 IdComponent;
#ifdef VTKM_USE_DOUBLE_PRECISION
/// Scalar corresponds to a floating point number.
typedef vtkm::Float64 Scalar;
/// The floating point type to use when no other precision is specified.
typedef vtkm::Float64 FloatDefault;
#else //VTKM_USE_DOUBLE_PRECISION
/// Scalar corresponds to a floating point number.
typedef vtkm::Float32 Scalar;
/// The floating point type to use when no other precision is specified.
typedef vtkm::Float32 FloatDefault;
#endif //VTKM_USE_DOUBLE_PRECISION
......@@ -1043,9 +1043,6 @@ public:
}
};
/// Vector2 corresponds to a 2-tuple
typedef vtkm::Vec<vtkm::Scalar,2> Vector2;
/// Id2 corresponds to a 2-dimensional index
typedef vtkm::Vec<vtkm::Id,2> Id2;
......@@ -1071,9 +1068,6 @@ public:
}
};
/// Vector3 corresponds to a 3-tuple
typedef vtkm::Vec<vtkm::Scalar,3> Vector3;
/// Id3 corresponds to a 3-dimensional index for 3d arrays. Note that
/// the precision of each index may be less than vtkm::Id.
typedef vtkm::Vec<vtkm::Id,3> Id3;
......@@ -1101,39 +1095,6 @@ public:
}
};
/// Vector4 corresponds to a 4-tuple
typedef vtkm::Vec<vtkm::Scalar,4> Vector4;
/// Initializes and returns a Vector2.
VTKM_EXEC_CONT_EXPORT vtkm::Vector2 make_Vector2(vtkm::Scalar x,
vtkm::Scalar y)
{
return vtkm::Vector2(x, y);
}
/// Initializes and returns a Vector3.
VTKM_EXEC_CONT_EXPORT vtkm::Vector3 make_Vector3(vtkm::Scalar x,
vtkm::Scalar y,
vtkm::Scalar z)
{
return vtkm::Vector3(x, y, z);
}
/// Initializes and returns a Vector4.
VTKM_EXEC_CONT_EXPORT vtkm::Vector4 make_Vector4(vtkm::Scalar x,
vtkm::Scalar y,
vtkm::Scalar z,
vtkm::Scalar w)
{
return vtkm::Vector4(x, y, z, w);
}
/// Initializes and returns an Id3
VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z)
{
return vtkm::Id3(x, y, z);
}
/// Initializes and returns a Vec of length 2.
///
......
......@@ -36,15 +36,15 @@ namespace internal {
class ArrayPortalUniformPointCoordinates
{
public:
typedef vtkm::Vector3 ValueType;
typedef vtkm::Vec<vtkm::FloatDefault,3> ValueType;
VTKM_EXEC_CONT_EXPORT
ArrayPortalUniformPointCoordinates() : NumberOfValues(0) { }
VTKM_EXEC_CONT_EXPORT
ArrayPortalUniformPointCoordinates(vtkm::Extent3 extent,
vtkm::Vector3 origin,
vtkm::Vector3 spacing)
ValueType origin,
ValueType spacing)
: Extent(extent),
Dimensions(vtkm::ExtentPointDimensions(extent)),
NumberOfValues(vtkm::ExtentNumberOfPoints(extent)),
......@@ -78,7 +78,7 @@ public:
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
VTKM_EXEC_CONT_EXPORT
vtkm::Vector3 Get(vtkm::Id index) const {
ValueType Get(vtkm::Id index) const {
return this->GetCoordinatesForTopologyIndex(
vtkm::ExtentPointFlatIndexToTopologyIndex(index, this->Extent));
}
......@@ -87,7 +87,7 @@ public:
vtkm::Id3 GetRange3() const { return this->Dimensions; }
VTKM_EXEC_CONT_EXPORT
vtkm::Vector3 Get(vtkm::Id3 index) const {
ValueType Get(vtkm::Id3 index) const {
return this->GetCoordinatesForTopologyIndex(index + this->Extent.Min);
}
......@@ -95,14 +95,14 @@ private:
vtkm::Extent3 Extent;
vtkm::Id3 Dimensions;
vtkm::Id NumberOfValues;
vtkm::Vector3 Origin;
vtkm::Vector3 Spacing;
ValueType Origin;
ValueType Spacing;
VTKM_EXEC_CONT_EXPORT
vtkm::Vector3 GetCoordinatesForTopologyIndex(vtkm::Id3 ijk) const {
return vtkm::Vector3(this->Origin[0] + this->Spacing[0]*ijk[0],
this->Origin[1] + this->Spacing[1]*ijk[1],
this->Origin[2] + this->Spacing[2]*ijk[2]);
ValueType GetCoordinatesForTopologyIndex(vtkm::Id3 ijk) const {
return ValueType(this->Origin[0] + this->Spacing[0]*ijk[0],
this->Origin[1] + this->Spacing[1]*ijk[1],
this->Origin[2] + this->Spacing[2]*ijk[2]);
}
};
......@@ -115,12 +115,16 @@ private:
///
class ArrayHandleUniformPointCoordinates
: public vtkm::cont::ArrayHandle<
vtkm::Vector3,
vtkm::Vec<vtkm::FloatDefault,3>,
vtkm::cont::StorageTagImplicit<
internal::ArrayPortalUniformPointCoordinates> >
{
public:
typedef vtkm::Vec<vtkm::FloatDefault,3> ValueType;
private:
typedef vtkm::cont::ArrayHandle<
vtkm::Vector3,
ValueType,
vtkm::cont::StorageTagImplicit<
internal::ArrayPortalUniformPointCoordinates> > Superclass;
......@@ -130,8 +134,8 @@ public:
VTKM_CONT_EXPORT
ArrayHandleUniformPointCoordinates(vtkm::Extent3 extent,
vtkm::Vector3 origin,
vtkm::Vector3 spacing)
ValueType origin,
ValueType spacing)
: Superclass(
internal::ArrayPortalUniformPointCoordinates(extent, origin, spacing))
{ }
......
......@@ -91,7 +91,17 @@ public:
template<typename Storage>
VTKM_CONT_EXPORT
DynamicPointCoordinates(
const vtkm::cont::ArrayHandle<vtkm::Vector3,Storage> &array)
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3>,Storage> &array)
: PointCoordinatesContainer(new vtkm::cont::PointCoordinatesArray(array))
{ }
/// Special constructor for the common case of using a basic array to store
/// point coordinates.
///
template<typename Storage>
VTKM_CONT_EXPORT
DynamicPointCoordinates(
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64,3>,Storage> &array)
: PointCoordinatesContainer(new vtkm::cont::PointCoordinatesArray(array))
{ }
......
......@@ -52,7 +52,13 @@ public:
template<typename Storage>
VTKM_CONT_EXPORT
PointCoordinatesArray(
const vtkm::cont::ArrayHandle<vtkm::Vector3,Storage> &array)
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3>,Storage> &array)
: Array(array) { }
template<typename Storage>
VTKM_CONT_EXPORT
PointCoordinatesArray(
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64,3>,Storage> &array)
: Array(array) { }
/// In this \c CastAndCall, \c TypeList is ignored. All point coordinates are
......
......@@ -39,13 +39,15 @@ namespace cont {
class PointCoordinatesUniform : public internal::PointCoordinatesBase
{
public:
typedef vtkm::Vec<vtkm::FloatDefault,3> ValueType;
VTKM_CONT_EXPORT
PointCoordinatesUniform() { }
VTKM_CONT_EXPORT
PointCoordinatesUniform(const vtkm::Extent3 &extent,
const vtkm::Vector3 &origin,
const vtkm::Vector3 &spacing)
const ValueType &origin,
const ValueType &spacing)
: Array(extent, origin, spacing)
{ }
......
......@@ -60,7 +60,7 @@ public:
/// asynchronous operations.
///
VTKM_CONT_EXPORT
vtkm::Scalar GetElapsedTime()
vtkm::Float64 GetElapsedTime()
{
return this->TimerImplementation.GetElapsedTime();
}
......
......@@ -347,15 +347,15 @@ public:
/// number of times to get the progressive time. This method synchronizes all
/// asynchronous operations.
///
VTKM_CONT_EXPORT vtkm::Scalar GetElapsedTime()
VTKM_CONT_EXPORT vtkm::Float64 GetElapsedTime()
{
TimeStamp currentTime = this->GetCurrentTime();
vtkm::Scalar elapsedTime;
elapsedTime = vtkm::Scalar(currentTime.Seconds - this->StartTime.Seconds);
vtkm::Float64 elapsedTime;
elapsedTime = vtkm::Float64(currentTime.Seconds - this->StartTime.Seconds);
elapsedTime +=
(vtkm::Scalar(currentTime.Microseconds - this->StartTime.Microseconds)
/vtkm::Scalar(1000000));
(vtkm::Float64(currentTime.Microseconds - this->StartTime.Microseconds)
/vtkm::Float64(1000000));
return elapsedTime;
}
......
......@@ -40,7 +40,7 @@ static int g_FunctionCalls;
struct TypeListTagString : vtkm::ListTagBase<std::string> { };
struct ScalarFunctor {
void operator()(vtkm::Scalar) const {
void operator()(vtkm::FloatDefault) const {
std::cout << " In Scalar functor." << std::endl;
g_FunctionCalls++;
}
......@@ -51,7 +51,7 @@ struct ArrayHandleScalarFunctor {
void operator()(const vtkm::cont::ArrayHandle<T> &) const {
VTKM_TEST_FAIL("Called wrong form of functor operator.");
}
void operator()(const vtkm::cont::ArrayHandle<vtkm::Scalar> &) const {
void operator()(const vtkm::cont::ArrayHandle<vtkm::FloatDefault> &) const {
std::cout << " In ArrayHandle<Scalar> functor." << std::endl;
g_FunctionCalls++;
}
......@@ -71,8 +71,8 @@ struct FunctionInterfaceFunctor {
}
void operator()(
const vtkm::internal::FunctionInterface<
void(vtkm::cont::ArrayHandle<vtkm::Scalar>,
vtkm::cont::ArrayHandle<vtkm::Scalar>,
void(vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<std::string>,
vtkm::cont::ArrayHandleUniformPointCoordinates)> &) const {
std::cout << " In FunctionInterface<...> functor." << std::endl;
......@@ -87,10 +87,10 @@ void TestBasicTransform()
vtkm::cont::internal::DynamicTransform transform;
std::cout << " Trying with simple scalar." << std::endl;
TRY_TRANSFORM(transform(vtkm::Scalar(5), ScalarFunctor()));
TRY_TRANSFORM(transform(vtkm::FloatDefault(5), ScalarFunctor()));
std::cout << " Trying with basic scalar array." << std::endl;
vtkm::cont::ArrayHandle<vtkm::Scalar> concreteArray;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> concreteArray;
TRY_TRANSFORM(transform(concreteArray, ArrayHandleScalarFunctor()));
std::cout << " Trying scalar dynamic array." << std::endl;
......@@ -107,7 +107,7 @@ void TestFunctionTransform()
{
std::cout << "Testing transforms in FunctionInterface." << std::endl;
vtkm::cont::ArrayHandle<vtkm::Scalar> scalarArray;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> scalarArray;
vtkm::cont::ArrayHandle<std::string> stringArray;
vtkm::cont::ArrayHandleUniformPointCoordinates pointCoordinatesArray;
......
......@@ -120,7 +120,7 @@ private:
typedef vtkm::cont::ArrayHandle<vtkm::Id, StorageTag>
IdArrayHandle;
typedef vtkm::cont::ArrayHandle<vtkm::Scalar,StorageTag>
typedef vtkm::cont::ArrayHandle<vtkm::FloatDefault,StorageTag>
ScalarArrayHandle;
typedef vtkm::cont::internal::ArrayManagerExecution<
......@@ -134,8 +134,8 @@ private:
typedef typename IdArrayHandle::template ExecutionTypes<DeviceAdapterTag>
::PortalConst IdPortalConstType;
typedef vtkm::cont::ArrayHandle<vtkm::Vector3,StorageTag>
Vector3ArrayHandle;
typedef vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault,3>,StorageTag>
Vec3ArrayHandle;
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag>
Algorithm;
......@@ -357,26 +357,26 @@ private:
std::cout << "Testing ArrayManagerExecution" << std::endl;
typedef vtkm::cont::internal::ArrayManagerExecution<
vtkm::Scalar,StorageTagBasic,DeviceAdapterTag>
vtkm::FloatDefault,StorageTagBasic,DeviceAdapterTag>
ArrayManagerExecution;
// Create original input array.
vtkm::Scalar inputArray[ARRAY_SIZE*2];
vtkm::FloatDefault inputArray[ARRAY_SIZE*2];
for (vtkm::Id index = 0; index < ARRAY_SIZE*2; index++)
{
inputArray[index] = vtkm::Scalar(index);
inputArray[index] = vtkm::FloatDefault(index);
}
::vtkm::cont::internal::ArrayPortalFromIterators<vtkm::Scalar *>
::vtkm::cont::internal::ArrayPortalFromIterators<vtkm::FloatDefault *>
inputPortal(inputArray, inputArray+ARRAY_SIZE*2);
ArrayManagerExecution inputManager;
inputManager.LoadDataForInput(
::vtkm::cont::internal::ArrayPortalFromIterators<const vtkm::Scalar*>(inputPortal));
::vtkm::cont::internal::ArrayPortalFromIterators<const vtkm::FloatDefault*>(inputPortal));
// Change size.
inputManager.Shrink(ARRAY_SIZE);
// Copy array back.
vtkm::Scalar outputArray[ARRAY_SIZE];
vtkm::FloatDefault outputArray[ARRAY_SIZE];
vtkm::cont::ArrayPortalToIterators<
typename ArrayManagerExecution::PortalConstType>
iterators(inputManager.GetPortalConst());
......@@ -437,7 +437,7 @@ private:
Sleep(1000);
#endif
vtkm::Scalar elapsedTime = timer.GetElapsedTime();
vtkm::FloatDefault elapsedTime = timer.GetElapsedTime();
std::cout << "Elapsed time: " << elapsedTime << std::endl;
......@@ -562,7 +562,7 @@ private:
// VTKM_TEST_ASSERT(singleElement[0] == 1234,
// "output of single scheduling is incorrect");
// std::vector<vtkm::Scalar> field(ARRAY_SIZE);
// std::vector<vtkm::FloatDefault> field(ARRAY_SIZE);
// for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
// {
// field[i]=i;
......@@ -580,8 +580,8 @@ private:
// for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
// {
// vtkm::Scalar squareValue = multPortal.Get(i);
// vtkm::Scalar squareTrue = field[i]*field[i];
// vtkm::FloatDefault squareValue = multPortal.Get(i);
// vtkm::FloatDefault squareTrue = field[i]*field[i];
// VTKM_TEST_ASSERT(test_equal(squareValue, squareTrue),
// "Got bad multiply result");
// }
......@@ -592,15 +592,15 @@ private:
// for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
// {
// vtkm::Scalar squareValue = multPortal.Get(i);
// vtkm::Scalar squareTrue = field[i]*4.0f;
// vtkm::FloatDefault squareValue = multPortal.Get(i);
// vtkm::FloatDefault squareTrue = field[i]*4.0f;
// VTKM_TEST_ASSERT(test_equal(squareValue, squareTrue),
// "Got bad multiply result");
// }
// std::cout << "Testing Schedule on Subset" << std::endl;
// std::vector<vtkm::Scalar> fullField(ARRAY_SIZE);
// std::vector<vtkm::FloatDefault> fullField(ARRAY_SIZE);
// std::vector<vtkm::Id> subSetLookup(ARRAY_SIZE/2);
// for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
// {
......@@ -852,10 +852,10 @@ private:
// }
// IdArrayHandle keys = MakeArrayHandle(testKeys, ARRAY_SIZE);
// Vector3ArrayHandle values = MakeArrayHandle(testValues, ARRAY_SIZE);
// Vec3ArrayHandle values = MakeArrayHandle(testValues, ARRAY_SIZE);
// IdArrayHandle sorted_keys;
// Vector3ArrayHandle sorted_values;
// Vec3ArrayHandle sorted_values;
// Algorithm::Copy(keys,sorted_keys);
// Algorithm::Copy(values,sorted_values);
......@@ -865,7 +865,7 @@ private:
// {
// //keys should be sorted from 1 to ARRAY_SIZE
// //values should be sorted from (ARRAY_SIZE-1) to 0
// vtkm::Scalar sorted_value =
// vtkm::FloatDefault sorted_value =
// sorted_values.GetPortalConstControl().Get(i)[0];
// vtkm::Id sorted_key = sorted_keys.GetPortalConstControl().Get(i);
......@@ -880,7 +880,7 @@ private:
// {
// //keys should be sorted from ARRAY_SIZE to 1
// //values should be sorted from 0 to (ARRAY_SIZE-1)
// vtkm::Scalar sorted_value =
// vtkm::FloatDefault sorted_value =
// sorted_values.GetPortalConstControl().Get(i)[0];
// vtkm::Id sorted_key = sorted_keys.GetPortalConstControl().Get(i);
......@@ -896,7 +896,7 @@ private:
// {
// //keys should be sorted from ARRAY_SIZE to 1
// //values should be sorted from 0 to (ARRAY_SIZE-1)
// vtkm::Scalar sorted_value =
// vtkm::FloatDefault sorted_value =
// sorted_values.GetPortalConstControl().Get(i)[0];
// vtkm::Id sorted_key = sorted_keys.GetPortalConstControl().Get(i);
......@@ -1119,7 +1119,7 @@ private:
// vtkm::Vector3 trueGradient = vtkm::make_Vector3(1.0, 1.0, 1.0);
// std::vector<vtkm::Scalar> field(grid->GetNumberOfPoints());
// std::vector<vtkm::FloatDefault> field(grid->GetNumberOfPoints());
// std::cout << "Number of Points in the grid: "
// << grid->GetNumberOfPoints()
// << std::endl;
......@@ -1147,8 +1147,8 @@ private:
// pointIndex < grid->GetNumberOfPoints();
// pointIndex++)
// {
// vtkm::Scalar squareValue = squarePortal.Get(pointIndex);
// vtkm::Scalar squareTrue = field[pointIndex]*field[pointIndex];
// vtkm::FloatDefault squareValue = squarePortal.Get(pointIndex);
// vtkm::FloatDefault squareTrue = field[pointIndex]*field[pointIndex];
// VTKM_TEST_ASSERT(test_equal(squareValue, squareTrue),
// "Got bad square");
// }
......@@ -1209,7 +1209,7 @@ private:
// vtkm::Vector3 trueGradient = vtkm::make_Vector3(1.0, 1.0, 1.0);
// std::vector<vtkm::Scalar> field(grid->GetNumberOfPoints());
// std::vector<vtkm::FloatDefault> field(grid->GetNumberOfPoints());
// for (vtkm::Id pointIndex = 0;
// pointIndex < grid->GetNumberOfPoints();
// pointIndex++)
......@@ -1219,7 +1219,7 @@ private:
// }
// ScalarArrayHandle fieldHandle = MakeArrayHandle(field);
// Vector3ArrayHandle gradientHandle;
// Vec3ArrayHandle gradientHandle;
// std::cout << "Running CellGradient worklet" << std::endl;
......@@ -1230,7 +1230,7 @@ private:
// fieldHandle,
// gradientHandle);
// typename Vector3ArrayHandle::PortalConstControl gradientPortal =
// typename Vec3ArrayHandle::PortalConstControl gradientPortal =
// gradientHandle.GetPortalConstControl();
// std::cout << "Checking result" << std::endl;
......
......@@ -25,6 +25,8 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/testing/Testing.h>
#include <algorithm>
......@@ -32,9 +34,32 @@
namespace {
const vtkm::Id ARRAY_SIZE = 10;
vtkm::Scalar TestValue(vtkm::Id index)
template<typename T>
T TestValue(vtkm::Id index, T, vtkm::TypeTraitsIntegerTag)
{
return static_cast<vtkm::Scalar>(10.0*index + 0.01*(index+1));
return T(index*100);
}
template<typename T>
T TestValue(vtkm::Id index, T, vtkm::TypeTraitsRealTag)
{
return T(10.0*index + 0.01*(index+1))/100;
}
template<typename T>
T TestValue(vtkm::Id index, T)
{
return TestValue(index, T(), typename vtkm::TypeTraits<T>::NumericTag());
}
template<typename T, vtkm::IdComponent N>
vtkm::Vec<T,N> TestValue(vtkm::Id index, vtkm::Vec<T,N>) {
vtkm::Vec<T,N> value;
for (vtkm::IdComponent i = 0; i < N; i++)
{
value[i] = TestValue(index, T()) + (i + 1);
}
return value;
}
template<class IteratorType>
......@@ -43,7 +68,7 @@ bool CheckIterators(IteratorType begin, IteratorType end)
vtkm::Id index = 0;
for (IteratorType iter = begin; iter != end; iter++)
{
if (!test_equal(*iter, TestValue(index))) { return false; }
if (!test_equal(*iter, TestValue(index, *iter))) { return false; }
index++;
}
return true;
......@@ -62,105 +87,113 @@ bool CheckArray(const vtkm::cont::ArrayHandle<T> &handle)
return CheckPortal(handle.GetPortalConstControl());
}
void TestArrayHandle()
struct TryArrayHandleType
{
std::cout << "Create array handle." << std::endl;
vtkm::Scalar array[ARRAY_SIZE];
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
template<typename T>
void operator()(T) const
{
array[index] = TestValue(index);
}
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalControl arrayPortal(
&array[0], &array[ARRAY_SIZE]);
std::cout << "Create array handle." << std::endl;
T array[ARRAY_SIZE];
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
array[index] = TestValue(index, T());
}
vtkm::cont::ArrayHandle<vtkm::Scalar>
arrayHandle(arrayPortal);
typename vtkm::cont::ArrayHandle<T>::PortalControl arrayPortal(
&array[0], &array[ARRAY_SIZE]);
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"ArrayHandle has wrong number of entries.");
vtkm::cont::ArrayHandle<T> arrayHandle(arrayPortal);
std::cout << "Check basic array." << std::endl;
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
"Array values not set correctly.");
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"ArrayHandle has wrong number of entries.");
std::cout << "Check out execution array behavior." << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::PortalConst
executionPortal;
executionPortal =
arrayHandle.PrepareForInput(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
VTKM_TEST_ASSERT(CheckPortal(executionPortal),
"Array not copied to execution correctly.");
}
std::cout << "Check basic array." << std::endl;
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
"Array values not set correctly.");
{
bool gotException = false;
try
std::cout << "Check out execution array behavior." << std::endl;
{
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
typename vtkm::cont::ArrayHandle<T>::template
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::PortalConst
executionPortal;
executionPortal =
arrayHandle.PrepareForInput(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
VTKM_TEST_ASSERT(CheckPortal(executionPortal),
"Array not copied to execution correctly.");
}
catch (vtkm::cont::Error &error)
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
gotException = true;
bool gotException = false;
try
{
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
}
catch (vtkm::cont::Error &error)
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
gotException = true;
}
VTKM_TEST_ASSERT(gotException,
"PrepareForInPlace did not fail for const array.");
}
VTKM_TEST_ASSERT(gotException,
"PrepareForInPlace did not fail for const array.");
}
{
typedef vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal
ExecutionPortalType;
ExecutionPortalType executionPortal =
arrayHandle.PrepareForOutput(ARRAY_SIZE*2,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
for (vtkm::Id index = 0;
index < executionPortal.GetNumberOfValues();
index++)
{
executionPortal.Set(index, TestValue(index));
typedef typename vtkm::cont::ArrayHandle<T>::template
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal
ExecutionPortalType;
ExecutionPortalType executionPortal =
arrayHandle.PrepareForOutput(ARRAY_SIZE*2,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
for (vtkm::Id index = 0;
index < executionPortal.GetNumberOfValues();
index++)
{
executionPortal.Set(index, TestValue(index, T()));
}
}
}
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
"Array not allocated correctly.");
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
"Array values not retrieved from execution.");
std::cout << "Try shrinking the array." << std::endl;
arrayHandle.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"Array size did not shrink correctly.");
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
"Array values not retrieved from execution.");
std::cout << "Try in place operation." << std::endl;
{
typedef vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal
ExecutionPortalType;
ExecutionPortalType executionPortal =
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
for (vtkm::Id index = 0;
index < executionPortal.GetNumberOfValues();
index++)
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
"Array not allocated correctly.");
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
"Array values not retrieved from execution.");
std::cout << "Try shrinking the array." << std::endl;
arrayHandle.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"Array size did not shrink correctly.");
VTKM_TEST_ASSERT(CheckArray(arrayHandle),