Merge branch 'astyle_applied'

This commit is contained in:
Robert Maynard 2014-02-11 16:21:08 -05:00
commit f2552645e0
44 changed files with 1107 additions and 992 deletions

@ -45,7 +45,7 @@ if (NOT VTKm_SOURCE_DIR)
message(SEND_ERROR "VTKm_SOURCE_DIR not defined.")
endif (NOT VTKm_SOURCE_DIR)
set(copyright_file ${VTKm_SOURCE_DIR}/CMake/VTKMCopyrightStatement.txt)
set(copyright_file ${VTKm_SOURCE_DIR}/CMake/VTKmCopyrightStatement.txt)
if (NOT EXISTS ${copyright_file})
message(SEND_ERROR "Cannot find VTKMCopyrightStatement.txt.")

@ -57,7 +57,8 @@ template<typename T> struct TypeTraits;
/// override behavior of called functions.
///
template<typename T>
class TypeTraits {
class TypeTraits
{
typedef int tag_type; // Shut up, test compile.
public:
@ -82,16 +83,16 @@ struct TypeTraits<const T> : TypeTraits<T>
{ };
#define VTKM_BASIC_REAL_TYPE(T) \
template<> struct TypeTraits<T> { \
typedef TypeTraitsRealTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
template<> struct TypeTraits<T> { \
typedef TypeTraitsRealTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
#define VTKM_BASIC_INTEGER_TYPE(T) \
template<> struct TypeTraits<T> { \
typedef TypeTraitsIntegerTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
template<> struct TypeTraits<T> { \
typedef TypeTraitsIntegerTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
/// Traits for basic C++ types.
///
@ -118,10 +119,10 @@ VTKM_BASIC_INTEGER_TYPE(unsigned long long);
#undef VTKM_BASIC_INTEGER_TYPE
#define VTKM_VECTOR_TYPE(T, NTag) \
template<> struct TypeTraits<T> { \
typedef NTag NumericTag; \
typedef TypeTraitsVectorTag DimensionalityTag; \
}
template<> struct TypeTraits<T> { \
typedef NTag NumericTag; \
typedef TypeTraitsVectorTag DimensionalityTag; \
}
/// Traits for vector types.
///
@ -135,7 +136,8 @@ VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag);
/// Traits for tuples.
///
template<typename T, int Size> struct TypeTraits<vtkm::Tuple<T, Size> > {
template<typename T, int Size> struct TypeTraits<vtkm::Tuple<T, Size> >
{
typedef typename TypeTraits<T>::NumericTag NumericTag;
typedef TypeTraitsVectorTag DimensionalityTag;
};

@ -79,8 +79,7 @@
*
*/
namespace vtkm
{
namespace vtkm {
//*****************************************************************************
// Typedefs for basic types.
//*****************************************************************************
@ -179,7 +178,8 @@ struct assign_scalar_to_vector<2>
VTKM_EXEC_CONT_EXPORT
void operator()(VectorType &dest, const ComponentType &src)
{
dest[0] = src; dest[1] = src;
dest[0] = src;
dest[1] = src;
}
};
@ -190,7 +190,9 @@ struct assign_scalar_to_vector<3>
VTKM_EXEC_CONT_EXPORT
void operator()(VectorType &dest, const ComponentType &src)
{
dest[0] = src; dest[1] = src; dest[2] = src;
dest[0] = src;
dest[1] = src;
dest[2] = src;
}
};
@ -221,7 +223,8 @@ struct copy_vector<2>
template<typename T1, typename T2>
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
{
dest[0] = src[0]; dest[1] = src[1];
dest[0] = src[0];
dest[1] = src[1];
}
};
@ -231,7 +234,9 @@ struct copy_vector<3>
template<typename T1, typename T2>
VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src)
{
dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2];
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
}
};
@ -270,49 +275,52 @@ typedef float Scalar __attribute__ ((aligned(VTKM_SIZE_SCALAR)));
/// Tuple corresponds to a Size-tuple of type T
template<typename T, int Size>
class Tuple {
class Tuple
{
public:
typedef T ComponentType;
static const int NUM_COMPONENTS=Size;
VTKM_EXEC_CONT_EXPORT Tuple(){}
VTKM_EXEC_CONT_EXPORT Tuple() {}
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
{
for(int i=0; i < NUM_COMPONENTS; ++i)
{
for(int i=0; i < NUM_COMPONENTS;++i)
{
this->Components[i]=value;
}
}
}
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values)
{
for(int i=0; i < NUM_COMPONENTS; ++i)
{
for(int i=0; i < NUM_COMPONENTS;++i)
{
this->Components[i]=values[i];
}
}
}
VTKM_EXEC_CONT_EXPORT
Tuple(const Tuple<ComponentType, Size> &src)
{
for (int i = 0; i < NUM_COMPONENTS; i++)
{
{
this->Components[i] = src[i];
}
}
}
VTKM_EXEC_CONT_EXPORT
Tuple<ComponentType, Size> &operator=(const Tuple<ComponentType, Size> &src)
{
for (int i = 0; i < NUM_COMPONENTS; i++)
{
{
this->Components[i] = src[i];
}
}
return *this;
}
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const
{
return this->Components[idx];
}
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx)
{
return this->Components[idx];
}
@ -321,9 +329,9 @@ public:
{
bool same = true;
for (int componentIndex=0; componentIndex<NUM_COMPONENTS; componentIndex++)
{
{
same &= (this->Components[componentIndex] == other[componentIndex]);
}
}
return same;
}
@ -331,14 +339,14 @@ public:
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
{
for(vtkm::Id i=0; i < NUM_COMPONENTS; ++i)
{
{
//ignore equals as that represents check next value
if(this->Components[i] < other[i])
return true;
{ return true; }
else if(other[i] < this->Components[i])
return false;
} //if all same we are not less
return false;
{ return false; }
} //if all same we are not less
return false;
}
VTKM_EXEC_CONT_EXPORT
@ -355,12 +363,13 @@ protected:
// Specializations for common tuple sizes (with special names).
template<typename T>
class Tuple<T,2>{
class Tuple<T,2>
{
public:
typedef T ComponentType;
static const int NUM_COMPONENTS = 2;
VTKM_EXEC_CONT_EXPORT Tuple(){}
VTKM_EXEC_CONT_EXPORT Tuple() {}
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
{
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
@ -369,7 +378,8 @@ public:
{
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
}
VTKM_EXEC_CONT_EXPORT Tuple(ComponentType x, ComponentType y) {
VTKM_EXEC_CONT_EXPORT Tuple(ComponentType x, ComponentType y)
{
this->Components[0] = x;
this->Components[1] = y;
}
@ -387,10 +397,12 @@ public:
return *this;
}
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const
{
return this->Components[idx];
}
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx)
{
return this->Components[idx];
}
@ -408,9 +420,9 @@ public:
VTKM_EXEC_CONT_EXPORT
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
{
return( (this->Components[0] < other[0]) ||
(!(other[0] < this->Components[0]) && (this->Components[1] < other[1]))
);
return( (this->Components[0] < other[0]) ||
(!(other[0] < this->Components[0]) && (this->Components[1] < other[1]))
);
}
protected:
@ -426,12 +438,13 @@ typedef vtkm::Tuple<vtkm::Scalar,2>
typedef vtkm::Tuple<vtkm::Id,2> Id2 __attribute__ ((aligned(VTKM_SIZE_ID)));
template<typename T>
class Tuple<T,3>{
class Tuple<T,3>
{
public:
typedef T ComponentType;
static const int NUM_COMPONENTS = 3;
VTKM_EXEC_CONT_EXPORT Tuple(){}
VTKM_EXEC_CONT_EXPORT Tuple() {}
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
{
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
@ -441,7 +454,8 @@ public:
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
}
VTKM_EXEC_CONT_EXPORT
Tuple(ComponentType x, ComponentType y, ComponentType z) {
Tuple(ComponentType x, ComponentType y, ComponentType z)
{
this->Components[0] = x;
this->Components[1] = y;
this->Components[2] = z;
@ -460,10 +474,12 @@ public:
return *this;
}
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const
{
return this->Components[idx];
}
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx)
{
return this->Components[idx];
}
@ -481,12 +497,12 @@ public:
VTKM_EXEC_CONT_EXPORT
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
{
return((this->Components[0] < other[0]) ||
( !(other[0] < this->Components[0]) &&
(this->Components[1] < other[1])) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
(this->Components[2] < other[2]) ) );
return((this->Components[0] < other[0]) ||
( !(other[0] < this->Components[0]) &&
(this->Components[1] < other[1])) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
(this->Components[2] < other[2]) ) );
}
protected:
@ -498,12 +514,13 @@ typedef vtkm::Tuple<vtkm::Scalar,3>
Vector3 __attribute__ ((aligned(VTKM_SIZE_SCALAR)));
template<typename T>
class Tuple<T,4>{
class Tuple<T,4>
{
public:
typedef T ComponentType;
static const int NUM_COMPONENTS = 4;
VTKM_EXEC_CONT_EXPORT Tuple(){}
VTKM_EXEC_CONT_EXPORT Tuple() {}
VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value)
{
internal::assign_scalar_to_vector<NUM_COMPONENTS>()(this->Components,value);
@ -513,7 +530,8 @@ public:
internal::copy_vector<NUM_COMPONENTS>()(this->Components, values);
}
VTKM_EXEC_CONT_EXPORT
Tuple(ComponentType x, ComponentType y, ComponentType z, ComponentType w) {
Tuple(ComponentType x, ComponentType y, ComponentType z, ComponentType w)
{
this->Components[0] = x;
this->Components[1] = y;
this->Components[2] = z;
@ -533,10 +551,12 @@ public:
return *this;
}
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const {
VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const
{
return this->Components[idx];
}
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) {
VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx)
{
return this->Components[idx];
}
@ -554,16 +574,16 @@ public:
VTKM_EXEC_CONT_EXPORT
bool operator<(const Tuple<T,NUM_COMPONENTS> &other) const
{
return((this->Components[0] < other[0]) ||
( !(other[0] < this->Components[0]) &&
this->Components[1] < other[1]) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
(this->Components[2] < other[2]) ) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
!(other[2] < this->Components[2]) &&
(this->Components[3] < other[3])) );
return((this->Components[0] < other[0]) ||
( !(other[0] < this->Components[0]) &&
this->Components[1] < other[1]) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
(this->Components[2] < other[2]) ) ||
( !(other[0] < this->Components[0]) &&
!(other[1] < this->Components[1]) &&
!(other[2] < this->Components[2]) &&
(this->Components[3] < other[3])) );
}
protected:
@ -611,13 +631,13 @@ VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z)
template<typename T, int Size>
VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Tuple<T,Size> &a,
const vtkm::Tuple<T,Size> &b)
const vtkm::Tuple<T,Size> &b)
{
T result = a[0]*b[0];
for (int componentIndex = 1; componentIndex < Size; componentIndex++)
{
{
result += a[componentIndex]*b[componentIndex];
}
}
return result;
}
@ -639,9 +659,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator+(const vtkm::Tuple<T,Size> &a
{
vtkm::Tuple<T,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a[componentIndex] + b[componentIndex];
}
}
return result;
}
template<typename T, int Size>
@ -650,9 +670,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator-(const vtkm::Tuple<T,Size> &a
{
vtkm::Tuple<T,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a[componentIndex] - b[componentIndex];
}
}
return result;
}
template<typename T, int Size>
@ -661,9 +681,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator*(const vtkm::Tuple<T,Size> &a
{
vtkm::Tuple<T,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a[componentIndex] * b[componentIndex];
}
}
return result;
}
template<typename T, int Size>
@ -672,9 +692,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<T,Size> operator/(const vtkm::Tuple<T,Size> &a
{
vtkm::Tuple<T,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a[componentIndex] / b[componentIndex];
}
}
return result;
}
@ -684,9 +704,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<Ta,Size> operator*(const vtkm::Tuple<Ta,Size>
{
vtkm::Tuple<Ta,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a[componentIndex] * b;
}
}
return result;
}
template<typename Ta, typename Tb, int Size>
@ -695,9 +715,9 @@ VTKM_EXEC_CONT_EXPORT vtkm::Tuple<Tb,Size> operator*(const Ta &a,
{
vtkm::Tuple<Tb,Size> result;
for (int componentIndex = 0; componentIndex < Size; componentIndex++)
{
{
result[componentIndex] = a * b[componentIndex];
}
}
return result;
}

@ -38,12 +38,14 @@ struct VectorTraitsTagSingleComponent { };
namespace internal {
template<int numComponents>
struct VectorTraitsMultipleComponentChooser {
struct VectorTraitsMultipleComponentChooser
{
typedef VectorTraitsTagMultipleComponents Type;
};
template<>
struct VectorTraitsMultipleComponentChooser<1> {
struct VectorTraitsMultipleComponentChooser<1>
{
typedef VectorTraitsTagSingleComponent Type;
};

@ -73,53 +73,53 @@ public:
void ReleaseResources()
{
if (this->NumberOfValues > 0)
{
{
VTKM_ASSERT_CONT(this->Array != NULL);
AllocatorType allocator;
allocator.deallocate(this->Array, this->AllocatedSize);
this->Array = NULL;
this->NumberOfValues = 0;
this->AllocatedSize = 0;
}
}
else
{
{
VTKM_ASSERT_CONT(this->Array == NULL);
}
}
}
void Allocate(vtkm::Id numberOfValues)
{
if (numberOfValues <= this->AllocatedSize)
{
{
this->NumberOfValues = numberOfValues;
return;
}
}
this->ReleaseResources();
try
{
{
if (numberOfValues > 0)
{
{
AllocatorType allocator;
this->Array = allocator.allocate(numberOfValues);
this->AllocatedSize = numberOfValues;
this->NumberOfValues = numberOfValues;
}
}
else
{
{
// ReleaseResources should have already set AllocatedSize to 0.
VTKM_ASSERT_CONT(this->AllocatedSize == 0);
}
}
}
catch (std::bad_alloc err)
{
{
// Make sureour state is OK.
this->Array = NULL;
this->NumberOfValues = 0;
this->AllocatedSize = 0;
throw vtkm::cont::ErrorControlOutOfMemory(
"Could not allocate basic control array.");
}
"Could not allocate basic control array.");
}
}
vtkm::Id GetNumberOfValues() const
@ -130,10 +130,10 @@ public:
void Shrink(vtkm::Id numberOfValues)
{
if (numberOfValues > this->GetNumberOfValues())
{
{
throw vtkm::cont::ErrorControlBadValue(
"Shrink method cannot be used to grow array.");
}
"Shrink method cannot be used to grow array.");
}
this->NumberOfValues = numberOfValues;
}

@ -44,7 +44,8 @@ namespace cont {
/// and environment do not share memory. This is wasteful and should be fixed.
///
template<class ArrayPortalType>
struct ArrayContainerControlTagImplicit {
struct ArrayContainerControlTagImplicit
{
typedef ArrayPortalType PortalType;
};
@ -61,16 +62,19 @@ public:
// This is meant to be invalid. Because implicit arrays are read only, you
// should only be able to use the const version.
struct PortalType {
struct PortalType
{
typedef void *ValueType;
typedef void *IteratorType;
};
// All these methods do nothing but raise errors.
PortalType GetPortal() {
PortalType GetPortal()
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
PortalConstType GetPortalConst() const {
PortalConstType GetPortalConst() const
{
// This does not work because the ArrayHandle holds the constant
// ArrayPortal, not the container.
throw vtkm::cont::ErrorControlBadValue(
@ -78,7 +82,8 @@ public:
"Perhaps you did not set the ArrayPortal when "
"constructing the ArrayHandle.");
}
vtkm::Id GetNumberOfValues() const {
vtkm::Id GetNumberOfValues() const
{
// This does not work because the ArrayHandle holds the constant
// ArrayPortal, not the container.
throw vtkm::cont::ErrorControlBadValue(
@ -86,13 +91,16 @@ public:
"Perhaps you did not set the ArrayPortal when "
"constructing the ArrayHandle.");
}
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues)) {
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues)) {
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
void ReleaseResources() {
void ReleaseResources()
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
};
@ -117,17 +125,20 @@ public:
ArrayTransfer() : PortalValid(false) { }
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const {
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT_CONT(this->PortalValid);
return this->Portal.GetNumberOfValues();
}
VTKM_CONT_EXPORT void LoadDataForInput(PortalConstControl portal) {
VTKM_CONT_EXPORT void LoadDataForInput(PortalConstControl portal)
{
this->Portal = portal;
this->PortalValid = true;
}
VTKM_CONT_EXPORT void LoadDataForInput(const ContainerType &controlArray) {
VTKM_CONT_EXPORT void LoadDataForInput(const ContainerType &controlArray)
{
this->LoadDataForInput(controlArray.GetPortalConst());
}

@ -80,7 +80,8 @@ public:
typedef typename ArrayContainerControlType::PortalConstType
PortalConstControl;
template <typename DeviceAdapterTag>
struct ExecutionTypes {
struct ExecutionTypes
{
typedef typename ExecutionManagerType
::template ExecutionTypes<DeviceAdapterTag>::Portal Portal;
typedef typename ExecutionManagerType
@ -115,22 +116,22 @@ public:
{
this->SyncControlArray();
if (this->Internals->UserPortalValid)
{
{
throw vtkm::cont::ErrorControlBadValue(
"ArrayHandle has a read-only control portal.");
}
"ArrayHandle has a read-only control portal.");
}
else if (this->Internals->ControlArrayValid)
{
{
// If the user writes into the iterator we return, then the execution
// array will become invalid. Play it safe and release the execution
// resources. (Use the const version to preserve the execution array.)
this->ReleaseResourcesExecution();
return this->Internals->ControlArray.GetPortal();
}
}
else
{
{
throw vtkm::cont::ErrorControlBadValue("ArrayHandle contains no data.");
}
}
}
/// Get the array portal of the control array.
@ -139,17 +140,17 @@ public:
{
this->SyncControlArray();
if (this->Internals->UserPortalValid)
{
{
return this->Internals->UserPortal;
}
}
else if (this->Internals->ControlArrayValid)
{
{
return this->Internals->ControlArray.GetPortalConst();
}
}
else
{
{
throw vtkm::cont::ErrorControlBadValue("ArrayHandle contains no data.");
}
}
}
/// Returns the number of entries in the array.
@ -157,22 +158,22 @@ public:
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
{
if (this->Internals->UserPortalValid)
{
{
return this->Internals->UserPortal.GetNumberOfValues();
}
}
else if (this->Internals->ControlArrayValid)
{
{
return this->Internals->ControlArray.GetNumberOfValues();
}
}
else if (this->Internals->ExecutionArrayValid)
{
{
return
this->Internals->ExecutionArray->GetNumberOfValues();
}
this->Internals->ExecutionArray->GetNumberOfValues();
}
else
{
{
return 0;
}
}
}
/// \brief Reduces the size of the array without changing its values.
@ -188,30 +189,30 @@ public:
vtkm::Id originalNumberOfValues = this->GetNumberOfValues();
if (numberOfValues < originalNumberOfValues)
{
{
if (this->Internals->UserPortalValid)
{
{
throw vtkm::cont::ErrorControlBadValue(
"ArrayHandle has a read-only control portal.");
}
"ArrayHandle has a read-only control portal.");
}
if (this->Internals->ControlArrayValid)
{
{
this->Internals->ControlArray.Shrink(numberOfValues);
}
}
if (this->Internals->ExecutionArrayValid)
{
{
this->Internals->ExecutionArray->Shrink(numberOfValues);
}
}
}
else if (numberOfValues == originalNumberOfValues)
{
{
// Nothing to do.
}
}
else // numberOfValues > originalNumberOfValues
{
{
throw vtkm::cont::ErrorControlBadValue(
"ArrayHandle::Shrink cannot be used to grow array.");
}
"ArrayHandle::Shrink cannot be used to grow array.");
}
VTKM_ASSERT_CONT(this->GetNumberOfValues() == numberOfValues);
}
@ -222,10 +223,10 @@ public:
VTKM_CONT_EXPORT void ReleaseResourcesExecution()
{
if (this->Internals->ExecutionArrayValid)
{
{
this->Internals->ExecutionArray->ReleaseResources();
this->Internals->ExecutionArrayValid = false;
}
}
}
/// Releases all resources in both the control and execution environments.
@ -238,10 +239,10 @@ public:
this->Internals->UserPortalValid = false;
if (this->Internals->ControlArrayValid)
{
{
this->Internals->ControlArray.ReleaseResources();
this->Internals->ControlArrayValid = false;
}
}
}
/// Prepares this array to be used as an input to an operation in the
@ -258,31 +259,31 @@ public:
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
if (this->Internals->ExecutionArrayValid)
{
{
// Nothing to do, data already loaded.
}
}
else if (this->Internals->UserPortalValid)
{
{
VTKM_ASSERT_CONT(!this->Internals->ControlArrayValid);
this->PrepareForDevice(DeviceAdapterTag());
this->Internals->ExecutionArray->LoadDataForInput(
this->Internals->UserPortal);
this->Internals->UserPortal);
this->Internals->ExecutionArrayValid = true;
}
}
else if (this->Internals->ControlArrayValid)
{
{
this->PrepareForDevice(DeviceAdapterTag());
this->Internals->ExecutionArray->LoadDataForInput(
this->Internals->ControlArray);
this->Internals->ControlArray);
this->Internals->ExecutionArrayValid = true;
}
}
else
{
{
throw vtkm::cont::ErrorControlBadValue(
"ArrayHandle has no data when PrepareForInput called.");
}
"ArrayHandle has no data when PrepareForInput called.");
}
return this->Internals->ExecutionArray->GetPortalConstExecution(
DeviceAdapterTag());
DeviceAdapterTag());
}
/// Prepares (allocates) this array to be used as an output from an operation
@ -307,7 +308,7 @@ public:
this->PrepareForDevice(DeviceAdapterTag());
this->Internals->ExecutionArray->AllocateArrayForOutput(
this->Internals->ControlArray, numberOfValues);
this->Internals->ControlArray, numberOfValues);
// We are assuming that the calling code will fill the array using the
// iterators we are returning, so go ahead and mark the execution array as
@ -337,32 +338,32 @@ public:
VTKM_IS_DEVICE_ADAPTER_TAG(DeviceAdapterTag);
if (this->Internals->UserPortalValid)
{
{
throw vtkm::cont::ErrorControlBadValue(
"In place execution cannot be used with an ArrayHandle that has "
"user arrays because this might write data back into user space "
"unexpectedly. Copy the data to a new array first.");
}
"In place execution cannot be used with an ArrayHandle that has "
"user arrays because this might write data back into user space "
"unexpectedly. Copy the data to a new array first.");
}
// This code is similar to PrepareForInput except that we have to give a
// writable portal instead of the const portal to the execution array
// manager so that the data can (potentially) be written to.
if (this->Internals->ExecutionArrayValid)
{
{
// Nothing to do, data already loaded.
}
}
else if (this->Internals->ControlArrayValid)
{
{
this->PrepareForDevice(DeviceAdapterTag());
this->Internals->ExecutionArray->LoadDataForInPlace(
this->Internals->ControlArray);
this->Internals->ControlArray);
this->Internals->ExecutionArrayValid = true;
}
}
else
{
{
throw vtkm::cont::ErrorControlBadValue(
"ArrayHandle has no data when PrepareForInput called.");
}
"ArrayHandle has no data when PrepareForInput called.");
}
// Invalidate any control arrays since their data will become invalid when
// the execution data is overwritten. Don't actually release the control
@ -386,8 +387,9 @@ public:
this->Internals->ExecutionArrayValid = false;
}
// private:
struct InternalStruct {
// private:
struct InternalStruct
{
PortalConstControl UserPortal;
bool UserPortalValid;
@ -400,7 +402,7 @@ public:
bool ExecutionArrayValid;
};
ArrayHandle(boost::shared_ptr<InternalStruct> i)
ArrayHandle(boost::shared_ptr<InternalStruct> i)
: Internals(i)
{ }
@ -414,14 +416,14 @@ public:
void PrepareForDevice(DeviceAdapterTag) const
{
if (this->Internals->ExecutionArray != NULL)
{
{
if (this->Internals->ExecutionArray->IsDeviceAdapter(DeviceAdapterTag()))
{
{
// Already have manager for correct device adapter. Nothing to do.
return;
}
}
else
{
{
// Have the wrong manager. Delete the old one and create a new one
// of the right type. (BTW, it would be possible for the array handle
// to hold references to execution arrays on multiple devices. However,
@ -458,23 +460,23 @@ public:
VTKM_CONT_EXPORT void SyncControlArray() const
{
if ( !this->Internals->UserPortalValid
&& !this->Internals->ControlArrayValid)
{
&& !this->Internals->ControlArrayValid)
{
// Need to change some state that does not change the logical state from
// an external point of view.
InternalStruct *internals
= const_cast<InternalStruct*>(this->Internals.get());
= const_cast<InternalStruct*>(this->Internals.get());
internals->ExecutionArray->RetrieveOutputData(internals->ControlArray);
internals->ControlArrayValid = true;
}
}
else
{
{
// It should never be the case that both the user and control array are
// valid.
VTKM_ASSERT_CONT(!this->Internals->UserPortalValid
|| !this->Internals->ControlArrayValid);
|| !this->Internals->ControlArrayValid);
// Nothing to do.
}
}
}
boost::shared_ptr<InternalStruct> Internals;

@ -38,14 +38,14 @@ public:
VTKM_EXEC_CONT_EXPORT
ArrayPortalCounting() :
StartingValue(),
NumberOfValues(0)
StartingValue(),
NumberOfValues(0)
{ }
VTKM_EXEC_CONT_EXPORT
ArrayPortalCounting(ValueType startingValue, vtkm::Id numValues) :
StartingValue(startingValue),
NumberOfValues(numValues)
StartingValue(startingValue),
NumberOfValues(numValues)
{ }
template<typename OtherValueType>
@ -58,7 +58,7 @@ public:
template<typename OtherValueType>
VTKM_EXEC_CONT_EXPORT
ArrayPortalCounting<ValueType> &operator=(
const ArrayPortalCounting<OtherValueType> &src)
const ArrayPortalCounting<OtherValueType> &src)
{
this->StartingValue = src.StartingValue;
this->NumberOfValues = src.NumberOfValues;

@ -44,18 +44,18 @@ namespace vtkm {
namespace cont {
VTKM_CONT_EXPORT void Assert(bool condition,
const std::string &file,
vtkm::Id line,
const std::string &message)
const std::string &file,
vtkm::Id line,
const std::string &message)
{
if (condition)
{
{
// Do nothing.
}
}
else
{
{
throw vtkm::cont::ErrorControlAssert(file, line, message);
}
}
}
}

@ -40,7 +40,8 @@ protected:
Error() { }
Error(const std::string message) : Message(message) { }
void SetMessage(const std::string &message) {
void SetMessage(const std::string &message)
{
this->Message = message;
}

@ -40,7 +40,8 @@ private:
public:
template <typename DeviceAdapter>
struct ExecutionTypes {
struct ExecutionTypes
{
private:
typedef vtkm::cont::internal::ArrayTransfer<T,Container,DeviceAdapter>
ArrayTransferType;
@ -158,17 +159,17 @@ public:
bool IsDeviceAdapter(DeviceAdapter) const
{
return this->IsDeviceAdapterImpl(
vtkm::cont::internal::DeviceAdapterTraits<DeviceAdapter>::GetId());
vtkm::cont::internal::DeviceAdapterTraits<DeviceAdapter>::GetId());
}
protected:
virtual void GetPortalExecutionImpl(void *portalExecution) = 0;
virtual void GetPortalConstExecutionImpl(
void *portalConstExecution) const = 0;
void *portalConstExecution) const = 0;
virtual bool IsDeviceAdapterImpl(
const vtkm::cont::internal::DeviceAdapterId &id) const = 0;
const vtkm::cont::internal::DeviceAdapterId &id) const = 0;
private:
template<typename DeviceAdapter>
@ -176,9 +177,9 @@ private:
void VerifyDeviceAdapter(DeviceAdapter device) const
{
if (!this->IsDeviceAdapter(device))
{
{
throw vtkm::cont::ErrorControlInternal("Device Adapter Mismatch");
}
}
}
};
@ -193,7 +194,7 @@ template<typename T,
typename Container,
typename DeviceAdapter>
class ArrayHandleExecutionManager
: public ArrayHandleExecutionManagerBase<T, Container>
: public ArrayHandleExecutionManagerBase<T, Container>
{
typedef ArrayHandleExecutionManagerBase<T, Container> Superclass;
typedef vtkm::cont::internal::ArrayTransfer<T,Container,DeviceAdapter>

@ -56,7 +56,8 @@ public:
/// Returns the size of the saved portal.
///
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const {
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT_CONT(this->ConstPortalValid);
return this->ConstPortal.GetNumberOfValues();
}
@ -106,7 +107,7 @@ public:
{
VTKM_ASSERT_CONT(this->ConstPortalValid);
VTKM_ASSERT_CONT(controlArray.GetPortalConst().GetIteratorBegin() ==
this->ConstPortal.GetIteratorBegin());
this->ConstPortal.GetIteratorBegin());
controlArray.Shrink(this->ConstPortal.GetNumberOfValues());
}
@ -130,9 +131,9 @@ public:
this->ConstPortal.Shrink(numberOfValues);
if (this->PortalValid)
{
{
this->Portal.Shrink(numberOfValues);
}
}
}
/// Returns the portal previously saved from an \c ArrayContainerControl.

@ -61,17 +61,20 @@ public:
{ }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
vtkm::Id GetNumberOfValues() const
{
return std::distance(this->BeginIterator, this->EndIterator);
}
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
ValueType Get(vtkm::Id index) const
{
return *this->IteratorAt(index);
}
VTKM_CONT_EXPORT
void Set(vtkm::Id index, ValueType value) const {
void Set(vtkm::Id index, ValueType value) const
{
*this->IteratorAt(index) = value;
}
@ -86,7 +89,8 @@ private:
IteratorType EndIterator;
VTKM_CONT_EXPORT
IteratorType IteratorAt(vtkm::Id index) const {
IteratorType IteratorAt(vtkm::Id index) const
{
VTKM_ASSERT_CONT(index >= 0);
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());

@ -48,7 +48,7 @@ public:
{ }
VTKM_CONT_EXPORT ArrayPortalShrink(const DelegatePortalType &delegatePortal,
vtkm::Id numberOfValues)
vtkm::Id numberOfValues)
: DelegatePortal(delegatePortal), NumberOfValues(numberOfValues)
{
VTKM_ASSERT_CONT(numberOfValues <= delegatePortal.GetNumberOfValues());
@ -69,26 +69,30 @@ public:
vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
ValueType Get(vtkm::Id index) const
{
VTKM_ASSERT_CONT(index >= 0);
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());
return this->DelegatePortal.Get(index);
}
VTKM_CONT_EXPORT
void Set(vtkm::Id index, ValueType value) const {
void Set(vtkm::Id index, ValueType value) const
{
VTKM_ASSERT_CONT(index >= 0);
VTKM_ASSERT_CONT(index < this->GetNumberOfValues());
this->DelegatePortal.Set(index, value);
}
VTKM_CONT_EXPORT
IteratorType GetIteratorBegin() const {
IteratorType GetIteratorBegin() const
{
return this->DelegatePortal.GetIteratorBegin();
}
VTKM_CONT_EXPORT
IteratorType GetIteratorEnd() const {
IteratorType GetIteratorEnd() const
{
IteratorType iterator = this->DelegatePortal.GetIteratorBegin();
std::advance(iterator, this->GetNumberOfValues());
return iterator;
@ -98,7 +102,8 @@ public:
/// (exposed) array.
///
VTKM_CONT_EXPORT
void Shrink(vtkm::Id numberOfValues) {
void Shrink(vtkm::Id numberOfValues)
{
VTKM_ASSERT_CONT(numberOfValues < this->GetNumberOfValues());
this->NumberOfValues = numberOfValues;
}

@ -152,7 +152,7 @@ struct DeviceAdapterAlgorithm
///
template<class Functor>
VTKM_CONT_EXPORT static void Schedule(Functor functor,
vtkm::Id numInstances);
vtkm::Id numInstances);
/// \brief Schedule many instances of a function to run on concurrent threads.
///
@ -178,7 +178,7 @@ struct DeviceAdapterAlgorithm
///
template<class Functor, class IndiceType>
VTKM_CONT_EXPORT static void Schedule(Functor functor,
vtkm::Id3 rangeMax);
vtkm::Id3 rangeMax);
/// \brief Unstable ascending sort of input array.
///
@ -355,7 +355,8 @@ public:
return elapsedTime;
}
struct TimeStamp {
struct TimeStamp
{
vtkm::internal::Int64Type Seconds;
vtkm::internal::Int64Type Microseconds;
};

@ -29,8 +29,7 @@
#include <algorithm>
namespace
{
namespace {
/// Predicate that takes a single argument \c x, and returns
/// True if it isn't the identity of the Type \p T.
template<typename T>
@ -132,7 +131,8 @@ private:
// Copy
private:
template<class InputPortalType, class OutputPortalType>
struct CopyKernel {
struct CopyKernel
{
InputPortalType InputPortal;
OutputPortalType OutputPortal;
vtkm::Id InputOffset;
@ -150,10 +150,11 @@ private:
{ }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
this->OutputPortal.Set(
index + this->OutputOffset,
this->InputPortal.Get(index + this->InputOffset));
index + this->OutputOffset,
this->InputPortal.Get(index + this->InputOffset));
}
VTKM_CONT_EXPORT
@ -164,7 +165,7 @@ private:
public:
template<typename T, class CIn, class COut>
VTKM_CONT_EXPORT static void Copy(const vtkm::cont::ArrayHandle<T, CIn> &input,
vtkm::cont::ArrayHandle<T, COut> &output)
vtkm::cont::ArrayHandle<T, COut> &output)
{
vtkm::Id arraySize = input.GetNumberOfValues();
@ -181,7 +182,8 @@ public:
// Lower Bounds
private:
template<class InputPortalType,class ValuesPortalType,class OutputPortalType>
struct LowerBoundsKernel {
struct LowerBoundsKernel
{
InputPortalType InputPortal;
ValuesPortalType ValuesPortal;
OutputPortalType OutputPortal;
@ -195,7 +197,8 @@ private:
OutputPortal(outputPortal) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
// This method assumes that (1) InputPortalType can return working
// iterators in the execution environment and that (2) methods not
// specified with VTKM_EXEC_EXPORT (such as the STL algorithms) can be
@ -220,7 +223,8 @@ private:
};
template<class InputPortalType,class ValuesPortalType,class OutputPortalType,class Compare>
struct LowerBoundsComparisonKernel {
struct LowerBoundsComparisonKernel
{
InputPortalType InputPortal;
ValuesPortalType ValuesPortal;
OutputPortalType OutputPortal;
@ -228,16 +232,17 @@ private:
VTKM_CONT_EXPORT
LowerBoundsComparisonKernel(InputPortalType inputPortal,
ValuesPortalType valuesPortal,
OutputPortalType outputPortal,
Compare comp)
ValuesPortalType valuesPortal,
OutputPortalType outputPortal,
Compare comp)
: InputPortal(inputPortal),
ValuesPortal(valuesPortal),
OutputPortal(outputPortal),
CompareFunctor(comp) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
// This method assumes that (1) InputPortalType can return working
// iterators in the execution environment and that (2) methods not
// specified with VTKM_EXEC_EXPORT (such as the STL algorithms) can be
@ -356,9 +361,9 @@ public:
vtkm::Id numValues = inclusiveScan.GetNumberOfValues();
if (numValues < 1)
{
{
return result;
}
}
typedef typename TempArrayType::template ExecutionTypes<DeviceAdapterTag>
::PortalConst SrcPortalType;
@ -411,11 +416,11 @@ private:
vtkm::Id rightIndex = leftIndex + this->Distance;
if (rightIndex < this->Portal.GetNumberOfValues())
{
{
ValueType leftValue = this->Portal.Get(leftIndex);
ValueType rightValue = this->Portal.Get(rightIndex);
this->Portal.Set(rightIndex, leftValue+rightValue);
}
}
}
};
@ -433,25 +438,25 @@ public:
vtkm::Id numValues = output.GetNumberOfValues();
if (numValues < 1)
{
{
return 0;
}
}
PortalType portal = output.PrepareForInPlace(DeviceAdapterTag());
vtkm::Id stride;
for (stride = 2; stride-1 < numValues; stride *= 2)
{
{
ScanKernel<PortalType> kernel(portal, stride, stride/2 - 1);
DerivedAlgorithm::Schedule(kernel, numValues/stride);
}
}
// Do reverse operation on odd indices. Start at stride we were just at.
for (stride /= 2; stride > 1; stride /= 2)
{
{
ScanKernel<PortalType> kernel(portal, stride, stride - 1);
DerivedAlgorithm::Schedule(kernel, numValues/stride);
}
}
return GetExecutionValue(output, numValues-1);
}
@ -473,7 +478,8 @@ private:
: Portal(portal), Compare(compare), GroupSize(groupSize) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
typedef typename PortalType::ValueType ValueType;
vtkm::Id groupIndex = index%this->GroupSize;
@ -484,15 +490,15 @@ private:
vtkm::Id highIndex = lowIndex + this->GroupSize;
if (highIndex < this->Portal.GetNumberOfValues())
{
{
ValueType lowValue = this->Portal.Get(lowIndex);
ValueType highValue = this->Portal.Get(highIndex);
if (this->Compare(highValue, lowValue))
{
{
this->Portal.Set(highIndex, lowValue);
this->Portal.Set(lowIndex, highValue);
}
}
}
}
};
@ -510,7 +516,8 @@ private:
: Portal(portal), Compare(compare), GroupSize(groupSize) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
typedef typename PortalType::ValueType ValueType;
vtkm::Id groupIndex = index%this->GroupSize;
@ -521,15 +528,15 @@ private:
vtkm::Id highIndex = blockIndex*blockSize + (blockSize - groupIndex - 1);
if (highIndex < this->Portal.GetNumberOfValues())
{
{
ValueType lowValue = this->Portal.Get(lowIndex);
ValueType highValue = this->Portal.Get(highIndex);
if (this->Compare(highValue, lowValue))
{
{
this->Portal.Set(highIndex, lowValue);
this->Portal.Set(lowIndex, highValue);
}
}
}
}
};
@ -569,15 +576,15 @@ public:
for (vtkm::Id crossoverSize = 1;
crossoverSize < numValues;
crossoverSize *= 2)
{
{
DerivedAlgorithm::Schedule(CrossoverKernel(portal,compare,crossoverSize),
numThreads);
for (vtkm::Id mergeSize = crossoverSize/2; mergeSize > 0; mergeSize /= 2)
{
{
DerivedAlgorithm::Schedule(MergeKernel(portal,compare,mergeSize),
numThreads);
}
}
}
}
template<typename T, class Container>
@ -642,14 +649,14 @@ private:
typedef typename StencilPortalType::ValueType StencilValueType;
StencilValueType stencilValue = this->StencilPortal.Get(index);
if (not_default_constructor<StencilValueType>()(stencilValue))
{
{
vtkm::Id outputIndex = this->IndexPortal.Get(index);
typedef typename OutputPortalType::ValueType OutputValueType;
OutputValueType value = this->InputPortal.Get(index);
this->OutputPortal.Set(outputIndex, value);
}
}
}
VTKM_CONT_EXPORT
@ -729,7 +736,8 @@ public:
// Unique
private:
template<class InputPortalType, class StencilPortalType>
struct ClassifyUniqueKernel {
struct ClassifyUniqueKernel
{
InputPortalType InputPortal;
StencilPortalType StencilPortal;
@ -739,19 +747,20 @@ private:
: InputPortal(inputPortal), StencilPortal(stencilPortal) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
typedef typename StencilPortalType::ValueType ValueType;
if (index == 0)
{
{
// Always copy first value.
this->StencilPortal.Set(index, ValueType(1));
}
}
else
{
{
ValueType flag = ValueType(this->InputPortal.Get(index-1)
!= this->InputPortal.Get(index));
this->StencilPortal.Set(index, flag);
}
}
}
VTKM_CONT_EXPORT
@ -760,35 +769,37 @@ private:
};
template<class InputPortalType, class StencilPortalType, class Compare>
struct ClassifyUniqueComparisonKernel {
struct ClassifyUniqueComparisonKernel
{
InputPortalType InputPortal;
StencilPortalType StencilPortal;
Compare CompareFunctor;
VTKM_CONT_EXPORT
ClassifyUniqueComparisonKernel(InputPortalType inputPortal,
StencilPortalType stencilPortal,
Compare comp):
StencilPortalType stencilPortal,
Compare comp):
InputPortal(inputPortal),
StencilPortal(stencilPortal),
CompareFunctor(comp) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
typedef typename StencilPortalType::ValueType ValueType;
if (index == 0)
{
{
// Always copy first value.
this->StencilPortal.Set(index, ValueType(1));
}
}
else
{
{
//comparison predicate returns true when they match
const bool same = !(this->CompareFunctor(this->InputPortal.Get(index-1),
this->InputPortal.Get(index)));
ValueType flag = ValueType(same);
this->StencilPortal.Set(index, flag);
}
}
}
VTKM_CONT_EXPORT
@ -850,7 +861,8 @@ public:
// Upper bounds
private:
template<class InputPortalType,class ValuesPortalType,class OutputPortalType>
struct UpperBoundsKernel {
struct UpperBoundsKernel
{
InputPortalType InputPortal;
ValuesPortalType ValuesPortal;
OutputPortalType OutputPortal;
@ -864,7 +876,8 @@ private:
OutputPortal(outputPortal) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
// This method assumes that (1) InputPortalType can return working
// iterators in the execution environment and that (2) methods not
// specified with VTKM_EXEC_EXPORT (such as the STL algorithms) can be
@ -890,7 +903,8 @@ private:
template<class InputPortalType,class ValuesPortalType,class OutputPortalType,class Compare>
struct UpperBoundsKernelComparisonKernel {
struct UpperBoundsKernelComparisonKernel
{
InputPortalType InputPortal;
ValuesPortalType ValuesPortal;
OutputPortalType OutputPortal;
@ -898,16 +912,17 @@ private:
VTKM_CONT_EXPORT
UpperBoundsKernelComparisonKernel(InputPortalType inputPortal,
ValuesPortalType valuesPortal,
OutputPortalType outputPortal,
Compare comp)
ValuesPortalType valuesPortal,
OutputPortalType outputPortal,
Compare comp)
: InputPortal(inputPortal),
ValuesPortal(valuesPortal),
OutputPortal(outputPortal),
CompareFunctor(comp) { }
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const {
void operator()(vtkm::Id index) const
{
// This method assumes that (1) InputPortalType can return working
// iterators in the execution environment and that (2) methods not
// specified with VTKM_EXEC_EXPORT (such as the STL algorithms) can be

@ -125,7 +125,7 @@ private:
public:
template<class Functor>
VTKM_CONT_EXPORT static void Schedule(Functor functor,
vtkm::Id numInstances)
vtkm::Id numInstances)
{
const vtkm::Id MESSAGE_SIZE = 1024;
char errorString[MESSAGE_SIZE];
@ -143,9 +143,9 @@ public:
kernel);
if (errorMessage.IsErrorRaised())
{
{
throw vtkm::cont::ErrorExecution(errorString);
}
}
}
template<class FunctorType>
@ -168,7 +168,7 @@ public:
template<typename T, class Container, class Compare>
VTKM_CONT_EXPORT static void Sort(vtkm::cont::ArrayHandle<T,Container>& values,
Compare comp)
Compare comp)
{
typedef typename vtkm::cont::ArrayHandle<T,Container>
::template ExecutionTypes<Device>::Portal PortalType;

@ -32,7 +32,8 @@ namespace internal {
namespace detail {
template<class ArrayPortalType>
struct IteratorFromArrayPortalValue {
struct IteratorFromArrayPortalValue
{
typedef typename ArrayPortalType::ValueType ValueType;
VTKM_CONT_EXPORT
@ -52,20 +53,22 @@ struct IteratorFromArrayPortalValue {
VTKM_CONT_EXPORT
IteratorFromArrayPortalValue<ArrayPortalType> &operator=(
const IteratorFromArrayPortalValue<ArrayPortalType> &rhs)
const IteratorFromArrayPortalValue<ArrayPortalType> &rhs)
{
this->Portal.Set(this->Index, rhs.Portal.Get(rhs.Index));
return *this;
}
VTKM_CONT_EXPORT
ValueType operator=(ValueType value) {
ValueType operator=(ValueType value)
{
this->Portal.Set(this->Index, value);
return value;
}
VTKM_CONT_EXPORT
operator ValueType(void) const {
operator ValueType(void) const
{
return this->Portal.Get(this->Index);
}
@ -96,8 +99,8 @@ public:
detail::IteratorFromArrayPortalValue<ArrayPortalType>
operator[](int idx) const
{
return detail::IteratorFromArrayPortalValue<ArrayPortalType>(this->Portal,
idx);
return detail::IteratorFromArrayPortalValue<ArrayPortalType>(this->Portal,
idx);
}
private:
@ -108,13 +111,15 @@ private:
friend class boost::iterator_core_access;
VTKM_CONT_EXPORT
detail::IteratorFromArrayPortalValue<ArrayPortalType> dereference() const {
detail::IteratorFromArrayPortalValue<ArrayPortalType> dereference() const
{
return detail::IteratorFromArrayPortalValue<ArrayPortalType>(this->Portal,
this->Index);
this->Index);
}
VTKM_CONT_EXPORT
bool equal(const IteratorFromArrayPortal<ArrayPortalType> &other) const {
bool equal(const IteratorFromArrayPortal<ArrayPortalType> &other) const
{
// Technically, we should probably check that the portals are the same,
// but the portal interface does not specify an equal operator. It is
// by its nature undefined what happens when comparing iterators from
@ -123,21 +128,24 @@ private:
}
VTKM_CONT_EXPORT
void increment() {
void increment()
{
this->Index++;
VTKM_ASSERT_CONT(this->Index >= 0);
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
}
VTKM_CONT_EXPORT
void decrement() {
void decrement()
{
this->Index--;
VTKM_ASSERT_CONT(this->Index >= 0);
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
}
VTKM_CONT_EXPORT
void advance(vtkm::Id delta) {
void advance(vtkm::Id delta)
{
this->Index += delta;
VTKM_ASSERT_CONT(this->Index >= 0);
VTKM_ASSERT_CONT(this->Index <= this->Portal.GetNumberOfValues());
@ -145,7 +153,8 @@ private:
VTKM_CONT_EXPORT
vtkm::Id
distance_to(const IteratorFromArrayPortal<ArrayPortalType> &other) const {
distance_to(const IteratorFromArrayPortal<ArrayPortalType> &other) const
{
// Technically, we should probably check that the portals are the same,
// but the portal interface does not specify an equal operator. It is
// by its nature undefined what happens when comparing iterators from
@ -156,28 +165,28 @@ private:
template<class ArrayPortalType>
IteratorFromArrayPortal<ArrayPortalType> make_IteratorBegin(
const ArrayPortalType &portal)
const ArrayPortalType &portal)
{
return IteratorFromArrayPortal<ArrayPortalType>(portal, 0);
}
template<class ArrayPortalType>
IteratorFromArrayPortal<ArrayPortalType> make_IteratorEnd(
const ArrayPortalType &portal)
const ArrayPortalType &portal)
{
return IteratorFromArrayPortal<ArrayPortalType>(portal,
portal.GetNumberOfValues());
portal.GetNumberOfValues());
}
//implementat a custom swap function, since the std::swap won't work
//since we return RValues instead of Lvalues
template<typename T>
void swap( vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> a,
vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> b)
{
a.Swap(b);
}
void swap( vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> a,
vtkm::cont::internal::detail::IteratorFromArrayPortalValue<T> b)
{
a.Swap(b);
}
}

@ -51,9 +51,9 @@ struct TemplatedTests
bool CheckArray(IteratorType begin, IteratorType end, ValueType value)
{
for (IteratorType iter = begin; iter != end; iter++)
{
if (!test_equal(*iter, value)) return false;
}
{
if (!test_equal(*iter, value)) { return false; }
}
return true;
}
@ -87,7 +87,7 @@ struct TemplatedTests
executionArray.CopyInto(copyBack.begin());
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), INPUT_VALUE),
"Did not get correct array back.");
"Did not get correct array back.");
}
void InPlaceData()
@ -117,7 +117,7 @@ struct TemplatedTests
executionArray.CopyInto(copyBack.begin());
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), INPUT_VALUE),
"Did not get correct array back.");
"Did not get correct array back.");
}
void OutputData()
@ -137,15 +137,16 @@ struct TemplatedTests
executionArray.CopyInto(copyBack.begin());
VTKM_TEST_ASSERT(CheckArray(copyBack.begin(), copyBack.end(), OUTPUT_VALUE),
"Did not get correct array back.");
"Did not get correct array back.");
executionArray.RetrieveOutputData(controlArray);
VTKM_TEST_ASSERT(CheckContainer(controlArray, OUTPUT_VALUE),
"Did not get the right value in the control container.");
"Did not get the right value in the control container.");
}
void operator()() {
void operator()()
{
InputData();
InPlaceData();

@ -33,30 +33,33 @@ struct TemplatedTests
typedef T ValueType;
typedef typename vtkm::VectorTraits<ValueType>::ComponentType ComponentType;
ValueType ExpectedValue(vtkm::Id index, ComponentType value) {
ValueType ExpectedValue(vtkm::Id index, ComponentType value)
{
return ValueType(index + value);
}
template<class IteratorType>
void FillIterator(IteratorType begin, IteratorType end, ComponentType value) {
void FillIterator(IteratorType begin, IteratorType end, ComponentType value)
{
vtkm::Id index = 0;
for (IteratorType iter = begin; iter != end; iter++)
{
{
*iter = ExpectedValue(index, value);
index++;
}
}
}
template<class IteratorType>
bool CheckIterator(IteratorType begin,
IteratorType end,
ComponentType value) {
ComponentType value)
{
vtkm::Id index = 0;
for (IteratorType iter = begin; iter != end; iter++)
{
if (*iter != ExpectedValue(index, value)) return false;
{
if (*iter != ExpectedValue(index, value)) { return false; }
index++;
}
}
return true;
}
@ -68,47 +71,47 @@ struct TemplatedTests
FillIterator(array, array+ARRAY_SIZE, ORIGINAL_VALUE);
::vtkm::cont::internal::ArrayPortalFromIterators<ValueType *>
portal(array, array+ARRAY_SIZE);
portal(array, array+ARRAY_SIZE);
::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType *>
const_portal(array, array+ARRAY_SIZE);
const_portal(array, array+ARRAY_SIZE);
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE,
"Portal array size wrong.");
"Portal array size wrong.");
VTKM_TEST_ASSERT(const_portal.GetNumberOfValues() == ARRAY_SIZE,
"Const portal array size wrong.");
"Const portal array size wrong.");
std::cout << " Check inital value." << std::endl;
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
portal.GetIteratorEnd(),
ORIGINAL_VALUE),
"Portal iterator has bad value.");
portal.GetIteratorEnd(),
ORIGINAL_VALUE),
"Portal iterator has bad value.");
VTKM_TEST_ASSERT(CheckIterator(const_portal.GetIteratorBegin(),
const_portal.GetIteratorEnd(),
ORIGINAL_VALUE),
"Const portal iterator has bad value.");
const_portal.GetIteratorEnd(),
ORIGINAL_VALUE),
"Const portal iterator has bad value.");
static const ComponentType SET_VALUE = 562;
std::cout << " Check get/set methods." << std::endl;
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
{
VTKM_TEST_ASSERT(portal.Get(index)
== ExpectedValue(index, ORIGINAL_VALUE),
"Bad portal value.");
== ExpectedValue(index, ORIGINAL_VALUE),
"Bad portal value.");
VTKM_TEST_ASSERT(const_portal.Get(index)
== ExpectedValue(index, ORIGINAL_VALUE),
"Bad const portal value.");
== ExpectedValue(index, ORIGINAL_VALUE),
"Bad const portal value.");
portal.Set(index, ExpectedValue(index, SET_VALUE));
}
}
std::cout << " Make sure set has correct value." << std::endl;
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
portal.GetIteratorEnd(),
SET_VALUE),
"Portal iterator has bad value.");
portal.GetIteratorEnd(),
SET_VALUE),
"Portal iterator has bad value.");
VTKM_TEST_ASSERT(CheckIterator(array, array+ARRAY_SIZE, SET_VALUE),
"Array has bad value.");
"Array has bad value.");
}
};

@ -35,30 +35,33 @@ struct TemplatedTests
typedef T ValueType;
typedef typename vtkm::VectorTraits<ValueType>::ComponentType ComponentType;
ValueType ExpectedValue(vtkm::Id index, ComponentType value) {
ValueType ExpectedValue(vtkm::Id index, ComponentType value)
{
return ValueType(index + value);
}
template<class IteratorType>
void FillIterator(IteratorType begin, IteratorType end, ComponentType value) {
void FillIterator(IteratorType begin, IteratorType end, ComponentType value)
{
vtkm::Id index = 0;
for (IteratorType iter = begin; iter != end; iter++)
{
{
*iter = ExpectedValue(index, value);
index++;
}
}
}
template<class IteratorType>
bool CheckIterator(IteratorType begin,
IteratorType end,
ComponentType value) {
ComponentType value)
{
vtkm::Id index = 0;
for (IteratorType iter = begin; iter != end; iter++)
{
if (ValueType(*iter) != ExpectedValue(index, value)) return false;
{
if (ValueType(*iter) != ExpectedValue(index, value)) { return false; }
index++;
}
}
return true;
}
@ -72,29 +75,29 @@ struct TemplatedTests
IteratorType begin = vtkm::cont::internal::make_IteratorBegin(portal);
IteratorType end = vtkm::cont::internal::make_IteratorEnd(portal);
VTKM_TEST_ASSERT(std::distance(begin, end) == ARRAY_SIZE,
"Distance between begin and end incorrect.");
"Distance between begin and end incorrect.");
std::cout << " Check forward iteration." << std::endl;
VTKM_TEST_ASSERT(CheckIterator(begin, end, ORIGINAL_VALUE()),
"Forward iteration wrong");
"Forward iteration wrong");
std::cout << " Check backward iteration." << std::endl;
IteratorType middle = end;
for (vtkm::Id index = portal.GetNumberOfValues()-1; index >= 0; index--)
{
{
middle--;
ValueType value = *middle;
VTKM_TEST_ASSERT(value == ExpectedValue(index, ORIGINAL_VALUE()),
"Backward iteration wrong");
}
"Backward iteration wrong");
}
std::cout << " Check advance" << std::endl;
middle = begin + ARRAY_SIZE/2;
VTKM_TEST_ASSERT(std::distance(begin, middle) == ARRAY_SIZE/2,
"Bad distance to middle.");
"Bad distance to middle.");
VTKM_TEST_ASSERT(
ValueType(*middle) == ExpectedValue(ARRAY_SIZE/2, ORIGINAL_VALUE()),
"Bad value at middle.");
ValueType(*middle) == ExpectedValue(ARRAY_SIZE/2, ORIGINAL_VALUE()),
"Bad value at middle.");
}
template<class ArrayPortalType>
@ -112,9 +115,9 @@ struct TemplatedTests
std::cout << " Check values in portal." << std::endl;
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
portal.GetIteratorEnd(),
WRITE_VALUE),
"Did not get correct values when writing to iterator.");
portal.GetIteratorEnd(),
WRITE_VALUE),
"Did not get correct values when writing to iterator.");
}
void operator()()

@ -35,27 +35,27 @@ public:
static VTKM_CONT_EXPORT int Run(Func function)
{
try
{
{
function();
}
}
catch (vtkm::testing::Testing::TestFailure error)
{
{
std::cout << "***** Test failed @ "
<< error.GetFile() << ":" << error.GetLine() << std::endl
<< error.GetMessage() << std::endl;
return 1;
}
}
catch (vtkm::cont::Error error)
{
{
std::cout << "***** Uncaught VTKm exception thrown." << std::endl
<< error.GetMessage() << std::endl;
return 1;
}
}
catch (...)
{
{
std::cout << "***** Unidentified exception thrown." << std::endl;
return 1;
}
}
return 0;
}
};

@ -42,63 +42,62 @@ namespace vtkm {
namespace cont {
namespace testing {
namespace
namespace {
struct SortLess
{
struct SortLess
template<typename T>
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a,const T& b) const
{
template<typename T>
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a,const T& b) const
typedef typename vtkm::TypeTraits<T>::DimensionalityTag Dimensionality;
return this->compare(a,b,Dimensionality());
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsScalarTag) const
{
return a < b;
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsVectorTag) const
{
enum {SIZE = vtkm::VectorTraits<T>::NUM_COMPONENTS};
bool valid = true;
for(unsigned int i=0; i < SIZE && valid; ++i)
{
typedef typename vtkm::TypeTraits<T>::DimensionalityTag Dimensionality;
return this->compare(a,b,Dimensionality());
valid = a[i] < b[i];
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsScalarTag) const
{
return a < b;
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsVectorTag) const
{
enum{SIZE = vtkm::VectorTraits<T>::NUM_COMPONENTS};
bool valid = true;
for(unsigned int i=0; i < SIZE && valid; ++i)
{
valid = a[i] < b[i];
}
return valid;
}
};
return valid;
}
};
struct SortGreater
struct SortGreater
{
template<typename T>
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a,const T& b) const
{
template<typename T>
VTKM_EXEC_CONT_EXPORT bool operator()(const T& a,const T& b) const
typedef typename vtkm::TypeTraits<T>::DimensionalityTag Dimensionality;
return this->compare(a,b,Dimensionality());
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsScalarTag) const
{
return a > b;
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsVectorTag) const
{
enum {SIZE = vtkm::VectorTraits<T>::NUM_COMPONENTS};
bool valid = true;
for(unsigned int i=0; i < SIZE && valid; ++i)
{
typedef typename vtkm::TypeTraits<T>::DimensionalityTag Dimensionality;
return this->compare(a,b,Dimensionality());
valid = a[i] > b[i];
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsScalarTag) const
{
return a > b;
}
template<typename T>
VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b,
vtkm::TypeTraitsVectorTag) const
{
enum{SIZE = vtkm::VectorTraits<T>::NUM_COMPONENTS};
bool valid = true;
for(unsigned int i=0; i < SIZE && valid; ++i)
{
valid = a[i] > b[i];
}
return valid;
}
};
return valid;
}
};
}
#define ERROR_MESSAGE "Got an error."
@ -213,9 +212,9 @@ public:
VTKM_EXEC_EXPORT void operator()(vtkm::Id index) const
{
if (index == ARRAY_SIZE/2)
{
{
this->ErrorMessage.RaiseError(ERROR_MESSAGE);
}
}
}
VTKM_CONT_EXPORT void SetErrorMessageBuffer(
@ -282,21 +281,21 @@ public:
template<typename T>
VTKM_EXEC_EXPORT T operator()(T a, T b) const
{
{
return a * b;
}
}
};
struct NGNoOp //: public vtkm::exec::WorkletMapField
struct NGNoOp //: public vtkm::exec::WorkletMapField
{
// typedef void ControlSignature(Field(In), Field(Out));
// typedef _2 ExecutionSignature(_1);
template<typename T>
VTKM_EXEC_EXPORT T operator()(T a) const
{
{
return a;
}
}
};
struct FuseAll
@ -318,8 +317,8 @@ private:
MakeArrayHandle(const T *array, vtkm::Id length)
{
return vtkm::cont::make_ArrayHandle(array,
length,
ArrayContainerControlTagBasic());
length,
ArrayContainerControlTagBasic());
}
template<typename T>
@ -328,7 +327,7 @@ private:
MakeArrayHandle(const std::vector<T>& array)
{
return vtkm::cont::make_ArrayHandle(array,
ArrayContainerControlTagBasic());
ArrayContainerControlTagBasic());
}
static VTKM_CONT_EXPORT void TestDeviceAdapterTag()
@ -341,9 +340,9 @@ private:
vtkm::cont::DeviceAdapterTagError> ErrorTraits;
VTKM_TEST_ASSERT(Traits::GetId() == Traits::GetId(),
"Device adapter Id does not equal itself.");
"Device adapter Id does not equal itself.");
VTKM_TEST_ASSERT(Traits::GetId() != ErrorTraits::GetId(),
"Device adapter Id not distinguishable from others.");
"Device adapter Id not distinguishable from others.");
}
// Note: this test does not actually test to make sure the data is available
@ -362,9 +361,9 @@ private:
// Create original input array.
vtkm::Scalar inputArray[ARRAY_SIZE*2];
for (vtkm::Id index = 0; index < ARRAY_SIZE*2; index++)
{
{
inputArray[index] = index;
}
}
::vtkm::cont::internal::ArrayPortalFromIterators<vtkm::Scalar *>
inputPortal(inputArray, inputArray+ARRAY_SIZE*2);
ArrayManagerExecution inputManager;
@ -380,10 +379,10 @@ private:
// Check array.
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
{
VTKM_TEST_ASSERT(outputArray[index] == index,
"Did not get correct values from array.");
}
"Did not get correct values from array.");
}
}
static VTKM_CONT_EXPORT void TestOutOfMemory()
@ -395,7 +394,7 @@ private:
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Out of Memory" << std::endl;
try
{
{
std::cout << "Do array allocation that should fail." << std::endl;
vtkm::cont::internal::ArrayManagerExecution<
vtkm::Vector4,ArrayContainerControlTagBasic,DeviceAdapterTag>
@ -406,41 +405,41 @@ private:
bigManager.AllocateArrayForOutput(supportArray, bigSize);
// It does not seem reasonable to get here. The previous call should fail.
VTKM_TEST_FAIL("A ridiculously sized allocation succeeded. Either there "
"was a failure that was not reported but should have been "
"or the width of vtkm::Id is not large enough to express all "
"array sizes.");
}
"was a failure that was not reported but should have been "
"or the width of vtkm::Id is not large enough to express all "
"array sizes.");
}
catch (vtkm::cont::ErrorControlOutOfMemory error)
{
{
std::cout << "Got the expected error: " << error.GetMessage() << std::endl;
}
}
#else
std::cout << "--------- Skiping out of memory test" << std::endl;
#endif
}
// VTKM_CONT_EXPORT static void TestTimer()
// {
// std::cout << "-------------------------------------------" << std::endl;
// std::cout << "Testing Timer" << std::endl;
// VTKM_CONT_EXPORT static void TestTimer()
// {
// std::cout << "-------------------------------------------" << std::endl;
// std::cout << "Testing Timer" << std::endl;
// vtkm::cont::Timer<DeviceAdapterTag> timer;
// vtkm::cont::Timer<DeviceAdapterTag> timer;
// #ifndef _WIN32
// sleep(1);
// #else
// Sleep(1000);
// #endif
// #ifndef _WIN32
// sleep(1);
// #else
// Sleep(1000);
// #endif
// vtkm::Scalar elapsedTime = timer.GetElapsedTime();
// vtkm::Scalar elapsedTime = timer.GetElapsedTime();
// std::cout << "Elapsed time: " << elapsedTime << std::endl;
// std::cout << "Elapsed time: " << elapsedTime << std::endl;
// VTKM_TEST_ASSERT(elapsedTime > 0.999,
// "Timer did not capture full second wait.");
// VTKM_TEST_ASSERT(elapsedTime < 2.0,
// "Timer counted too far or system really busy.");
// }
// VTKM_TEST_ASSERT(elapsedTime > 0.999,
// "Timer did not capture full second wait.");
// VTKM_TEST_ASSERT(elapsedTime < 2.0,
// "Timer counted too far or system really busy.");
// }
static VTKM_CONT_EXPORT void TestAlgorithmSchedule()
{
@ -448,25 +447,25 @@ private:
std::cout << "Testing single value Scheduling with vtkm::Id" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
manager.AllocateArrayForOutput(container, 1);
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
manager.AllocateArrayForOutput(container, 1);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), 1);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), 1);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), 1);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), 1);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
for (vtkm::Id index = 0; index < 1; index++)
for (vtkm::Id index = 0; index < 1; index++)
{
vtkm::Scalar value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for single value scheduled kernel.");
vtkm::Scalar value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for single value scheduled kernel.");
}
} //release memory
@ -474,25 +473,25 @@ private:
std::cout << "Testing Schedule with vtkm::Id" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
manager.AllocateArrayForOutput(container, ARRAY_SIZE);
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
manager.AllocateArrayForOutput(container, ARRAY_SIZE);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), ARRAY_SIZE);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), ARRAY_SIZE);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), ARRAY_SIZE);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), ARRAY_SIZE);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
vtkm::Id value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for scheduled kernels.");
vtkm::Id value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for scheduled kernels.");
}
} //release memory
@ -501,29 +500,29 @@ private:
std::cout << "Testing Schedule with vtkm::Id3" << std::endl;
{
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
vtkm::Id DIM_SIZE = std::pow(ARRAY_SIZE, 1/3.0f);
manager.AllocateArrayForOutput(container,
DIM_SIZE * DIM_SIZE * DIM_SIZE);
vtkm::Id3 maxRange(DIM_SIZE);
std::cout << "Allocating execution array" << std::endl;
IdContainer container;
IdArrayManagerExecution manager;
vtkm::Id DIM_SIZE = std::pow(ARRAY_SIZE, 1/3.0f);
manager.AllocateArrayForOutput(container,
DIM_SIZE * DIM_SIZE * DIM_SIZE);
vtkm::Id3 maxRange(DIM_SIZE);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), maxRange);
std::cout << "Running clear." << std::endl;
Algorithm::Schedule(ClearArrayKernel(manager.GetPortal()), maxRange);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), maxRange);
std::cout << "Running add." << std::endl;
Algorithm::Schedule(AddArrayKernel(manager.GetPortal()), maxRange);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
std::cout << "Checking results." << std::endl;
manager.RetrieveOutputData(container);
const vtkm::Id maxId = DIM_SIZE * DIM_SIZE * DIM_SIZE;
for (vtkm::Id index = 0; index < maxId; index++)
const vtkm::Id maxId = DIM_SIZE * DIM_SIZE * DIM_SIZE;
for (vtkm::Id index = 0; index < maxId; index++)
{
vtkm::Id value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for scheduled vtkm::Id3 kernels.");
vtkm::Id value = container.GetPortalConst().Get(index);
VTKM_TEST_ASSERT(value == index + OFFSET,
"Got bad value for scheduled vtkm::Id3 kernels.");
}
} //release memory
}
@ -642,14 +641,14 @@ private:
Algorithm::StreamCompact(array, result);
VTKM_TEST_ASSERT(result.GetNumberOfValues() == array.GetNumberOfValues()/2,
"result of compacation has an incorrect size");
"result of compacation has an incorrect size");
for (vtkm::Id index = 0; index < result.GetNumberOfValues(); index++)
{
{
const vtkm::Id value = result.GetPortalConstControl().Get(index);
VTKM_TEST_ASSERT(value == (index*2)+1,
"Incorrect value in compaction results.");
}
"Incorrect value in compaction results.");
}
}
static VTKM_CONT_EXPORT void TestStreamCompactWithStencil()
@ -673,14 +672,14 @@ private:
Algorithm::StreamCompact(array,stencil,result);
VTKM_TEST_ASSERT(result.GetNumberOfValues() == array.GetNumberOfValues()/2,
"result of compacation has an incorrect size");
"result of compacation has an incorrect size");
for (vtkm::Id index = 0; index < result.GetNumberOfValues(); index++)
{
{
const vtkm::Id value = result.GetPortalConstControl().Get(index);
VTKM_TEST_ASSERT(value == (OFFSET + (index*2)+1),
"Incorrect value in compaction result.");
}
"Incorrect value in compaction result.");
}
}
static VTKM_CONT_EXPORT void TestOrderedUniqueValues()
@ -689,9 +688,9 @@ private:
std::cout << "Testing Sort, Unique, LowerBounds and UpperBounds" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
testData[i]= OFFSET+(i % 50);
}
}
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle handle;
@ -714,12 +713,12 @@ private:
"Unique did not resize array (or size did not copy to control).");
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
vtkm::Id value = handle.GetPortalConstControl().Get(i);
vtkm::Id value1 = handle1.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(value == i % 50, "Got bad value (LowerBounds)");
VTKM_TEST_ASSERT(value1 >= i % 50, "Got bad value (UpperBounds)");
}
}
std::cout << "Testing Sort, Unique, LowerBounds and UpperBounds with random values"
<< std::endl;
@ -737,22 +736,22 @@ private:
input = MakeArrayHandle(randomData, RANDOMDATA_SIZE);
Algorithm::Copy(input,handle);
VTKM_TEST_ASSERT(handle.GetNumberOfValues() == RANDOMDATA_SIZE,
"Handle incorrect size after setting new control data");
"Handle incorrect size after setting new control data");
Algorithm::Copy(input,handle1);
VTKM_TEST_ASSERT(handle.GetNumberOfValues() == RANDOMDATA_SIZE,
"Handle incorrect size after setting new control data");
"Handle incorrect size after setting new control data");
Algorithm::Copy(handle,temp);
VTKM_TEST_ASSERT(temp.GetNumberOfValues() == RANDOMDATA_SIZE,
"Copy failed");
"Copy failed");
Algorithm::Sort(temp);
Algorithm::Unique(temp);
Algorithm::LowerBounds(temp,handle);
Algorithm::UpperBounds(temp,handle1);
VTKM_TEST_ASSERT(handle.GetNumberOfValues() == RANDOMDATA_SIZE,
"LowerBounds returned incorrect size");
"LowerBounds returned incorrect size");
std::copy(handle.GetPortalConstControl().GetIteratorBegin(),
handle.GetPortalConstControl().GetIteratorEnd(),
@ -765,7 +764,7 @@ private:
VTKM_TEST_ASSERT(randomData[5] == 3, "Got bad value - LowerBounds");
VTKM_TEST_ASSERT(handle1.GetNumberOfValues() == RANDOMDATA_SIZE,
"UppererBounds returned incorrect size");
"UppererBounds returned incorrect size");
std::copy(handle1.GetPortalConstControl().GetIteratorBegin(),
handle1.GetPortalConstControl().GetIteratorEnd(),
@ -784,9 +783,9 @@ private:
std::cout << "Sort with comparison object" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
testData[i]= OFFSET+((ARRAY_SIZE-i) % 50);
}
}
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle sorted;
@ -799,34 +798,34 @@ private:
Algorithm::Sort(sorted);
for (vtkm::Id i = 0; i < ARRAY_SIZE-1; ++i)
{
{
vtkm::Id sorted1 = sorted.GetPortalConstControl().Get(i);
vtkm::Id sorted2 = sorted.GetPortalConstControl().Get(i+1);
// std::cout << sorted1 << " <= " << sorted2 << std::endl;
// std::cout << sorted1 << " <= " << sorted2 << std::endl;
VTKM_TEST_ASSERT(sorted1 <= sorted2, "Values not properly sorted.");
}
}
//Validate the sort, and SortGreater are inverse
Algorithm::Sort(comp_sorted,SortGreater());
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
vtkm::Id sorted1 = sorted.GetPortalConstControl().Get(i);
vtkm::Id sorted2 = comp_sorted.GetPortalConstControl().Get(ARRAY_SIZE - (i + 1));
// std::cout << sorted1 << "==" << sorted2 << std::endl;
// std::cout << sorted1 << "==" << sorted2 << std::endl;
VTKM_TEST_ASSERT(sorted1 == sorted2,
"Got bad sort values when using SortGreater");
}
"Got bad sort values when using SortGreater");
}
Algorithm::Sort(comp_sorted,SortLess());
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
vtkm::Id sorted1 = sorted.GetPortalConstControl().Get(i);
vtkm::Id sorted2 = comp_sorted.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(sorted1 == sorted2,
"Got bad sort values when using SortLesser");
}
"Got bad sort values when using SortLesser");
}
}
// static VTKM_CONT_EXPORT void TestSortByKey()
@ -906,9 +905,9 @@ private:
std::cout << "Testing LowerBounds with comparison object" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
testData[i]= OFFSET+(i % 50);
}
}
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle temp;
@ -929,10 +928,10 @@ private:
"Unique did not resize array (or size did not copy to control).");
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
vtkm::Id value = handle.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(value == i % 50, "Got bad LowerBounds value with SortLess");
}
}
}
@ -942,9 +941,9 @@ private:
std::cout << "Testing UpperBounds with comparison object" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
testData[i]= OFFSET+(i % 50);
}
}
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle temp;
@ -965,10 +964,10 @@ private:
"Unique did not resize array (or size did not copy to control).");
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
vtkm::Id value = handle.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(value == (i % 50)+1, "Got bad UpperBounds value with SortLess");
}
}
}
static VTKM_CONT_EXPORT void TestUniqueWithComparisonObject()
@ -977,9 +976,9 @@ private:
std::cout << "Testing Unique with comparison object" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
{
testData[i]= OFFSET+(i % 50);
}
}
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle temp;
@ -1008,28 +1007,28 @@ private:
//construct the index array
IdArrayHandle array;
Algorithm::Schedule(
ClearArrayKernel(array.PrepareForOutput(ARRAY_SIZE,
DeviceAdapterTag())),
ARRAY_SIZE);
ClearArrayKernel(array.PrepareForOutput(ARRAY_SIZE,
DeviceAdapterTag())),
ARRAY_SIZE);
//we know have an array whose sum is equal to OFFSET * ARRAY_SIZE,
//let's validate that
vtkm::Id sum = Algorithm::ScanInclusive(array, array);
VTKM_TEST_ASSERT(sum == OFFSET * ARRAY_SIZE,
"Got bad sum from Inclusive Scan");
"Got bad sum from Inclusive Scan");
//each value should be equal to the Triangle Number of that index
//ie 1, 3, 6, 10, 15, 21 ...
vtkm::Id partialSum = 0;
vtkm::Id triangleNumber = 0;
for(unsigned int i=0, pos=1; i < ARRAY_SIZE; ++i, ++pos)
{
{
const vtkm::Id value = array.GetPortalConstControl().Get(i);
partialSum += value;
triangleNumber = ((pos*(pos+1))/2);
VTKM_TEST_ASSERT(partialSum == triangleNumber * OFFSET,
"Incorrect partial sum");
}
"Incorrect partial sum");
}
}
static VTKM_CONT_EXPORT void TestScanExclusive()
@ -1040,29 +1039,29 @@ private:
//construct the index array
IdArrayHandle array;
Algorithm::Schedule(
ClearArrayKernel(array.PrepareForOutput(ARRAY_SIZE,
DeviceAdapterTag())),
ARRAY_SIZE);
ClearArrayKernel(array.PrepareForOutput(ARRAY_SIZE,
DeviceAdapterTag())),
ARRAY_SIZE);
// we know have an array whose sum = (OFFSET * ARRAY_SIZE),
// let's validate that
vtkm::Id sum = Algorithm::ScanExclusive(array, array);
VTKM_TEST_ASSERT(sum == (OFFSET * ARRAY_SIZE),
"Got bad sum from Exclusive Scan");
"Got bad sum from Exclusive Scan");
//each value should be equal to the Triangle Number of that index
//ie 0, 1, 3, 6, 10, 15, 21 ...
vtkm::Id partialSum = 0;
vtkm::Id triangleNumber = 0;
for(unsigned int i=0, pos=0; i < ARRAY_SIZE; ++i, ++pos)
{
{
const vtkm::Id value = array.GetPortalConstControl().Get(i);
partialSum += value;
triangleNumber = ((pos*(pos+1))/2);
VTKM_TEST_ASSERT(partialSum == triangleNumber * OFFSET,
"Incorrect partial sum");
}
"Incorrect partial sum");
}
}
static VTKM_CONT_EXPORT void TestErrorExecution()
@ -1073,30 +1072,30 @@ private:
std::cout << "Generating one error." << std::endl;
std::string message;
try
{
{
Algorithm::Schedule(OneErrorKernel(), ARRAY_SIZE);
}
}
catch (vtkm::cont::ErrorExecution error)
{
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
message = error.GetMessage();
}
}
VTKM_TEST_ASSERT(message == ERROR_MESSAGE,
"Did not get expected error message.");
"Did not get expected error message.");
std::cout << "Generating lots of errors." << std::endl;
message = "";
try
{
{
Algorithm::Schedule(AllErrorKernel(), ARRAY_SIZE);
}
}
catch (vtkm::cont::ErrorExecution error)
{
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
message = error.GetMessage();
}
}
VTKM_TEST_ASSERT(message == ERROR_MESSAGE,
"Did not get expected error message.");
"Did not get expected error message.");
}
// template<typename GridType>

@ -25,8 +25,7 @@
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/VectorTraits.h>
namespace
{
namespace {
const vtkm::Id ARRAY_SIZE = 10;
@ -44,9 +43,9 @@ struct TemplatedTests
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
iter != array.GetPortal().GetIteratorEnd();
iter ++)
{
{
*iter = value;
}
}
}
bool CheckContainer(ArrayContainerType &array, ValueType value)
@ -54,13 +53,14 @@ struct TemplatedTests
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
iter != array.GetPortal().GetIteratorEnd();
iter ++)
{
if (!test_equal(*iter, value)) return false;
}
{
if (!test_equal(*iter, value)) { return false; }
}
return true;
}
typename vtkm::VectorTraits<ValueType>::ComponentType STOLEN_ARRAY_VALUE() {
typename vtkm::VectorTraits<ValueType>::ComponentType STOLEN_ARRAY_VALUE()
{
return 4529;
}
@ -78,11 +78,11 @@ struct TemplatedTests
SetContainer(stealMyArray, stolenArrayValue);
VTKM_TEST_ASSERT(stealMyArray.GetNumberOfValues() == ARRAY_SIZE,
"Array not properly allocated.");
"Array not properly allocated.");
// This call steals the array and prevents deallocation.
stolenArray = stealMyArray.StealArray();
VTKM_TEST_ASSERT(stealMyArray.GetNumberOfValues() == 0,
"StealArray did not let go of array.");
"StealArray did not let go of array.");
return stolenArray;
}
@ -91,10 +91,10 @@ struct TemplatedTests
ValueType stolenArrayValue = ValueType(STOLEN_ARRAY_VALUE());
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
{
VTKM_TEST_ASSERT(test_equal(stolenArray[index], stolenArrayValue),
"Stolen array did not retain values.");
}
"Stolen array did not retain values.");
}
delete[] stolenArray;
}
@ -102,36 +102,36 @@ struct TemplatedTests
{
ArrayContainerType arrayContainer;
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == 0,
"New array container not zero sized.");
"New array container not zero sized.");
arrayContainer.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE,
"Array not properly allocated.");
"Array not properly allocated.");
const ValueType BASIC_ALLOC_VALUE = ValueType(548);
SetContainer(arrayContainer, BASIC_ALLOC_VALUE);
VTKM_TEST_ASSERT(CheckContainer(arrayContainer, BASIC_ALLOC_VALUE),
"Array not holding value.");
"Array not holding value.");
arrayContainer.Allocate(ARRAY_SIZE * 2);
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE * 2,
"Array not reallocated correctly.");
"Array not reallocated correctly.");
arrayContainer.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == ARRAY_SIZE,
"Array Shrnk failed to resize.");
"Array Shrnk failed to resize.");
arrayContainer.ReleaseResources();
VTKM_TEST_ASSERT(arrayContainer.GetNumberOfValues() == 0,
"Array not released correctly.");
"Array not released correctly.");
try
{
{
arrayContainer.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(true==false,
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch(vtkm::cont::ErrorControlBadValue){}
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch(vtkm::cont::ErrorControlBadValue) {}
}
void operator()()

@ -28,8 +28,7 @@
#include <vtkm/VectorTraits.h>
namespace
{
namespace {
template <typename T>
struct TestImplicitContainer
@ -52,16 +51,18 @@ struct TestImplicitContainer
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id vtkmNotUsed(index)) const
{
return Temp;
return Temp;
}
VTKM_CONT_EXPORT
IteratorType GetIteratorBegin() const {
IteratorType GetIteratorBegin() const
{
return IteratorType(*this);
}
VTKM_CONT_EXPORT
IteratorType GetIteratorEnd() const {
IteratorType GetIteratorEnd() const
{
return IteratorType(*this, this->GetNumberOfValues());
}
@ -86,45 +87,49 @@ struct TemplatedTests
{
ArrayContainerType arrayContainer;
try{ arrayContainer.GetNumberOfValues();
try
{
arrayContainer.GetNumberOfValues();
VTKM_TEST_ASSERT(false == true,
"Implicit Container GetNumberOfValues method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e){}
try{ arrayContainer.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(false == true,
"Implicit Container Allocate method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e){}
"Implicit Container GetNumberOfValues method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e) {}
try
{
{
arrayContainer.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(false == true,
"Implicit Container Allocate method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e) {}
try
{
arrayContainer.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(true==false,
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch(vtkm::cont::ErrorControlBadValue){}
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch(vtkm::cont::ErrorControlBadValue) {}
try
{
{
arrayContainer.ReleaseResources();
VTKM_TEST_ASSERT(true==false,
"Can't Release an implicit array");
}
catch(vtkm::cont::ErrorControlBadValue){}
"Can't Release an implicit array");
}
catch(vtkm::cont::ErrorControlBadValue) {}
}
void BasicAccess()
{
{
TestImplicitContainer<T> portal;
vtkm::cont::ArrayHandle<T,ContainerTagType> implictHandle(portal);
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == 1,
"handle should have size 1");
"handle should have size 1");
VTKM_TEST_ASSERT(implictHandle.GetPortalConstControl().Get(0) == T(1),
"portals first values should be 1");
"portals first values should be 1");
;
}
}
void operator()()
{

@ -29,8 +29,7 @@
#include <algorithm>
namespace
{
namespace {
const vtkm::Id ARRAY_SIZE = 10;
vtkm::Scalar TestValue(vtkm::Id index)
@ -43,10 +42,10 @@ bool CheckValues(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))) { return false; }
index++;
}
}
return true;
}
@ -62,9 +61,9 @@ void TestArrayHandle()
std::cout << "Create array handle." << std::endl;
vtkm::Scalar array[ARRAY_SIZE];
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
{
array[index] = TestValue(index);
}
}
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalControl arrayPortal(
&array[0], &array[ARRAY_SIZE]);
@ -73,11 +72,11 @@ void TestArrayHandle()
arrayHandle(arrayPortal);
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"ArrayHandle has wrong number of entries.");
"ArrayHandle has wrong number of entries.");
std::cout << "Check basic array." << std::endl;
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
"Array values not set correctly.");
"Array values not set correctly.");
std::cout << "Check out execution array behavior." << std::endl;
{
@ -86,73 +85,73 @@ void TestArrayHandle()
executionPortal;
executionPortal =
arrayHandle.PrepareForInput(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
VTKM_TEST_ASSERT(CheckValues(executionPortal.GetIteratorBegin(),
executionPortal.GetIteratorEnd()),
"Array not copied to execution correctly.");
VTKM_TEST_ASSERT(CheckValues(executionPortal.GetIteratorBegin(),
executionPortal.GetIteratorEnd()),
"Array not copied to execution correctly.");
}
{
bool gotException = false;
try
bool gotException = false;
try
{
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
}
catch (vtkm::cont::Error &error)
catch (vtkm::cont::Error &error)
{
std::cout << "Got expected error: " << error.GetMessage() << std::endl;
gotException = true;
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.");
}
{
vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
executionPortal =
vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
executionPortal =
arrayHandle.PrepareForOutput(ARRAY_SIZE*2,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
vtkm::Id index = 0;
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
iter != executionPortal.GetIteratorEnd();
iter++)
vtkm::Id index = 0;
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
iter != executionPortal.GetIteratorEnd();
iter++)
{
*iter = TestValue(index);
index++;
*iter = TestValue(index);
index++;
}
}
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
"Array not allocated correctly.");
"Array not allocated correctly.");
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
"Array values not retrieved from execution.");
"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.");
"Array size did not shrink correctly.");
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
"Array values not retrieved from execution.");
"Array values not retrieved from execution.");
std::cout << "Try in place operation." << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
executionPortal =
vtkm::cont::ArrayHandle<vtkm::Scalar>::
ExecutionTypes<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>::Portal executionPortal;
executionPortal =
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
iter != executionPortal.GetIteratorEnd();
iter++)
for (vtkm::Scalar *iter = executionPortal.GetIteratorBegin();
iter != executionPortal.GetIteratorEnd();
iter++)
{
*iter += 1;
*iter += 1;
}
}
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalConstControl controlPortal =
arrayHandle.GetPortalConstControl();
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
{
VTKM_TEST_ASSERT(test_equal(controlPortal.Get(index), TestValue(index) + 1),
"Did not get result from in place operation.");
}
"Did not get result from in place operation.");
}
}
}

@ -36,19 +36,19 @@ struct CountByTwo
explicit CountByTwo(T t): Value(t) {}
bool operator==(const T& other) const
{ return Value == other; }
{ return Value == other; }
bool operator==(const CountByTwo<T>& other) const
{ return Value == other.Value; }
{ return Value == other.Value; }
CountByTwo<T> operator+(vtkm::Id count) const
{ return CountByTwo<T>(Value+(count*2)); }
CountByTwo<T>& operator++()
{ ++Value; ++Value; return *this; }
{ ++Value; ++Value; return *this; }
friend std::ostream& operator<< (std::ostream& os, const CountByTwo<T>& obj)
{ os << obj.Value; return os; }
{ os << obj.Value; return os; }
T Value;
};
@ -60,40 +60,40 @@ struct TemplatedTests
typedef vtkm::cont::ArrayHandleCounting<ValueType> ArrayHandleType;
typedef vtkm::cont::ArrayHandle<ValueType,
typename vtkm::cont::internal::ArrayHandleCountingTraits<ValueType>::Tag>
ArrayHandleType2;
typename vtkm::cont::internal::ArrayHandleCountingTraits<ValueType>::Tag>
ArrayHandleType2;
typedef typename ArrayHandleType::PortalConstControl PortalType;
void operator()( const ValueType startingValue )
{
ArrayHandleType arrayConst(startingValue, ARRAY_SIZE);
ArrayHandleType arrayConst(startingValue, ARRAY_SIZE);
ArrayHandleType arrayMake = vtkm::cont::make_ArrayHandleCounting(startingValue,ARRAY_SIZE);
ArrayHandleType arrayMake = vtkm::cont::make_ArrayHandleCounting(startingValue,ARRAY_SIZE);
ArrayHandleType2 arrayHandle =
ArrayHandleType2 arrayHandle =
ArrayHandleType2(PortalType(startingValue, ARRAY_SIZE));
VTKM_TEST_ASSERT(arrayConst.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using constructor has wrong size.");
VTKM_TEST_ASSERT(arrayConst.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using constructor has wrong size.");
VTKM_TEST_ASSERT(arrayMake.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using make has wrong size.");
VTKM_TEST_ASSERT(arrayMake.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using make has wrong size.");
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using raw array handle + tag has wrong size.");
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"Counting array using raw array handle + tag has wrong size.");
ValueType properValue = startingValue;
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
ValueType properValue = startingValue;
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
VTKM_TEST_ASSERT(arrayConst.GetPortalConstControl().Get(index) == properValue,
"Counting array using constructor has unexpected value.");
VTKM_TEST_ASSERT(arrayMake.GetPortalConstControl().Get(index) == properValue,
"Counting array using make has unexpected value.");
VTKM_TEST_ASSERT(arrayConst.GetPortalConstControl().Get(index) == properValue,
"Counting array using constructor has unexpected value.");
VTKM_TEST_ASSERT(arrayMake.GetPortalConstControl().Get(index) == properValue,
"Counting array using make has unexpected value.");
VTKM_TEST_ASSERT(arrayHandle.GetPortalConstControl().Get(index) == properValue,
"Counting array using raw array handle + tag has unexpected value.");
++properValue;
VTKM_TEST_ASSERT(arrayHandle.GetPortalConstControl().Get(index) == properValue,
"Counting array using raw array handle + tag has unexpected value.");
++properValue;
}
}
};

@ -54,18 +54,18 @@ int UnitTestContTesting(int, char *[])
{
std::cout << "-------\nThis call should fail." << std::endl;
if (vtkm::cont::testing::Testing::Run(TestFail) == 0)
{
{
std::cout << "Did not get expected fail!" << std::endl;
return 1;
}
}
std::cout << "-------\nThis call should fail." << std::endl;
if (vtkm::cont::testing::Testing::Run(BadTestAssert) == 0)
{
{
std::cout << "Did not get expected fail!" << std::endl;
return 1;
}
}
//VTKM_ASSERT_CONT only is a valid call when you are building with debug
//VTKM_ASSERT_CONT only is a valid call when you are building with debug
#ifndef NDEBUG
int expectedResult=0;
#else
@ -74,10 +74,10 @@ int UnitTestContTesting(int, char *[])
std::cout << "-------\nThis call should fail on debug builds." << std::endl;
if (vtkm::cont::testing::Testing::Run(BadAssert) == expectedResult)
{
{
std::cout << "Did not get expected fail!" << std::endl;
return 1;
}
}
std::cout << "-------\nThis call should pass." << std::endl;
// This is what your main function typically looks like.

@ -57,14 +57,14 @@ public:
template<class Functor>
VTKM_CONT_EXPORT static void Schedule(Functor functor,
vtkm::Id numInstances)
vtkm::Id numInstances)
{
Algorithm::Schedule(functor, numInstances);
}
template<class Functor>
VTKM_CONT_EXPORT static void Schedule(Functor functor,
vtkm::Id3 rangeMax)
vtkm::Id3 rangeMax)
{
Algorithm::Schedule(functor, rangeMax);
}

@ -60,10 +60,10 @@ public:
// Safely copy message into array.
for (vtkm::Id index = 0; index < this->MessageBufferSize; index++)
{
{
this->MessageBuffer[index] = message[index];
if (message[index] == '\0') { break; }
}
}
// Make sure message is null terminated.
this->MessageBuffer[this->MessageBufferSize-1] = '\0';
@ -72,14 +72,14 @@ public:
VTKM_EXEC_CONT_EXPORT bool IsErrorRaised() const
{
if (this->MessageBufferSize > 0)
{
{
return (this->MessageBuffer[0] != '\0');
}
}
else
{
{
// If there is no buffer set, then always report an error.
return true;
}
}
}
private:

@ -40,13 +40,13 @@ namespace {
void TestTypeSizes()
{
VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE,
"VTKM_SIZE_ID an unexpected size.");
"VTKM_SIZE_ID an unexpected size.");
VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE,
"vtkm::Id an unexpected size.");
"vtkm::Id an unexpected size.");
VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE,
"VTKM_SIZE_SCALAR an unexpected size.");
"VTKM_SIZE_SCALAR an unexpected size.");
VTKM_TEST_ASSERT(sizeof(vtkm::Scalar) == EXPECTED_SIZE,
"vtkm::Scalar an unexpected size.");
"vtkm::Scalar an unexpected size.");
}
}

@ -40,13 +40,13 @@ namespace {
void TestTypeSizes()
{
VTKM_TEST_ASSERT(VTKM_SIZE_ID == EXPECTED_SIZE,
"VTKM_SIZE_ID an unexpected size.");
"VTKM_SIZE_ID an unexpected size.");
VTKM_TEST_ASSERT(sizeof(vtkm::Id) == EXPECTED_SIZE,
"vtkm::Id an unexpected size.");
"vtkm::Id an unexpected size.");
VTKM_TEST_ASSERT(VTKM_SIZE_SCALAR == EXPECTED_SIZE,
"VTKM_SIZE_SCALAR an unexpected size.");
"VTKM_SIZE_SCALAR an unexpected size.");
VTKM_TEST_ASSERT(sizeof(vtkm::Scalar) == EXPECTED_SIZE,
"vtkm::Scalar an unexpected size.");
"vtkm::Scalar an unexpected size.");
}
}

@ -214,11 +214,11 @@
#ifndef OPTIONPARSER_H_
#define OPTIONPARSER_H_
namespace vtkm { namespace testing {
namespace vtkm {
namespace testing {
/** @brief The namespace of The Lean Mean C++ Option Parser. */
namespace option
{
namespace option {
#ifdef _MSC_VER
#include <intrin.h>
@ -604,7 +604,7 @@ public:
{
Option* p = this;
while (!p->isFirst())
p = p->prev_;
{ p = p->prev_; }
return p;
}
@ -748,7 +748,7 @@ public:
* @ref desc, @ref name, @ref arg and @ref namelen.
*/
Option() :
desc(0), name(0), arg(0), namelen(0)
desc(0), name(0), arg(0), namelen(0)
{
prev_ = tag(this);
next_ = tag(this);
@ -805,12 +805,12 @@ private:
next_ = tag(this);
namelen = 0;
if (name == 0)
return;
{ return; }
namelen = 1;
if (name[0] != '-')
return;
{ return; }
while (name[namelen] != 0 && name[namelen] != '=')
++namelen;
{ ++namelen; }
}
static Option* tag(Option* ptr)
@ -895,9 +895,9 @@ struct Arg
static ArgStatus Optional(const Option& option, bool)
{
if (option.arg && option.name[option.namelen] != 0)
return ARG_OK;
{ return ARG_OK; }
else
return ARG_IGNORE;
{ return ARG_IGNORE; }
}
};
@ -940,7 +940,7 @@ struct Stats
* @brief Creates a Stats object with counts set to 1 (for the sentinel element).
*/
Stats() :
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
{
}
@ -955,7 +955,7 @@ struct Stats
*/
Stats(bool gnu, const Descriptor usage[], int argc, const char** argv, int min_abbr_len = 0, //
bool single_minus_longopt = false) :
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
{
add(gnu, usage, argc, argv, min_abbr_len, single_minus_longopt);
}
@ -963,7 +963,7 @@ struct Stats
//! @brief Stats(...) with non-const argv.
Stats(bool gnu, const Descriptor usage[], int argc, char** argv, int min_abbr_len = 0, //
bool single_minus_longopt = false) :
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
{
add(gnu, usage, argc, (const char**) argv, min_abbr_len, single_minus_longopt);
}
@ -971,7 +971,7 @@ struct Stats
//! @brief POSIX Stats(...) (gnu==false).
Stats(const Descriptor usage[], int argc, const char** argv, int min_abbr_len = 0, //
bool single_minus_longopt = false) :
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
{
add(false, usage, argc, argv, min_abbr_len, single_minus_longopt);
}
@ -979,7 +979,7 @@ struct Stats
//! @brief POSIX Stats(...) (gnu==false) with non-const argv.
Stats(const Descriptor usage[], int argc, char** argv, int min_abbr_len = 0, //
bool single_minus_longopt = false) :
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
buffer_max(1), options_max(1) // 1 more than necessary as sentinel
{
add(false, usage, argc, (const char**) argv, min_abbr_len, single_minus_longopt);
}
@ -1052,7 +1052,7 @@ public:
* @brief Creates a new Parser.
*/
Parser() :
op_count(0), nonop_count(0), nonop_args(0), err(false)
op_count(0), nonop_count(0), nonop_args(0), err(false)
{
}
@ -1062,7 +1062,7 @@ public:
*/
Parser(bool gnu, const Descriptor usage[], int argc, const char** argv, Option options[], Option buffer[],
int min_abbr_len = 0, bool single_minus_longopt = false, int bufmax = -1) :
op_count(0), nonop_count(0), nonop_args(0), err(false)
op_count(0), nonop_count(0), nonop_args(0), err(false)
{
parse(gnu, usage, argc, argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
}
@ -1070,7 +1070,7 @@ public:
//! @brief Parser(...) with non-const argv.
Parser(bool gnu, const Descriptor usage[], int argc, char** argv, Option options[], Option buffer[],
int min_abbr_len = 0, bool single_minus_longopt = false, int bufmax = -1) :
op_count(0), nonop_count(0), nonop_args(0), err(false)
op_count(0), nonop_count(0), nonop_args(0), err(false)
{
parse(gnu, usage, argc, (const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
}
@ -1078,7 +1078,7 @@ public:
//! @brief POSIX Parser(...) (gnu==false).
Parser(const Descriptor usage[], int argc, const char** argv, Option options[], Option buffer[], int min_abbr_len = 0,
bool single_minus_longopt = false, int bufmax = -1) :
op_count(0), nonop_count(0), nonop_args(0), err(false)
op_count(0), nonop_count(0), nonop_args(0), err(false)
{
parse(false, usage, argc, argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
}
@ -1086,7 +1086,7 @@ public:
//! @brief POSIX Parser(...) (gnu==false) with non-const argv.
Parser(const Descriptor usage[], int argc, char** argv, Option options[], Option buffer[], int min_abbr_len = 0,
bool single_minus_longopt = false, int bufmax = -1) :
op_count(0), nonop_count(0), nonop_args(0), err(false)
op_count(0), nonop_count(0), nonop_args(0), err(false)
{
parse(false, usage, argc, (const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
}
@ -1279,7 +1279,7 @@ private:
{
while (*st1 != 0)
if (*st1++ != *st2++)
return false;
{ return false; }
return (*st2 == 0 || *st2 == '=');
}
@ -1328,7 +1328,7 @@ private:
static bool instr(char ch, const char* st)
{
while (*st != 0 && *st != ch)
++st;
{ ++st; }
return *st == ch;
}
@ -1398,14 +1398,14 @@ public:
* parsed Option.
*/
CountOptionsAction(unsigned* buffer_max_) :
buffer_max(buffer_max_)
buffer_max(buffer_max_)
{
}
bool perform(Option&)
{
if (*buffer_max == 0x7fffffff)
return false; // overflow protection: don't accept number of options that doesn't fit signed int
{ return false; } // overflow protection: don't accept number of options that doesn't fit signed int
++*buffer_max;
return true;
}
@ -1431,12 +1431,12 @@ public:
* @param bufmax_ number of slots in @c buffer_. @c -1 means "large enough".
*/
StoreOptionAction(Parser& parser_, Option options_[], Option buffer_[], int bufmax_) :
parser(parser_), options(options_), buffer(buffer_), bufmax(bufmax_)
parser(parser_), options(options_), buffer(buffer_), bufmax(bufmax_)
{
// find first empty slot in buffer (if any)
int bufidx = 0;
while ((bufmax < 0 || bufidx < bufmax) && buffer[bufidx])
++bufidx;
{ ++bufidx; }
// set parser's optionCount
parser.op_count = bufidx;
@ -1447,14 +1447,14 @@ public:
if (bufmax < 0 || parser.op_count < bufmax)
{
if (parser.op_count == 0x7fffffff)
return false; // overflow protection: don't accept number of options that doesn't fit signed int
{ return false; } // overflow protection: don't accept number of options that doesn't fit signed int
buffer[parser.op_count] = option;
int idx = buffer[parser.op_count].desc->index;
if (options[idx])
options[idx].append(buffer[parser.op_count]);
{ options[idx].append(buffer[parser.op_count]); }
else
options[idx] = buffer[parser.op_count];
{ options[idx] = buffer[parser.op_count]; }
++parser.op_count;
}
return true; // NOTE: an option that is discarded because of a full buffer is not fatal
@ -1490,7 +1490,7 @@ inline void Stats::add(bool gnu, const Descriptor usage[], int argc, const char*
while (usage[i].shortopt != 0)
{
if (usage[i].index + 1 >= options_max)
options_max = (usage[i].index + 1) + 1; // 1 more than necessary as sentinel
{ options_max = (usage[i].index + 1) + 1; } // 1 more than necessary as sentinel
++i;
}
@ -1504,7 +1504,7 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
{
// protect against NULL pointer
if (args == 0)
numargs = 0;
{ numargs = 0; }
int nonops = 0;
@ -1521,11 +1521,11 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
++nonops;
++args;
if (numargs > 0)
--numargs;
{ --numargs; }
continue;
}
else
break;
{ break; }
}
// -- terminates the option list. The -- itself is skipped.
@ -1534,7 +1534,7 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
shift(args, nonops);
++args;
if (numargs > 0)
--numargs;
{ --numargs; }
break;
}
@ -1565,55 +1565,56 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
{
idx = 0;
while (usage[idx].longopt != 0 && !streq(usage[idx].longopt, longopt_name))
++idx;
{ ++idx; }
if (usage[idx].longopt == 0 && min_abbr_len > 0) // if we should try to match abbreviated long options
{
int i1 = 0;
while (usage[i1].longopt != 0 && !streqabbr(usage[i1].longopt, longopt_name, min_abbr_len))
++i1;
{ ++i1; }
if (usage[i1].longopt != 0)
{ // now test if the match is unambiguous by checking for another match
{
// now test if the match is unambiguous by checking for another match
int i2 = i1 + 1;
while (usage[i2].longopt != 0 && !streqabbr(usage[i2].longopt, longopt_name, min_abbr_len))
++i2;
{ ++i2; }
if (usage[i2].longopt == 0) // if there was no second match it's unambiguous, so accept i1 as idx
idx = i1;
{ idx = i1; }
}
}
// if we found something, disable handle_short_options (only relevant if single_minus_longopt)
if (usage[idx].longopt != 0)
handle_short_options = false;
{ handle_short_options = false; }
try_single_minus_longopt = false; // prevent looking for longopt in the middle of shortopt group
optarg = longopt_name;
while (*optarg != 0 && *optarg != '=')
++optarg;
{ ++optarg; }
if (*optarg == '=') // attached argument
++optarg;
{ ++optarg; }
else
// possibly detached argument
optarg = (have_more_args ? args[1] : 0);
{ optarg = (have_more_args ? args[1] : 0); }
}
/************************ short option ***********************************/
if (handle_short_options)
{
if (*++param == 0) // point at the 1st/next option character
break; // end of short option group
{ break; } // end of short option group
idx = 0;
while (usage[idx].shortopt != 0 && !instr(*param, usage[idx].shortopt))
++idx;
{ ++idx; }
if (param[1] == 0) // if the potential argument is separate
optarg = (have_more_args ? args[1] : 0);
{ optarg = (have_more_args ? args[1] : 0); }
else
// if the potential argument is attached
optarg = param + 1;
{ optarg = param + 1; }
}
const Descriptor* descriptor = &usage[idx];
@ -1623,7 +1624,7 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
// look for dummy entry (shortopt == "" and longopt == "") to use as Descriptor for unknown options
idx = 0;
while (usage[idx].shortopt != 0 && (usage[idx].shortopt[0] != 0 || usage[idx].longopt[0] != 0))
++idx;
{ ++idx; }
descriptor = (usage[idx].shortopt == 0 ? 0 : &usage[idx]);
}
@ -1640,7 +1641,7 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
{
shift(args, nonops);
if (numargs > 0)
--numargs;
{ --numargs; }
++args;
}
@ -1655,26 +1656,28 @@ inline bool Parser::workhorse(bool gnu, const Descriptor usage[], int numargs, c
}
if (!action.perform(option))
return false;
{ return false; }
}
} while (handle_short_options);
}
while (handle_short_options);
shift(args, nonops);
++args;
if (numargs > 0)
--numargs;
{ --numargs; }
} // while
if (numargs > 0 && *args == 0) // It's a bug in the caller if numargs is greater than the actual number
numargs = 0; // of arguments, but as a service to the user we fix this if we spot it.
{ numargs = 0; } // of arguments, but as a service to the user we fix this if we spot it.
if (numargs < 0) // if we don't know the number of remaining non-option arguments
{ // we need to count them
{
// we need to count them
numargs = 0;
while (args[numargs] != 0)
++numargs;
{ ++numargs; }
}
return action.finished(numargs + nonops, args - nonops);
@ -1716,7 +1719,7 @@ struct PrintUsageImplementation
}
FunctionWriter(Function* w) :
write(w)
write(w)
{
}
};
@ -1737,7 +1740,7 @@ struct PrintUsageImplementation
}
OStreamWriter(OStream& o) :
ostream(o)
ostream(o)
{
}
};
@ -1758,7 +1761,7 @@ struct PrintUsageImplementation
}
TemporaryWriter(const Temporary& u) :
userstream(u)
userstream(u)
{
}
};
@ -1781,7 +1784,7 @@ struct PrintUsageImplementation
}
SyscallWriter(Syscall* w, int f) :
write(w), fd(f)
write(w), fd(f)
{
}
};
@ -1802,7 +1805,7 @@ struct PrintUsageImplementation
}
StreamWriter(Function* w, Stream* s) :
fwrite(w), stream(s)
fwrite(w), stream(s)
{
}
};
@ -1840,7 +1843,7 @@ struct PrintUsageImplementation
{
char space = ' ';
for (int i = 0; i < indent; ++i)
write(&space, 1);
{ write(&space, 1); }
x = want_x;
}
}
@ -1866,12 +1869,12 @@ struct PrintUsageImplementation
static bool isWideChar(unsigned ch)
{
if (ch == 0x303F)
return false;
{ return false; }
return ((0x1100 <= ch && ch <= 0x115F) || (0x2329 <= ch && ch <= 0x232A) || (0x2E80 <= ch && ch <= 0xA4C6)
|| (0xA960 <= ch && ch <= 0xA97C) || (0xAC00 <= ch && ch <= 0xD7FB) || (0xF900 <= ch && ch <= 0xFAFF)
|| (0xFE10 <= ch && ch <= 0xFE6B) || (0xFF01 <= ch && ch <= 0xFF60) || (0xFFE0 <= ch && ch <= 0xFFE6)
|| (0x1B000 <= ch));
|| (0xA960 <= ch && ch <= 0xA97C) || (0xAC00 <= ch && ch <= 0xD7FB) || (0xF900 <= ch && ch <= 0xFAFF)
|| (0xFE10 <= ch && ch <= 0xFE6B) || (0xFF01 <= ch && ch <= 0xFF60) || (0xFFE0 <= ch && ch <= 0xFFE6)
|| (0x1B000 <= ch));
}
/**
@ -1948,7 +1951,7 @@ struct PrintUsageImplementation
}
// ch is the decoded unicode code point
if (ch >= 0x1100 && isWideChar(ch)) // the test for 0x1100 is here to avoid the function call in the Latin case
++screenlen;
{ ++screenlen; }
}
}
}
@ -1956,8 +1959,8 @@ struct PrintUsageImplementation
public:
//! @brief Creates an iterator for @c usage.
LinePartIterator(const Descriptor usage[]) :
tablestart(usage), rowdesc(0), rowstart(0), ptr(0), col(-1), len(0), max_line_in_block(0), line_in_block(0),
target_line_in_block(0), hit_target_line(true)
tablestart(usage), rowdesc(0), rowstart(0), ptr(0), col(-1), len(0), max_line_in_block(0), line_in_block(0),
target_line_in_block(0), hit_target_line(true)
{
}
@ -1973,12 +1976,12 @@ struct PrintUsageImplementation
if (rowdesc != 0)
{
while (tablestart->help != 0 && tablestart->shortopt != 0)
++tablestart;
{ ++tablestart; }
}
// Find the next table after the break (if any)
while (tablestart->help == 0 && tablestart->shortopt != 0)
++tablestart;
{ ++tablestart; }
restartTable();
return rowstart != 0;
@ -2008,12 +2011,12 @@ struct PrintUsageImplementation
}
while (*ptr != 0 && *ptr != '\n')
++ptr;
{ ++ptr; }
if (*ptr == 0)
{
if ((rowdesc + 1)->help == 0) // table break
return false;
{ return false; }
++rowdesc;
rowstart = rowdesc->help;
@ -2052,7 +2055,7 @@ struct PrintUsageImplementation
bool next()
{
if (ptr == 0)
return false;
{ return false; }
if (col == -1)
{
@ -2072,7 +2075,8 @@ struct PrintUsageImplementation
break;
case '\t':
if (!hit_target_line) // if previous column did not have the targetline
{ // then "insert" a 0-length part
{
// then "insert" a 0-length part
update_length();
hit_target_line = true;
return true;
@ -2086,7 +2090,8 @@ struct PrintUsageImplementation
case 0:
case '\n':
if (!hit_target_line) // if previous column did not have the targetline
{ // then "insert" a 0-length part
{
// then "insert" a 0-length part
update_length();
hit_target_line = true;
return true;
@ -2249,7 +2254,7 @@ struct PrintUsageImplementation
void output(IStringWriter& write, const char* data, int len)
{
if (buf_full())
write_one_line(write);
{ write_one_line(write); }
buf_store(data, len);
}
@ -2284,12 +2289,12 @@ struct PrintUsageImplementation
void flush(IStringWriter& write)
{
if (buf_empty())
return;
{ return; }
int _ = 0;
indent(write, _, x);
wrote_something = false;
while (!buf_empty())
write_one_line(write);
{ write_one_line(write); }
write("\n", 1);
}
@ -2337,7 +2342,7 @@ struct PrintUsageImplementation
unsigned mask = (unsigned) -1 >> __builtin_clz(ch ^ 0xff);
ch = ch & mask; // mask out length bits, we don't verify their correctness
while ((maxi + charbytes < len) && //
(((unsigned char) data[maxi + charbytes] ^ 0x80) <= 0x3F)) // while next byte is continuation byte
(((unsigned char) data[maxi + charbytes] ^ 0x80) <= 0x3F)) // while next byte is continuation byte
{
ch = (ch << 6) ^ (unsigned char) data[maxi + charbytes] ^ 0x80; // add continuation to char code
++charbytes;
@ -2346,7 +2351,7 @@ struct PrintUsageImplementation
if (ch >= 0x1100 && isWideChar(ch)) // the test for 0x1100 is here to avoid the function call in the Latin case
{
if (utf8width + 2 > width)
break;
{ break; }
++utf8width;
}
}
@ -2367,7 +2372,7 @@ struct PrintUsageImplementation
int i;
for (i = maxi; i >= 0; --i)
if (data[i] == ' ')
break;
{ break; }
if (i >= 0)
{
@ -2376,7 +2381,8 @@ struct PrintUsageImplementation
len -= i + 1;
}
else // did not find a space to split at => split before data[maxi]
{ // data[maxi] is always the beginning of a character, never a continuation byte
{
// data[maxi] is always the beginning of a character, never a continuation byte
output(write, data, maxi);
data += maxi;
len -= maxi;
@ -2385,7 +2391,7 @@ struct PrintUsageImplementation
}
}
if (!wrote_something) // if we didn't already write something to make space in the buffer
write_one_line(write); // write at most one line of actual output
{ write_one_line(write); } // write at most one line of actual output
}
/**
@ -2395,10 +2401,10 @@ struct PrintUsageImplementation
* @c x1 gives the indentation LineWrapper uses if it needs to indent.
*/
LineWrapper(int x1, int x2) :
x(x1), width(x2 - x1), head(0), tail(bufmask)
x(x1), width(x2 - x1), head(0), tail(bufmask)
{
if (width < 2) // because of wide characters we need at least width 2 or the code breaks
width = 2;
{ width = 2; }
}
};
@ -2411,15 +2417,15 @@ struct PrintUsageImplementation
int last_column_min_percent = 50, int last_column_own_line_max_percent = 75)
{
if (width < 1) // protect against nonsense values
width = 80;
{ width = 80; }
if (width > 10000) // protect against overflow in the following computation
width = 10000;
{ width = 10000; }
int last_column_min_width = ((width * last_column_min_percent) + 50) / 100;
int last_column_own_line_max_width = ((width * last_column_own_line_max_percent) + 50) / 100;
if (last_column_own_line_max_width == 0)
last_column_own_line_max_width = 1;
{ last_column_own_line_max_width = 1; }
LinePartIterator part(usage);
while (part.nextTable())
@ -2436,7 +2442,7 @@ struct PrintUsageImplementation
{
lastcolumn = 0;
for (int i = 0; i < maxcolumns; ++i)
col_width[i] = 0;
{ col_width[i] = 0; }
part.restartTable();
while (part.nextRow())
@ -2452,7 +2458,7 @@ struct PrintUsageImplementation
// or explanatory paragraphs that do not participate in the table layout.
if (part.column() > 0 || part.line() > 0 || part.data()[part.length()] == '\t'
|| part.data()[part.length()] == '\v')
upmax(col_width[part.column()], part.screenLength());
{ upmax(col_width[part.column()], part.screenLength()); }
}
}
}
@ -2476,14 +2482,15 @@ struct PrintUsageImplementation
upmax(overlong_column_threshold, col_width[i]);
}
} while (leftwidth > width);
}
while (leftwidth > width);
/**************** Determine tab stops and last column handling **********************/
int tabstop[maxcolumns];
tabstop[0] = 0;
for (int i = 1; i < maxcolumns; ++i)
tabstop[i] = tabstop[i - 1] + col_width[i - 1];
{ tabstop[i] = tabstop[i - 1] + col_width[i - 1]; }
int rightwidth = width - tabstop[lastcolumn];
bool print_last_column_on_own_line = false;
@ -2502,7 +2509,7 @@ struct PrintUsageImplementation
// a bullshit value >100 for last_column_min_percent) => the above if condition
// is false => print_last_column_on_own_line==false
if (lastcolumn == 0)
print_last_column_on_own_line = false;
{ print_last_column_on_own_line = false; }
LineWrapper lastColumnLineWrapper(width - rightwidth, width);
LineWrapper interjectionLineWrapper(0, width);
@ -2517,12 +2524,12 @@ struct PrintUsageImplementation
while (part.next())
{
if (part.column() > lastcolumn)
continue; // drop excess columns (can happen if lastcolumn == maxcolumns-1)
{ continue; } // drop excess columns (can happen if lastcolumn == maxcolumns-1)
if (part.column() == 0)
{
if (x >= 0)
write("\n", 1);
{ write("\n", 1); }
x = 0;
}
@ -2536,7 +2543,7 @@ struct PrintUsageImplementation
x += part.screenLength();
}
else // either part.column() == lastcolumn or we are in the special case of
// an interjection that doesn't contain \v or \t
// an interjection that doesn't contain \v or \t
{
// NOTE: This code block is not necessarily executed for
// each line, because some rows may have fewer columns.
@ -2544,7 +2551,7 @@ struct PrintUsageImplementation
LineWrapper& lineWrapper = (part.column() == 0) ? interjectionLineWrapper : lastColumnLineWrapper;
if (!print_last_column_on_own_line)
lineWrapper.process(write, part.data(), part.length());
{ lineWrapper.process(write, part.data(), part.length()); }
}
} // while
@ -2804,7 +2811,7 @@ void printUsage(Syscall* prn, int fd, const Descriptor descriptors[], int width
template<typename Function, typename Stream>
void printUsage(Function* prn, Stream* stream, const Descriptor descriptors[], int width = 80, int last_column_min_percent =
50,
50,
int last_column_own_line_max_percent = 75)
{
PrintUsageImplementation::StreamWriter<Function, Stream> write(prn, stream);
@ -2814,7 +2821,8 @@ void printUsage(Function* prn, Stream* stream, const Descriptor descriptors[], i
}
// namespace option
} }
}
}
// namespace vtkm::testing
#endif /* OPTIONPARSER_H_ */

@ -68,14 +68,14 @@ public:
{
public:
VTKM_CONT_EXPORT TestFailure(const std::string &file,
vtkm::Id line,
const std::string &message)
vtkm::Id line,
const std::string &message)
: File(file), Line(line), Message(message) { }
VTKM_CONT_EXPORT TestFailure(const std::string &file,
vtkm::Id line,
const std::string &message,
const std::string &condition)
vtkm::Id line,
const std::string &message,
const std::string &condition)
: File(file), Line(line)
{
this->Message.append(message);
@ -86,7 +86,8 @@ public:
VTKM_CONT_EXPORT const std::string &GetFile() const { return this->File; }
VTKM_CONT_EXPORT vtkm::Id GetLine() const { return this->Line; }
VTKM_CONT_EXPORT const std::string &GetMessage() const {
VTKM_CONT_EXPORT const std::string &GetMessage() const
{
return this->Message;
}
private:
@ -96,19 +97,19 @@ public:
};
static VTKM_CONT_EXPORT void Assert(bool condition,
const std::string &file,
vtkm::Id line,
const std::string &message,
const std::string &conditionString)
const std::string &file,
vtkm::Id line,
const std::string &message,
const std::string &conditionString)
{
if (condition)
{
{
// Do nothing.
}
}
else
{
{
throw TestFailure(file, line, message, conditionString);
}
}
}
#ifndef VTKM_TESTING_IN_CONT
@ -143,89 +144,104 @@ public:
static VTKM_CONT_EXPORT int Run(Func function)
{
try
{
{
function();
}
}
catch (TestFailure error)
{
{
std::cout << "***** Test failed @ "
<< error.GetFile() << ":" << error.GetLine() << std::endl
<< error.GetMessage() << std::endl;
return 1;
}
}
catch (...)
{
{
std::cout << "***** Unidentified exception thrown." << std::endl;
return 1;
}
}
return 0;
}
#endif
/// Check functors to be used with the TryAllTypes method.
///
struct TypeCheckAlwaysTrue {
struct TypeCheckAlwaysTrue
{
template <typename T, class Functor>
void operator()(T t, Functor function) const { function(t); }
};
struct TypeCheckInteger {
struct TypeCheckInteger
{
template <typename T, class Functor>
void operator()(T t, Functor function) const {
void operator()(T t, Functor function) const
{
this->DoInteger(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
}
private:
template <class Tag, typename T, class Functor>
void DoInteger(Tag, T, const Functor&) const { }
template <typename T, class Functor>
void DoInteger(vtkm::TypeTraitsIntegerTag, T t, Functor function) const {
void DoInteger(vtkm::TypeTraitsIntegerTag, T t, Functor function) const
{
function(t);
}
};
struct TypeCheckReal {
struct TypeCheckReal
{
template <typename T, class Functor>
void operator()(T t, Functor function) const {
void operator()(T t, Functor function) const
{
this->DoReal(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
}
private:
template <class Tag, typename T, class Functor>
void DoReal(Tag, T, const Functor&) const { }
template <typename T, class Functor>
void DoReal(vtkm::TypeTraitsRealTag, T t, Functor function) const {
void DoReal(vtkm::TypeTraitsRealTag, T t, Functor function) const
{
function(t);
}
};
struct TypeCheckScalar {
struct TypeCheckScalar
{
template <typename T, class Functor>
void operator()(T t, Functor func) const {
void operator()(T t, Functor func) const
{
this->DoScalar(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
}
private:
template <class Tag, typename T, class Functor>
void DoScalar(Tag, const T &, const Functor &) const { }
template <typename T, class Functor>
void DoScalar(vtkm::TypeTraitsScalarTag, T t, Functor function) const {
void DoScalar(vtkm::TypeTraitsScalarTag, T t, Functor function) const
{
function(t);
}
};
struct TypeCheckVector {
struct TypeCheckVector
{
template <typename T, class Functor>
void operator()(T t, Functor func) const {
void operator()(T t, Functor func) const
{
this->DoVector(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
}
private:
template <class Tag, typename T, class Functor>
void DoVector(Tag, const T &, const Functor &) const { }
template <typename T, class Functor>
void DoVector(vtkm::TypeTraitsVectorTag, T t, Functor function) const {
void DoVector(vtkm::TypeTraitsVectorTag, T t, Functor function) const
{
function(t);
}
};
template<class FunctionType>
struct InternalPrintOnInvoke {
struct InternalPrintOnInvoke
{
InternalPrintOnInvoke(FunctionType function, std::string toprint)
: Function(function), ToPrint(toprint) { }
template <typename T> void operator()(T t) {
template <typename T> void operator()(T t)
{
std::cout << this->ToPrint << std::endl;
this->Function(t);
}
@ -288,27 +304,27 @@ VTKM_EXEC_CONT_EXPORT bool test_equal(VectorType vector1,
{
typedef typename vtkm::VectorTraits<VectorType> Traits;
for (int component = 0; component < Traits::NUM_COMPONENTS; component++)
{
{
vtkm::Scalar value1 = Traits::GetComponent(vector1, component);
vtkm::Scalar value2 = Traits::GetComponent(vector2, component);
if ((fabs(value1) < 2*tolerance) && (fabs(value2) < 2*tolerance))
{
{
continue;
}
}
vtkm::Scalar ratio = value1/value2;
if ((ratio > vtkm::Scalar(1.0) - tolerance)
&& (ratio < vtkm::Scalar(1.0) + tolerance))
{
{
// This component is OK. The condition is checked in this way to
// correctly handle non-finites that fail all comparisons. Thus, if a
// non-finite is encountered, this condition will fail and false will be
// returned.
}
else
{
return false;
}
}
else
{
return false;
}
}
return true;
}
@ -320,9 +336,9 @@ std::ostream &operator<<(std::ostream &stream, const vtkm::Tuple<T,Size> &tuple)
{
stream << "[";
for (int component = 0; component < Size-1; component++)
{
{
stream << tuple[component] << ",";
}
}
return stream << tuple[Size-1] << "]";
}

@ -43,9 +43,9 @@ void GoodAssert()
void TestTestEqual()
{
VTKM_TEST_ASSERT(test_equal(vtkm::Scalar(2.0), vtkm::Scalar(1.9999999)),
"These should be close enough.");
"These should be close enough.");
VTKM_TEST_ASSERT(!test_equal(vtkm::Scalar(2.0), vtkm::Scalar(1.999)),
"These should not be close enough.");
"These should not be close enough.");
}
// All tests that should not raise a failure.
@ -61,16 +61,16 @@ int UnitTestTesting(int, char *[])
{
std::cout << "This call should fail." << std::endl;
if (vtkm::testing::Testing::Run(Fail) == 0)
{
{
std::cout << "Did not get expected fail!" << std::endl;
return 1;
}
}
std::cout << "This call should fail." << std::endl;
if (vtkm::testing::Testing::Run(BadAssert) == 0)
{
{
std::cout << "Did not get expected fail!" << std::endl;
return 1;
}
}
std::cout << "This call should pass." << std::endl;
// This is what your main function typically looks like.

@ -28,7 +28,8 @@ namespace {
struct TypeTraitTest
{
template <typename T> void operator()(T t) {
template <typename T> void operator()(T t)
{
// If you get compiler errors here, it could be a TypeTraits instance
// has missing or malformed tags.
this->TestDimensionality(t, typename vtkm::TypeTraits<T>::DimensionalityTag());
@ -37,32 +38,36 @@ struct TypeTraitTest
private:
template <typename T>
void TestDimensionality(T, vtkm::TypeTraitsScalarTag) {
void TestDimensionality(T, vtkm::TypeTraitsScalarTag)
{
std::cout << " scalar" << std::endl;
VTKM_TEST_ASSERT(vtkm::VectorTraits<T>::NUM_COMPONENTS == 1,
"Scalar type does not have one component.");
"Scalar type does not have one component.");
}
template <typename T>
void TestDimensionality(T, vtkm::TypeTraitsVectorTag) {
void TestDimensionality(T, vtkm::TypeTraitsVectorTag)
{
std::cout << " vector" << std::endl;
VTKM_TEST_ASSERT(vtkm::VectorTraits<T>::NUM_COMPONENTS > 1,
"Vector type does not have multiple components.");
"Vector type does not have multiple components.");
}
template <typename T>
void TestNumeric(T, vtkm::TypeTraitsIntegerTag) {
void TestNumeric(T, vtkm::TypeTraitsIntegerTag)
{
std::cout << " integer" << std::endl;
typedef typename vtkm::VectorTraits<T>::ComponentType VT;
VT value = VT(2.001);
VTKM_TEST_ASSERT(value == 2, "Integer does not round to integer.");
}
template <typename T>
void TestNumeric(T, vtkm::TypeTraitsRealTag) {
void TestNumeric(T, vtkm::TypeTraitsRealTag)
{
std::cout << " real" << std::endl;
typedef typename vtkm::VectorTraits<T>::ComponentType VT;
VT value = VT(2.001);
VTKM_TEST_ASSERT(test_equal(float(value), float(2.001)),
"Real does not hold floaing point number.");
"Real does not hold floaing point number.");
}
};

@ -52,11 +52,11 @@ template <typename T> void TypeTest()
typename T::ComponentType s(5);
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{
{
a[i]=typename T::ComponentType((i+1)*2);
b[i]=typename T::ComponentType(i+1);
c[i]=typename T::ComponentType((i+1)*2);
}
}
//verify prefix and postfix increment and decrement
++c[T::NUM_COMPONENTS-1];
@ -70,42 +70,42 @@ template <typename T> void TypeTest()
T plus = a + b;
T correct_plus;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{ correct_plus[i] = a[i] + b[i]; }
{ correct_plus[i] = a[i] + b[i]; }
VTKM_TEST_ASSERT(test_equal(plus, correct_plus),"Tuples not added correctly.");
T minus = a - b;
T correct_minus;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{ correct_minus[i] = a[i] - b[i]; }
{ correct_minus[i] = a[i] - b[i]; }
VTKM_TEST_ASSERT(test_equal(minus, correct_minus),"Tuples not subtracted correctly.");
T mult = a * b;
T correct_mult;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{ correct_mult[i] = a[i] * b[i]; }
{ correct_mult[i] = a[i] * b[i]; }
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),"Tuples not multiplied correctly.");
T div = a / b;
T correct_div;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{ correct_div[i] = a[i] / b[i]; }
{ correct_div[i] = a[i] / b[i]; }
VTKM_TEST_ASSERT(test_equal(div,correct_div),"Tuples not divided correctly.");
mult = s * a;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{ correct_mult[i] = s * a[i]; }
{ correct_mult[i] = s * a[i]; }
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),
"Scalar and Tuple did not multiply correctly.");
"Scalar and Tuple did not multiply correctly.");
mult = a * s;
VTKM_TEST_ASSERT(test_equal(mult, correct_mult),
"Tuple and Scalar to not multiply correctly.");
"Tuple and Scalar to not multiply correctly.");
typename T::ComponentType d = vtkm::dot(a, b);
typename T::ComponentType correct_d = 0;
for(int i=0; i < T::NUM_COMPONENTS; ++i)
{correct_d += a[i] * b[i]; }
{correct_d += a[i] * b[i]; }
VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong");
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
@ -137,27 +137,27 @@ template<> void TypeTest<vtkm::Vector2>()
vtkm::Vector2 plus = a + b;
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector2(3, 6)),
"Vectors do not add correctly.");
"Vectors do not add correctly.");
vtkm::Vector2 minus = a - b;
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector2(1, 2)),
"Vectors to not subtract correctly.");
"Vectors to not subtract correctly.");
vtkm::Vector2 mult = a * b;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(2, 8)),
"Vectors to not multiply correctly.");
"Vectors to not multiply correctly.");
vtkm::Vector2 div = a / b;
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector2(2, 2)),
"Vectors to not divide correctly.");
"Vectors to not divide correctly.");
mult = s * a;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
mult = a * s;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
vtkm::Scalar d = vtkm::dot(a, b);
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(10)), "dot(Vector2) wrong");
@ -193,27 +193,27 @@ template<> void TypeTest<vtkm::Vector3>()
vtkm::Vector3 plus = a + b;
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector3(3, 6, 9)),
"Vectors do not add correctly.");
"Vectors do not add correctly.");
vtkm::Vector3 minus = a - b;
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector3(1, 2, 3)),
"Vectors to not subtract correctly.");
"Vectors to not subtract correctly.");
vtkm::Vector3 mult = a * b;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(2, 8, 18)),
"Vectors to not multiply correctly.");
"Vectors to not multiply correctly.");
vtkm::Vector3 div = a / b;
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector3(2, 2, 2)),
"Vectors to not divide correctly.");
"Vectors to not divide correctly.");
mult = s * a;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
mult = a * s;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
vtkm::Scalar d = vtkm::dot(a, b);
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(28)), "dot(Vector3) wrong");
@ -249,27 +249,27 @@ template<> void TypeTest<vtkm::Vector4>()
vtkm::Vector4 plus = a + b;
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector4(3, 6, 9, 12)),
"Vectors do not add correctly.");
"Vectors do not add correctly.");
vtkm::Vector4 minus = a - b;
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector4(1, 2, 3, 4)),
"Vectors to not subtract correctly.");
"Vectors to not subtract correctly.");
vtkm::Vector4 mult = a * b;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(2, 8, 18, 32)),
"Vectors to not multiply correctly.");
"Vectors to not multiply correctly.");
vtkm::Vector4 div = a / b;
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector4(2, 2, 2, 2)),
"Vectors to not divide correctly.");
"Vectors to not divide correctly.");
mult = s * a;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
mult = a * s;
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)),
"Vector and scalar to not multiply correctly.");
"Vector and scalar to not multiply correctly.");
vtkm::Scalar d = vtkm::dot(a, b);
VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(60)), "dot(Vector4) wrong");
@ -306,44 +306,44 @@ template<> void TypeTest<vtkm::Id3>()
vtkm::Id3 plus = a + b;
if ((plus[0] != 3) || (plus[1] != 6) || (plus[2] != 9))
{
{
VTKM_TEST_FAIL("Vectors do not add correctly.");
}
}
vtkm::Id3 minus = a - b;
if ((minus[0] != 1) || (minus[1] != 2) || (minus[2] != 3))
{
{
VTKM_TEST_FAIL("Vectors to not subtract correctly.");
}
}
vtkm::Id3 mult = a * b;
if ((mult[0] != 2) || (mult[1] != 8) || (mult[2] != 18))
{
{
VTKM_TEST_FAIL("Vectors to not multiply correctly.");
}
}
vtkm::Id3 div = a / b;
if ((div[0] != 2) || (div[1] != 2) || (div[2] != 2))
{
{
VTKM_TEST_FAIL("Vectors to not divide correctly.");
}
}
mult = s * a;
if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30))
{
{
VTKM_TEST_FAIL("Vector and scalar to not multiply correctly.");
}
}
mult = a * s;
if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30))
{
{
VTKM_TEST_FAIL("Vector and scalar to not multiply correctly.");
}
}
if (vtkm::dot(a, b) != 28)
{
{
VTKM_TEST_FAIL("dot(Id3) wrong");
}
}
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
VTKM_TEST_ASSERT((b < a), "operator< wrong");
@ -352,22 +352,22 @@ template<> void TypeTest<vtkm::Id3>()
VTKM_TEST_ASSERT((minus < plus), "operator< wrong");
if (a == b)
{
{
VTKM_TEST_FAIL("operator== wrong");
}
}
if (!(a == a))
{
{
VTKM_TEST_FAIL("operator== wrong");
}
}
if (!(a != b))
{
{
VTKM_TEST_FAIL("operator!= wrong");
}
}
if (a != a)
{
{
VTKM_TEST_FAIL("operator!= wrong");
}
}
//test against a tuple that shares some values
const vtkm::Id3 c = vtkm::make_Id3(2,4,5);
@ -387,41 +387,41 @@ template<> void TypeTest<vtkm::Scalar>()
vtkm::Scalar plus = a + b;
if (plus != 6)
{
{
VTKM_TEST_FAIL("Scalars do not add correctly.");
}
}
vtkm::Scalar minus = a - b;
if (minus != 2)
{
{
VTKM_TEST_FAIL("Scalars to not subtract correctly.");
}
}
vtkm::Scalar mult = a * b;
if (mult != 8)
{
{
VTKM_TEST_FAIL("Scalars to not multiply correctly.");
}
}
vtkm::Scalar div = a / b;
if (div != 2)
{
{
VTKM_TEST_FAIL("Scalars to not divide correctly.");
}
}
if (a == b)
{
{
VTKM_TEST_FAIL("operator== wrong");
}
}
if (!(a != b))
{
{
VTKM_TEST_FAIL("operator!= wrong");
}
}
if (vtkm::dot(a, b) != 8)
{
{
VTKM_TEST_FAIL("dot(Scalar) wrong");
}
}
}
template<> void TypeTest<vtkm::Id>()
@ -431,46 +431,47 @@ template<> void TypeTest<vtkm::Id>()
vtkm::Id plus = a + b;
if (plus != 6)
{
{
VTKM_TEST_FAIL("Scalars do not add correctly.");
}
}
vtkm::Id minus = a - b;
if (minus != 2)
{
{
VTKM_TEST_FAIL("Scalars to not subtract correctly.");
}
}
vtkm::Id mult = a * b;
if (mult != 8)
{
{
VTKM_TEST_FAIL("Scalars to not multiply correctly.");
}
}
vtkm::Id div = a / b;
if (div != 2)
{
{
VTKM_TEST_FAIL("Scalars to not divide correctly.");
}
}
if (a == b)
{
{
VTKM_TEST_FAIL("operator== wrong");
}
}
if (!(a != b))
{
{
VTKM_TEST_FAIL("operator!= wrong");
}
}
if (vtkm::dot(a, b) != 8)
{
{
VTKM_TEST_FAIL("dot(Id) wrong");
}
}
}
struct TypeTestFunctor
{
template <typename T> void operator()(const T&) const {
template <typename T> void operator()(const T&) const
{
TypeTest<T>();
}
};

@ -28,15 +28,16 @@ static const vtkm::Id VectorInit[MAX_VECTOR_SIZE] = { 42, 54, 67, 12, 78 };
struct TestVectorTypeFunctor
{
template <typename T> void operator()(const T&) const {
template <typename T> void operator()(const T&) const
{
typedef vtkm::VectorTraits<T> Traits;
VTKM_TEST_ASSERT(Traits::NUM_COMPONENTS <= MAX_VECTOR_SIZE,
"Need to update test for larger vectors.");
"Need to update test for larger vectors.");
T vector;
for (int index = 0; index < Traits::NUM_COMPONENTS; index++)
{
{
Traits::SetComponent(vector, index, VectorInit[index]);
}
}
vtkm::testing::TestVectorType(vector);
}
};

@ -48,7 +48,7 @@ inline void CompareDimensionalityTags(vtkm::TypeTraitsVectorTag,
/// the Tuple class.
template <class T>
static void TestVectorTypeImpl(
const typename boost::remove_const<T>::type &vector)
const typename boost::remove_const<T>::type &vector)
{
typedef typename vtkm::VectorTraits<T> Traits;
typedef typename Traits::ComponentType ComponentType;
@ -56,48 +56,48 @@ static void TestVectorTypeImpl(
typedef typename boost::remove_const<T>::type NonConstT;
{
NonConstT result;
const ComponentType multiplier = 4;
for (int i = 0; i < NUM_COMPONENTS; i++)
NonConstT result;
const ComponentType multiplier = 4;
for (int i = 0; i < NUM_COMPONENTS; i++)
{
Traits::SetComponent(result, i, multiplier*Traits::GetComponent(vector, i));
Traits::SetComponent(result, i, multiplier*Traits::GetComponent(vector, i));
}
VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result),
multiplier*Traits::ToTuple(vector)),
"Got bad result for scalar multiple");
VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result),
multiplier*Traits::ToTuple(vector)),
"Got bad result for scalar multiple");
}
{
NonConstT result;
const ComponentType multiplier = 7;
for (int i = 0; i < NUM_COMPONENTS; i++)
NonConstT result;
const ComponentType multiplier = 7;
for (int i = 0; i < NUM_COMPONENTS; i++)
{
Traits::GetComponent(result, i)
Traits::GetComponent(result, i)
= multiplier * Traits::GetComponent(vector, i);
}
VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result),
multiplier*Traits::ToTuple(vector)),
"Got bad result for scalar multiple");
VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result),
multiplier*Traits::ToTuple(vector)),
"Got bad result for scalar multiple");
}
{
ComponentType result = 0;
for (int i = 0; i < NUM_COMPONENTS; i++)
ComponentType result = 0;
for (int i = 0; i < NUM_COMPONENTS; i++)
{
ComponentType component
ComponentType component
= Traits::GetComponent(vector, i);
result += component * component;
result += component * component;
}
VTKM_TEST_ASSERT(
test_equal(result,
vtkm::dot(Traits::ToTuple(vector), Traits::ToTuple(vector))),
"Got bad result for dot product");
VTKM_TEST_ASSERT(
test_equal(result,
vtkm::dot(Traits::ToTuple(vector), Traits::ToTuple(vector))),
"Got bad result for dot product");
}
// This will fail to compile if the tags are wrong.
detail::CompareDimensionalityTags(
typename vtkm::TypeTraits<T>::DimensionalityTag(),
typename vtkm::VectorTraits<T>::HasMultipleComponents());
typename vtkm::TypeTraits<T>::DimensionalityTag(),
typename vtkm::VectorTraits<T>::HasMultipleComponents());
}
inline void CheckVectorComponentsTag(vtkm::VectorTraitsTagMultipleComponents)
@ -117,7 +117,7 @@ inline void TestVectorComponentsTag()
// This will fail to compile if the tag is wrong
// (i.e. not vtkm::VectorTraitsTagMultipleComponents)
detail::CheckVectorComponentsTag(
typename vtkm::VectorTraits<T>::HasMultipleComponents());
typename vtkm::VectorTraits<T>::HasMultipleComponents());
}
namespace detail {
@ -148,7 +148,7 @@ inline void TestScalarComponentsTag()
// This will fail to compile if the tag is wrong
// (i.e. not vtkm::VectorTraitsTagSingleComponent)
detail::CheckScalarComponentsTag(
typename vtkm::VectorTraits<T>::HasMultipleComponents());
typename vtkm::VectorTraits<T>::HasMultipleComponents());
}
}