From cbe6284b833adb441f248eb08a785ddb4c17cb1b Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 7 Oct 2014 10:59:34 -0600 Subject: [PATCH] Add IdComponent and other base types with explicit widths In preparation for supporting base types with more widths, add typedefs for the base types with explicit widths (number of bits). Also added a IdComponent type that should be used for indices for components into tuples and vectors. There now should be no reason to use "int" inside of VTK-m code (especially for indexing). This change cleans up many of the int types that were used throughout. --- CMakeLists.txt | 2 + vtkm/Extent.h | 28 +-- vtkm/TypeTraits.h | 3 +- vtkm/Types.h | 215 +++++++++++------- vtkm/VectorTraits.h | 28 +-- vtkm/cont/ArrayHandleCompositeVector.h | 58 ++--- vtkm/cont/internal/DeviceAdapterAlgorithm.h | 4 +- vtkm/cont/internal/IteratorFromArrayPortal.h | 2 +- vtkm/cont/testing/TestingDeviceAdapter.h | 12 +- .../UnitTestArrayHandleCompositeVector.cxx | 22 +- .../testing/UnitTestDynamicArrayHandle.cxx | 4 +- vtkm/cont/testing/UnitTestStorageListTag.cxx | 8 +- vtkm/internal/Configure.h.in | 2 + vtkm/internal/FunctionInterface.h | 24 +- vtkm/testing/Testing.h | 8 +- vtkm/testing/UnitTestExtent.cxx | 34 +-- vtkm/testing/UnitTestListTag.cxx | 6 +- vtkm/testing/UnitTestTypeListTag.cxx | 8 +- vtkm/testing/UnitTestTypes.cxx | 30 ++- vtkm/testing/UnitTestVectorTraits.cxx | 2 +- 20 files changed, 287 insertions(+), 213 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1966db5ff..945eaff66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,8 @@ include(CheckTypeSize) check_type_size(float VTKm_SIZE_FLOAT BUILTIN_TYPES_ONLY) check_type_size(double VTKm_SIZE_DOUBLE BUILTIN_TYPES_ONLY) +check_type_size(char VTKm_SIZE_CHAR BUILTIN_TYPES_ONLY) +check_type_size(short VTKm_SIZE_SHORT BUILTIN_TYPES_ONLY) check_type_size(int VTKm_SIZE_INT BUILTIN_TYPES_ONLY) check_type_size(long VTKm_SIZE_LONG BUILTIN_TYPES_ONLY) check_type_size("long long" VTKm_SIZE_LONG_LONG BUILTIN_TYPES_ONLY) diff --git a/vtkm/Extent.h b/vtkm/Extent.h index 10a044a55..b4d7687a6 100644 --- a/vtkm/Extent.h +++ b/vtkm/Extent.h @@ -27,7 +27,7 @@ namespace vtkm { /// Extent stores the values for the index ranges for a structured grid array. /// It does this through the minimum indices and the maximum indices. /// -template +template struct Extent { vtkm::Tuple Min; @@ -66,7 +66,7 @@ typedef vtkm::Extent<2> Extent2; /// Given an extent, returns the array dimensions for the points. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple ExtentPointDimensions(const vtkm::Extent &extent) @@ -93,7 +93,7 @@ vtkm::Id2 ExtentPointDimensions(const vtkm::Extent2 &extent) /// Given an extent, returns the array dimensions for the cells. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple ExtentCellDimensions(const vtkm::Extent &extent) @@ -103,7 +103,7 @@ ExtentCellDimensions(const vtkm::Extent &extent) /// Given an extent, returns the number of points in the structured mesh. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentNumberOfPoints(const vtkm::Extent &extent) { @@ -134,7 +134,7 @@ vtkm::Id ExtentNumberOfPoints(const vtkm::Extent2 &extent) /// Given an extent, returns the number of cells in the structured mesh. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentNumberOfCells(const vtkm::Extent &extent) { @@ -168,7 +168,7 @@ vtkm::Id ExtentNumberOfCells(const vtkm::Extent2 &extent) /// then the s direction and so on. This method converts a flat index to the /// topological coordinates (e.g. r,s,t for 3d topologies). /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple ExtentPointFlatIndexToTopologyIndex(vtkm::Id index, @@ -178,7 +178,7 @@ ExtentPointFlatIndexToTopologyIndex(vtkm::Id index, vtkm::ExtentPointDimensions(extent); vtkm::Tuple ijkIndex; vtkm::Id indexOnDim = index; - for (int dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) { ijkIndex[dimIndex] = indexOnDim % dims[dimIndex] + extent.Min[dimIndex]; indexOnDim /= dims[dimIndex]; @@ -216,7 +216,7 @@ vtkm::Id2 ExtentPointFlatIndexToTopologyIndex(vtkm::Id index, /// then the s direction and so on. This method converts a flat index to the /// topological coordinates (e.g. r,s,t for 3d topologies). /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple ExtentCellFlatIndexToTopologyIndex(vtkm::Id index, @@ -226,7 +226,7 @@ ExtentCellFlatIndexToTopologyIndex(vtkm::Id index, vtkm::ExtentCellDimensions(extent); vtkm::Tuple ijkIndex; vtkm::Id indexOnDim = index; - for (int dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) { ijkIndex[dimIndex] = indexOnDim % dims[dimIndex] + extent.Min[dimIndex]; indexOnDim /= dims[dimIndex]; @@ -264,7 +264,7 @@ vtkm::Id2 ExtentCellFlatIndexToTopologyIndex(vtkm::Id index, /// then the s direction and so on. This method converts topological /// coordinates to a flat index. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentPointTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, @@ -273,7 +273,7 @@ ExtentPointTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, const vtkm::Tuple dims = ExtentPointDimensions(extent); const vtkm::Tuple deltas = ijk - extent.Min; vtkm::Id flatIndex = deltas[Dimensions-1]; - for (int dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) + for (vtkm::IdComponent dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) { flatIndex = flatIndex*dims[dimIndex] + deltas[dimIndex]; } @@ -285,7 +285,7 @@ ExtentPointTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, /// then the s direction and so on. This method converts topological /// coordinates to a flat index. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentCellTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, @@ -294,7 +294,7 @@ ExtentCellTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, const vtkm::Tuple dims = ExtentCellDimensions(extent); const vtkm::Tuple deltas = ijk - extent.Min; vtkm::Id flatIndex = deltas[Dimensions-1]; - for (int dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) + for (vtkm::IdComponent dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) { flatIndex = flatIndex*dims[dimIndex] + deltas[dimIndex]; } @@ -304,7 +304,7 @@ ExtentCellTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, /// Given a cell index, returns the index to the first point incident on that /// cell. /// -template +template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentFirstPointOnCell(vtkm::Id cellIndex, const Extent &extent) diff --git a/vtkm/TypeTraits.h b/vtkm/TypeTraits.h index d08676987..37c216817 100644 --- a/vtkm/TypeTraits.h +++ b/vtkm/TypeTraits.h @@ -136,7 +136,8 @@ VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag); /// Traits for tuples. /// -template struct TypeTraits > +template +struct TypeTraits > { typedef typename TypeTraits::NumericTag NumericTag; typedef TypeTraitsVectorTag DimensionalityTag; diff --git a/vtkm/Types.h b/vtkm/Types.h index d4a58a9f8..ee1f9158a 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -88,28 +88,89 @@ namespace vtkm { /// Alignment requirements are prescribed by CUDA on device (Table B-1 in NVIDIA /// CUDA C Programming Guide 4.0) -namespace internal { +#if VTKM_SIZE_FLOAT == 4 +typedef float Float32; +#else +#error Could not find a 32-bit float. +#endif + +#if VTKM_SIZE_DOUBLE == 8 +typedef double Float64; +#else +#error Could not find a 64-bit float. +#endif + +#if VTKM_SIZE_CHAR == 1 +typedef signed char Int8; +typedef unsigned char UInt8; +#else +#error Could not find an 8-bit integer. +#endif + +#if VTKM_SIZE_SHORT == 2 +typedef signed short Int16; +typedef unsigned short UInt16; +#else +#error Could not find a 16-bit integer. +#endif #if VTKM_SIZE_INT == 4 -typedef int Int32Type; -typedef unsigned int UInt32Type; +typedef signed int Int32; +typedef unsigned int UInt32; #else #error Could not find a 32-bit integer. #endif #if VTKM_SIZE_LONG == 8 -typedef long Int64Type; -typedef unsigned long UInt64Type; +typedef signed long Int64; +typedef unsigned long UInt64; #elif VTKM_SIZE_LONG_LONG == 8 -typedef long long Int64Type; -typedef unsigned long long UInt64Type; +typedef signed long long Int64; +typedef unsigned long long UInt64; #else #error Could not find a 64-bit integer. #endif //----------------------------------------------------------------------------- -template +#if VTKM_SIZE_ID == 4 + +/// Represents an ID (index into arrays). +typedef vtkm::Int32 Id; + +#elif VTKM_SIZE_ID == 8 + +/// Represents an ID. +typedef vtkm::Int64 Id; + +#else +#error Unknown Id Size +#endif + +/// Represents a component ID (index of component in a vector). The number +/// of components, being a value fixed at compile time, is generally assumed +/// to be quite small. However, we are currently using a 32-bit width +/// integer because modern processors tend to access them more efficiently +/// than smaller widths. +typedef vtkm::Int32 IdComponent; + +#ifdef VTKM_USE_DOUBLE_PRECISION + +/// Scalar corresponds to a floating point number. +typedef vtkm::Float64 Scalar; + +#else //VTKM_USE_DOUBLE_PRECISION + +/// Scalar corresponds to a floating point number. +typedef vtkm::Float32 Scalar; + +#endif //VTKM_USE_DOUBLE_PRECISION + +namespace internal { + +//----------------------------------------------------------------------------- + +template struct equals { template @@ -149,7 +210,7 @@ struct equals<3> } }; -template +template struct assign_scalar_to_vector { template @@ -197,7 +258,7 @@ struct assign_scalar_to_vector<3> } }; -template +template struct copy_vector { template @@ -241,7 +302,7 @@ struct copy_vector<3> } }; -template +template struct sum_vector { template @@ -296,7 +357,7 @@ struct sum_vector<4> } }; -template +template struct product_vector { template @@ -356,53 +417,25 @@ struct product_vector<4> //----------------------------------------------------------------------------- -#if VTKM_SIZE_ID == 4 - -/// Represents an ID. -typedef internal::Int32Type Id; - -#elif VTKM_SIZE_ID == 8 - -/// Represents an ID. -typedef internal::Int64Type Id; - -#else -#error Unknown Id Size -#endif - -#ifdef VTKM_USE_DOUBLE_PRECISION - -/// Scalar corresponds to a floating point number. -typedef double Scalar; - -#else //VTKM_USE_DOUBLE_PRECISION - -/// Scalar corresponds to a floating point number. -typedef float Scalar; - -#endif //VTKM_USE_DOUBLE_PRECISION - -//----------------------------------------------------------------------------- - /// Tuple corresponds to a Size-tuple of type T -template +template class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS=Size; + static const vtkm::IdComponent NUM_COMPONENTS=Size; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) { - for(int i=0; i < NUM_COMPONENTS; ++i) + for(vtkm::IdComponent 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(vtkm::IdComponent i=0; i < NUM_COMPONENTS; ++i) { this->Components[i]=values[i]; } @@ -410,7 +443,7 @@ public: VTKM_EXEC_CONT_EXPORT Tuple(const Tuple &src) { - for (int i = 0; i < NUM_COMPONENTS; i++) + for (vtkm::IdComponent i = 0; i < NUM_COMPONENTS; i++) { this->Components[i] = src[i]; } @@ -419,18 +452,19 @@ public: VTKM_EXEC_CONT_EXPORT Tuple &operator=(const Tuple &src) { - for (int i = 0; i < NUM_COMPONENTS; i++) + for (vtkm::IdComponent 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[](vtkm::IdComponent idx) const { return this->Components[idx]; } - VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) + VTKM_EXEC_CONT_EXPORT ComponentType &operator[](vtkm::IdComponent idx) { return this->Components[idx]; } @@ -439,7 +473,9 @@ public: bool operator==(const Tuple &other) const { bool same = true; - for (int componentIndex=0; componentIndexComponents[componentIndex] == other[componentIndex]); } @@ -479,7 +515,7 @@ class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS = 1; + static const vtkm::IdComponent NUM_COMPONENTS = 1; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType&) { } @@ -494,7 +530,8 @@ public: return *this; } - VTKM_EXEC_CONT_EXPORT ComponentType operator[](int vtkmNotUsed(idx)) const + VTKM_EXEC_CONT_EXPORT + ComponentType operator[](vtkm::IdComponent vtkmNotUsed(idx)) const { return ComponentType(); } @@ -516,7 +553,7 @@ class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS = 1; + static const vtkm::IdComponent NUM_COMPONENTS = 1; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) @@ -536,12 +573,12 @@ public: } VTKM_EXEC_CONT_EXPORT - const ComponentType &operator[](int vtkmNotUsed(idx)) const + const ComponentType &operator[](vtkm::IdComponent vtkmNotUsed(idx)) const { return this->Component; } VTKM_EXEC_CONT_EXPORT - ComponentType &operator[](int vtkmNotUsed(idx)) + ComponentType &operator[](vtkm::IdComponent vtkmNotUsed(idx)) { return this->Component; } @@ -575,7 +612,7 @@ class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS = 2; + static const vtkm::IdComponent NUM_COMPONENTS = 2; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) @@ -605,11 +642,13 @@ public: return *this; } - VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const + VTKM_EXEC_CONT_EXPORT + const ComponentType &operator[](vtkm::IdComponent idx) const { return this->Components[idx]; } - VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) + VTKM_EXEC_CONT_EXPORT + ComponentType &operator[](vtkm::IdComponent idx) { return this->Components[idx]; } @@ -649,7 +688,7 @@ class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS = 3; + static const vtkm::IdComponent NUM_COMPONENTS = 3; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) @@ -681,11 +720,13 @@ public: return *this; } - VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const + VTKM_EXEC_CONT_EXPORT + const ComponentType &operator[](vtkm::IdComponent idx) const { return this->Components[idx]; } - VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) + VTKM_EXEC_CONT_EXPORT + ComponentType &operator[](vtkm::IdComponent idx) { return this->Components[idx]; } @@ -728,7 +769,7 @@ class Tuple { public: typedef T ComponentType; - static const int NUM_COMPONENTS = 4; + static const vtkm::IdComponent NUM_COMPONENTS = 4; VTKM_EXEC_CONT_EXPORT Tuple() {} VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) @@ -761,11 +802,13 @@ public: return *this; } - VTKM_EXEC_CONT_EXPORT const ComponentType &operator[](int idx) const + VTKM_EXEC_CONT_EXPORT + const ComponentType &operator[](vtkm::IdComponent idx) const { return this->Components[idx]; } - VTKM_EXEC_CONT_EXPORT ComponentType &operator[](int idx) + VTKM_EXEC_CONT_EXPORT + ComponentType &operator[](vtkm::IdComponent idx) { return this->Components[idx]; } @@ -834,12 +877,12 @@ VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z) return vtkm::Id3(x, y, z); } -template +template VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Tuple &a, const vtkm::Tuple &b) { T result = a[0]*b[0]; - for (int componentIndex = 1; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 1; componentIndex < Size; componentIndex++) { result += a[componentIndex]*b[componentIndex]; } @@ -858,68 +901,74 @@ VTKM_EXEC_CONT_EXPORT vtkm::Scalar dot(vtkm::Scalar a, vtkm::Scalar b) } // End of namespace vtkm -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator+(const vtkm::Tuple &a, - const vtkm::Tuple &b) + const vtkm::Tuple &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) { result[componentIndex] = a[componentIndex] + b[componentIndex]; } return result; } -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator-(const vtkm::Tuple &a, - const vtkm::Tuple &b) + const vtkm::Tuple &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) { result[componentIndex] = a[componentIndex] - b[componentIndex]; } return result; } -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const vtkm::Tuple &a, - const vtkm::Tuple &b) + const vtkm::Tuple &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) { result[componentIndex] = a[componentIndex] * b[componentIndex]; } return result; } -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator/(const vtkm::Tuple &a, - const vtkm::Tuple &b) + const vtkm::Tuple &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) { result[componentIndex] = a[componentIndex] / b[componentIndex]; } return result; } -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const vtkm::Tuple &a, - const Tb &b) + const Tb &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) { result[componentIndex] = a[componentIndex] * b; } return result; } -template +template VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const Ta &a, - const vtkm::Tuple &b) + const vtkm::Tuple &b) { vtkm::Tuple result; - for (int componentIndex = 0; componentIndex < Size; componentIndex++) + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) { result[componentIndex] = a * b[componentIndex]; } diff --git a/vtkm/VectorTraits.h b/vtkm/VectorTraits.h index 1f893a68c..25bc6d79d 100644 --- a/vtkm/VectorTraits.h +++ b/vtkm/VectorTraits.h @@ -37,7 +37,7 @@ struct VectorTraitsTagSingleComponent { }; namespace internal { -template +template struct VectorTraitsMultipleComponentChooser { typedef VectorTraitsTagMultipleComponents Type; @@ -64,7 +64,7 @@ struct VectorTraits /// Number of components in the vector. /// - static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS; + static const vtkm::IdComponent NUM_COMPONENTS = VectorType::NUM_COMPONENTS; /// A tag specifying whether this vector has multiple components (i.e. is a /// "real" vector). This tag can be useful for creating specialized functions @@ -77,15 +77,15 @@ struct VectorTraits /// VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent( const typename boost::remove_const::type &vector, - int component); + vtkm::IdComponent component); VTKM_EXEC_CONT_EXPORT static ComponentType &GetComponent( typename boost::remove_const::type &vector, - int component); + vtkm::IdComponent component); /// Changes the value in a given component of the vector. /// VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector, - int component, + vtkm::IdComponent component, ComponentType value); /// Converts whatever type this vector is into the standard VTKm Tuple. @@ -105,7 +105,7 @@ template struct VectorTraits : VectorTraits { }; -template +template struct VectorTraits > { typedef vtkm::Tuple VectorType; @@ -116,7 +116,7 @@ struct VectorTraits > /// Number of components in the vector. /// - static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS; + static const vtkm::IdComponent NUM_COMPONENTS = VectorType::NUM_COMPONENTS; /// A tag specifying whether this vector has multiple components (i.e. is a /// "real" vector). This tag can be useful for creating specialized functions @@ -129,19 +129,19 @@ struct VectorTraits > /// VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(const VectorType &vector, - int component) + vtkm::IdComponent component) { return vector[component]; } VTKM_EXEC_CONT_EXPORT - static ComponentType &GetComponent(VectorType &vector, int component) { + static ComponentType &GetComponent(VectorType &vector, vtkm::IdComponent component) { return vector[component]; } /// Changes the value in a given component of the vector. /// VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector, - int component, + vtkm::IdComponent component, ComponentType value) { vector[component] = value; } @@ -162,21 +162,21 @@ namespace internal { template struct VectorTraitsBasic { typedef ScalarType ComponentType; - static const int NUM_COMPONENTS = 1; + static const vtkm::IdComponent NUM_COMPONENTS = 1; typedef VectorTraitsTagSingleComponent HasMultipleComponents; VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent( const ScalarType &vector, - int) { + vtkm::IdComponent) { return vector; } VTKM_EXEC_CONT_EXPORT - static ComponentType &GetComponent(ScalarType &vector, int) { + static ComponentType &GetComponent(ScalarType &vector, vtkm::IdComponent) { return vector; } VTKM_EXEC_CONT_EXPORT static void SetComponent(ScalarType &vector, - int, + vtkm::IdComponent, ComponentType value) { vector = value; } diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index 7c43fed24..e48c497e0 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -40,9 +40,9 @@ namespace detail { template struct CompositeVectorSwizzleFunctor { - static const int NUM_COMPONENTS = + static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VectorTraits::NUM_COMPONENTS; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Tuple ComponentMapType; // Caution! This is a reference. const ComponentMapType &SourceComponents; @@ -166,11 +166,11 @@ template class ArrayPortalCompositeVector { typedef vtkm::internal::FunctionInterface PortalTypes; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Tuple ComponentMapType; public: typedef typename PortalTypes::ResultType ValueType; - static const int NUM_COMPONENTS = + static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VectorTraits::NUM_COMPONENTS; BOOST_STATIC_ASSERT(NUM_COMPONENTS == PortalTypes::ARITY); @@ -181,7 +181,7 @@ public: VTKM_CONT_EXPORT ArrayPortalCompositeVector( const PortalTypes portals, - vtkm::Tuple sourceComponents) + vtkm::Tuple sourceComponents) : Portals(portals), SourceComponents(sourceComponents) { } VTKM_EXEC_EXPORT @@ -221,9 +221,9 @@ class ArrayPortalCompositeVectorCont public: typedef typename FunctionInterfaceArrays::ResultType ValueType; - static const int NUM_COMPONENTS = + static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VectorTraits::NUM_COMPONENTS; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Tuple ComponentMapType; // If you get a compile error here, it means you probably tried to create // an ArrayHandleCompositeVector with a return type of a vector with a @@ -283,8 +283,8 @@ class Storage< { typedef vtkm::internal::FunctionInterface FunctionInterfaceWithArrays; - static const int NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY; - typedef vtkm::Tuple ComponentMapType; + static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY; + typedef vtkm::Tuple ComponentMapType; public: typedef ArrayPortalCompositeVectorCont PortalType; @@ -529,7 +529,7 @@ public: template VTKM_CONT_EXPORT ArrayHandleCompositeVector(const ArrayHandleType1 &array1, - int sourceComponent1) + vtkm::IdComponent sourceComponent1) : Superclass(StorageType( vtkm::internal::make_FunctionInterface(array1), ComponentMapType(sourceComponent1))) @@ -538,9 +538,9 @@ public: typename ArrayHandleType2> VTKM_CONT_EXPORT ArrayHandleCompositeVector(const ArrayHandleType1 &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const ArrayHandleType2 &array2, - int sourceComponent2) + vtkm::IdComponent sourceComponent2) : Superclass(StorageType( vtkm::internal::make_FunctionInterface( array1, array2), @@ -552,11 +552,11 @@ public: typename ArrayHandleType3> VTKM_CONT_EXPORT ArrayHandleCompositeVector(const ArrayHandleType1 &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const ArrayHandleType2 &array2, - int sourceComponent2, + vtkm::IdComponent sourceComponent2, const ArrayHandleType3 &array3, - int sourceComponent3) + vtkm::IdComponent sourceComponent3) : Superclass(StorageType( vtkm::internal::make_FunctionInterface( array1, array2, array3), @@ -570,13 +570,13 @@ public: typename ArrayHandleType4> VTKM_CONT_EXPORT ArrayHandleCompositeVector(const ArrayHandleType1 &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const ArrayHandleType2 &array2, - int sourceComponent2, + vtkm::IdComponent sourceComponent2, const ArrayHandleType3 &array3, - int sourceComponent3, + vtkm::IdComponent sourceComponent3, const ArrayHandleType4 &array4, - int sourceComponent4) + vtkm::IdComponent sourceComponent4) : Superclass(StorageType( vtkm::internal::make_FunctionInterface( array1, array2, array3, array4), @@ -662,7 +662,7 @@ typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle >::type make_ArrayHandleCompositeVector( const vtkm::cont::ArrayHandle &array1, - int sourceComponent1) + vtkm::IdComponent sourceComponent1) { return typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle >::type(array1, @@ -676,9 +676,9 @@ typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle >::type make_ArrayHandleCompositeVector( const vtkm::cont::ArrayHandle &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const vtkm::cont::ArrayHandle &array2, - int sourceComponent2) + vtkm::IdComponent sourceComponent2) { return typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle, @@ -697,11 +697,11 @@ typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle >::type make_ArrayHandleCompositeVector( const vtkm::cont::ArrayHandle &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const vtkm::cont::ArrayHandle &array2, - int sourceComponent2, + vtkm::IdComponent sourceComponent2, const vtkm::cont::ArrayHandle &array3, - int sourceComponent3) + vtkm::IdComponent sourceComponent3) { return typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle, @@ -725,13 +725,13 @@ typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle >::type make_ArrayHandleCompositeVector( const vtkm::cont::ArrayHandle &array1, - int sourceComponent1, + vtkm::IdComponent sourceComponent1, const vtkm::cont::ArrayHandle &array2, - int sourceComponent2, + vtkm::IdComponent sourceComponent2, const vtkm::cont::ArrayHandle &array3, - int sourceComponent3, + vtkm::IdComponent sourceComponent3, const vtkm::cont::ArrayHandle &array4, - int sourceComponent4) + vtkm::IdComponent sourceComponent4) { return typename ArrayHandleCompositeVectorType< vtkm::cont::ArrayHandle, diff --git a/vtkm/cont/internal/DeviceAdapterAlgorithm.h b/vtkm/cont/internal/DeviceAdapterAlgorithm.h index 42930eb74..4a6f8fa05 100644 --- a/vtkm/cont/internal/DeviceAdapterAlgorithm.h +++ b/vtkm/cont/internal/DeviceAdapterAlgorithm.h @@ -361,8 +361,8 @@ public: } struct TimeStamp { - vtkm::internal::Int64Type Seconds; - vtkm::internal::Int64Type Microseconds; + vtkm::Int64 Seconds; + vtkm::Int64 Microseconds; }; TimeStamp StartTime; diff --git a/vtkm/cont/internal/IteratorFromArrayPortal.h b/vtkm/cont/internal/IteratorFromArrayPortal.h index 029b5c934..e24652751 100644 --- a/vtkm/cont/internal/IteratorFromArrayPortal.h +++ b/vtkm/cont/internal/IteratorFromArrayPortal.h @@ -97,7 +97,7 @@ public: VTKM_CONT_EXPORT detail::IteratorFromArrayPortalValue - operator[](int idx) const + operator[](vtkm::Id idx) const { return detail::IteratorFromArrayPortalValue(this->Portal, idx); diff --git a/vtkm/cont/testing/TestingDeviceAdapter.h b/vtkm/cont/testing/TestingDeviceAdapter.h index 466e5ad03..a43104d4a 100644 --- a/vtkm/cont/testing/TestingDeviceAdapter.h +++ b/vtkm/cont/testing/TestingDeviceAdapter.h @@ -64,9 +64,9 @@ struct SortLess VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b, vtkm::TypeTraitsVectorTag) const { - enum {SIZE = vtkm::VectorTraits::NUM_COMPONENTS}; + const vtkm::IdComponent SIZE = vtkm::VectorTraits::NUM_COMPONENTS; bool valid = true; - for(unsigned int i=0; i < SIZE && valid; ++i) + for(vtkm::IdComponent i=0; (i < SIZE) && valid; ++i) { valid = a[i] < b[i]; } @@ -92,9 +92,9 @@ struct SortGreater VTKM_EXEC_CONT_EXPORT bool compare(const T& a,const T& b, vtkm::TypeTraitsVectorTag) const { - enum {SIZE = vtkm::VectorTraits::NUM_COMPONENTS}; + const vtkm::IdComponent SIZE = vtkm::VectorTraits::NUM_COMPONENTS; bool valid = true; - for(unsigned int i=0; i < SIZE && valid; ++i) + for(vtkm::IdComponent i=0; (i < SIZE) && valid; ++i) { valid = a[i] > b[i]; } @@ -1029,7 +1029,7 @@ private: //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) + for(vtkm::Id i=0, pos=1; i < ARRAY_SIZE; ++i, ++pos) { const vtkm::Id value = array.GetPortalConstControl().Get(i); partialSum += value; @@ -1062,7 +1062,7 @@ private: //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) + for(vtkm::Id i=0, pos=0; i < ARRAY_SIZE; ++i, ++pos) { const vtkm::Id value = array.GetPortalConstControl().Get(i); partialSum += value; diff --git a/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx b/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx index 88a95899c..4de4a01d4 100644 --- a/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx +++ b/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx @@ -40,7 +40,9 @@ const vtkm::Id ARRAY_SIZE = 10; typedef vtkm::cont::StorageTagBasic StorageTag; -vtkm::Scalar TestValue(vtkm::Id index, int inComponentIndex, int inArrayId) +vtkm::Scalar TestValue(vtkm::Id index, + vtkm::IdComponent inComponentIndex, + int inArrayId) { return index + vtkm::Scalar(0.1)*inComponentIndex + vtkm::Scalar(0.01)*inArrayId; } @@ -55,7 +57,7 @@ MakeInputArray(int arrayId) ValueType buffer[ARRAY_SIZE]; for (vtkm::Id index = 0; index < ARRAY_SIZE; index++) { - for (int componentIndex = 0; + for (vtkm::IdComponent componentIndex = 0; componentIndex < VTraits::NUM_COMPONENTS; componentIndex++) { @@ -82,7 +84,7 @@ MakeInputArray(int arrayId) template void CheckArray(const vtkm::cont::ArrayHandle &outArray, - const int *inComponents, + const vtkm::IdComponent *inComponents, const int *inArrayIds) { // ArrayHandleCompositeVector currently does not implement the ability to @@ -98,7 +100,7 @@ void CheckArray(const vtkm::cont::ArrayHandle &outArray, for (vtkm::Id index = 0; index < ARRAY_SIZE; index++) { ValueType retreivedValue = portal.Get(index); - for (int componentIndex = 0; + for (vtkm::IdComponent componentIndex = 0; componentIndex < VTraits::NUM_COMPONENTS; componentIndex++) { @@ -113,7 +115,7 @@ void CheckArray(const vtkm::cont::ArrayHandle &outArray, } } -template +template void TryScalarArray() { std::cout << "Creating a scalar array from one of " @@ -126,7 +128,7 @@ void TryScalarArray() typedef typename vtkm::cont::ArrayHandleCompositeVectorType::type OutArrayType; - for (int inComponentIndex = 0; + for (vtkm::IdComponent inComponentIndex = 0; inComponentIndex < inComponents; inComponentIndex++) { @@ -143,7 +145,7 @@ void TryVector4(vtkm::cont::ArrayHandle array1, vtkm::cont::ArrayHandle array4) { int arrayIds[4] = {0, 1, 2, 3}; - int inComponents[4]; + vtkm::IdComponent inComponents[4]; for (inComponents[0] = 0; inComponents[0] < vtkm::VectorTraits::NUM_COMPONENTS; @@ -181,7 +183,7 @@ void TryVector3(vtkm::cont::ArrayHandle array1, vtkm::cont::ArrayHandle array3) { int arrayIds[3] = {0, 1, 2}; - int inComponents[3]; + vtkm::IdComponent inComponents[3]; for (inComponents[0] = 0; inComponents[0] < vtkm::VectorTraits::NUM_COMPONENTS; @@ -217,7 +219,7 @@ void TryVector2(vtkm::cont::ArrayHandle array1, vtkm::cont::ArrayHandle array2) { int arrayIds[2] = {0, 1}; - int inComponents[2]; + vtkm::IdComponent inComponents[2]; for (inComponents[0] = 0; inComponents[0] < vtkm::VectorTraits::NUM_COMPONENTS; @@ -246,7 +248,7 @@ template void TryVector1(vtkm::cont::ArrayHandle array1) { int arrayIds[1] = {0}; - int inComponents[1]; + vtkm::IdComponent inComponents[1]; for (inComponents[0] = 0; inComponents[0] < vtkm::VectorTraits::NUM_COMPONENTS; diff --git a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx index e87609083..4642d97f9 100644 --- a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx @@ -43,10 +43,10 @@ vtkm::Scalar TestValue(vtkm::Id index, vtkm::Scalar) { return static_cast(index)/100; } -template +template vtkm::Tuple TestValue(vtkm::Id index, vtkm::Tuple) { vtkm::Tuple value; - for (int i = 0; i < N; i++) + for (vtkm::IdComponent i = 0; i < N; i++) { value[i] = TestValue(index, T()) + (i + 1); } diff --git a/vtkm/cont/testing/UnitTestStorageListTag.cxx b/vtkm/cont/testing/UnitTestStorageListTag.cxx index f58eae855..1def83894 100644 --- a/vtkm/cont/testing/UnitTestStorageListTag.cxx +++ b/vtkm/cont/testing/UnitTestStorageListTag.cxx @@ -43,21 +43,21 @@ struct TestFunctor } }; -template +template void CheckSame(const vtkm::Tuple &expected, const std::vector &found) { - VTKM_TEST_ASSERT(static_cast(found.size()) == N, + VTKM_TEST_ASSERT(static_cast(found.size()) == N, "Got wrong number of items."); - for (int index = 0; index < N; index++) + for (vtkm::IdComponent index = 0; index < N; index++) { VTKM_TEST_ASSERT(expected[index] == found[index], "Got wrong type."); } } -template +template void TryList(const vtkm::Tuple &expected, ListTag) { TestFunctor functor; diff --git a/vtkm/internal/Configure.h.in b/vtkm/internal/Configure.h.in index fd5e78789..605a986c1 100644 --- a/vtkm/internal/Configure.h.in +++ b/vtkm/internal/Configure.h.in @@ -39,6 +39,8 @@ #define VTKM_SIZE_FLOAT @VTKm_SIZE_FLOAT@ #define VTKM_SIZE_DOUBLE @VTKm_SIZE_DOUBLE@ +#define VTKM_SIZE_CHAR @VTKm_SIZE_CHAR@ +#define VTKM_SIZE_SHORT @VTKm_SIZE_SHORT@ #define VTKM_SIZE_INT @VTKm_SIZE_INT@ #define VTKM_SIZE_LONG @VTKm_SIZE_LONG@ #define VTKM_SIZE_LONG_LONG @VTKm_SIZE_LONG_LONG@ diff --git a/vtkm/internal/FunctionInterface.h b/vtkm/internal/FunctionInterface.h index d68eedfdc..268becab3 100644 --- a/vtkm/internal/FunctionInterface.h +++ b/vtkm/internal/FunctionInterface.h @@ -56,14 +56,14 @@ struct IdentityFunctor { }; -template +template VTKM_EXEC_CONT_EXPORT typename ParameterContainerAccess::ParameterType GetParameter(const ParameterContainer ¶meters) { return ParameterContainerAccess::GetParameter(parameters); } -template +template VTKM_EXEC_CONT_EXPORT void SetParameter(ParameterContainer ¶meters, const typename ParameterContainerAccess::ParameterType &value) { @@ -72,7 +72,7 @@ void SetParameter(ParameterContainer ¶meters, // These functions exist to help copy components of a FunctionInterface. -template +template struct FunctionInterfaceCopyParameters { template static @@ -86,7 +86,7 @@ struct FunctionInterfaceCopyParameters { } }; -template +template struct FunctionInterfaceCopyParameters<0, ParameterIndex> { template static @@ -151,7 +151,7 @@ class FunctionInterfaceDynamicTransformContContinue; /// a template parameter. /// /// \code{.cpp} -/// vtkm::internal::FunctionInterface functionInterface = +/// vtkm::internal::FunctionInterface functionInterface = /// vtkm::internal::make_FunctionInterface(1, 2.5, 'a'); /// \endcode /// @@ -258,7 +258,7 @@ public: typedef typename boost::function_types::result_type::type ResultType; - template + template struct ParameterType { typedef typename boost::mpl::at_c< boost::function_types::components, @@ -268,13 +268,13 @@ public: /// The number of parameters in this \c Function Interface. /// - static const int ARITY = SignatureArity::value; + static const vtkm::IdComponent ARITY = SignatureArity::value; /// Returns the number of parameters held in this \c FunctionInterface. The /// return value is the same as \c ARITY. /// VTKM_EXEC_CONT_EXPORT - int GetArity() const { return ARITY; } + vtkm::IdComponent GetArity() const { return ARITY; } /// Retrieves the return value from the last invocation called. This method /// will result in a compiler error if used with a function having a void @@ -315,7 +315,7 @@ public: /// } /// \endcode /// - template + template VTKM_EXEC_CONT_EXPORT typename ParameterType::type GetParameter() const { @@ -328,7 +328,7 @@ public: /// template (which is almost always the case), then you will have to use the /// template keyword. /// - template + template VTKM_EXEC_CONT_EXPORT void SetParameter(typename ParameterType::type parameter) { @@ -447,7 +447,7 @@ public: return appendedFuncInterface; } - template + template class ReplaceType { typedef boost::function_types::components ThisFunctionComponents; typedef typename boost::mpl::advance_c::type, ParameterIndex>::type ToRemovePos; @@ -466,7 +466,7 @@ public: /// changes. The return type can be determined with the \c ReplaceType /// template. /// - template + template VTKM_EXEC_CONT_EXPORT typename ReplaceType::type Replace(NewType newParameter) const { diff --git a/vtkm/testing/Testing.h b/vtkm/testing/Testing.h index 6a58cb0c4..5c6bc8117 100644 --- a/vtkm/testing/Testing.h +++ b/vtkm/testing/Testing.h @@ -304,7 +304,9 @@ bool test_equal(VectorType vector1, vtkm::Scalar tolerance = 0.0001) { typedef typename vtkm::VectorTraits Traits; - for (int component = 0; component < Traits::NUM_COMPONENTS; component++) + for (vtkm::IdComponent component = 0; + component < Traits::NUM_COMPONENTS; + component++) { vtkm::Scalar value1 = vtkm::Scalar(Traits::GetComponent(vector1, component)); vtkm::Scalar value2 = vtkm::Scalar(Traits::GetComponent(vector2, component)); @@ -340,12 +342,12 @@ bool test_equal(const std::string &string1, const std::string &string2) /// Helper function for printing out vectors during testing. /// -template +template VTKM_EXEC_CONT_EXPORT std::ostream &operator<<(std::ostream &stream, const vtkm::Tuple &tuple) { stream << "["; - for (int component = 0; component < Size-1; component++) + for (vtkm::IdComponent component = 0; component < Size-1; component++) { stream << tuple[component] << ","; } diff --git a/vtkm/testing/UnitTestExtent.cxx b/vtkm/testing/UnitTestExtent.cxx index a1f834a25..21a25a9bd 100644 --- a/vtkm/testing/UnitTestExtent.cxx +++ b/vtkm/testing/UnitTestExtent.cxx @@ -24,14 +24,14 @@ namespace { -const int MIN_VALUES[] = { -5, 8, 40, -8, -3 }; -const int MAX_VALUES[] = { 10, 25, 44, -2, 1 }; -const int POINT_DIMS[] = { 16, 18, 5, 7, 5 }; -const int CELL_DIMS[] = { 15, 17, 4, 6, 4 }; -const int NUM_POINTS[] = { 0, 16, 288, 1440, 10080, 50400 }; -const int NUM_CELLS[] = { 0, 15, 255, 1020, 6120, 24480 }; +const vtkm::Id MIN_VALUES[] = { -5, 8, 40, -8, -3 }; +const vtkm::Id MAX_VALUES[] = { 10, 25, 44, -2, 1 }; +const vtkm::Id POINT_DIMS[] = { 16, 18, 5, 7, 5 }; +const vtkm::Id CELL_DIMS[] = { 15, 17, 4, 6, 4 }; +const vtkm::Id NUM_POINTS[] = { 0, 16, 288, 1440, 10080, 50400 }; +const vtkm::Id NUM_CELLS[] = { 0, 15, 255, 1020, 6120, 24480 }; -template +template void TestDimensions(vtkm::Extent) { std::cout << "Testing Dimension sizes for " << Dimensions << " dimensions" @@ -43,13 +43,13 @@ void TestDimensions(vtkm::Extent) vtkm::Id numPoints; vtkm::Id numCells; - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { extent.Min[dimIndex] = 0; extent.Max[dimIndex] = 10; } pointDims = vtkm::ExtentPointDimensions(extent); cellDims = vtkm::ExtentCellDimensions(extent); - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { VTKM_TEST_ASSERT(pointDims[dimIndex] == 11, "Got incorrect point dimensions for extent."); @@ -57,14 +57,14 @@ void TestDimensions(vtkm::Extent) "Got incorrect point dimensions for extent."); } - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { extent.Min[dimIndex] = MIN_VALUES[dimIndex]; extent.Max[dimIndex] = MAX_VALUES[dimIndex]; } pointDims = vtkm::ExtentPointDimensions(extent); cellDims = vtkm::ExtentCellDimensions(extent); - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { VTKM_TEST_ASSERT(pointDims[dimIndex] == POINT_DIMS[dimIndex], "Got incorrect point dimensions for extent."); @@ -79,7 +79,7 @@ void TestDimensions(vtkm::Extent) "Got wrong number of cells."); } -template +template void TryIndexConversion(const vtkm::Extent &extent) { typedef vtkm::Tuple IdX; @@ -94,7 +94,7 @@ void TryIndexConversion(const vtkm::Extent &extent) correctFlatIndex++) { // Increment topology index - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { correctTopologyIndex[dimIndex]++; if (correctTopologyIndex[dimIndex] <= extent.Max[dimIndex]) { break; } @@ -124,7 +124,7 @@ void TryIndexConversion(const vtkm::Extent &extent) correctFlatIndex++) { // Increment topology index - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { correctTopologyIndex[dimIndex]++; if (correctTopologyIndex[dimIndex] < extent.Max[dimIndex]) { break; } @@ -154,7 +154,7 @@ void TryIndexConversion(const vtkm::Extent &extent) "Test code error. Indexing problem."); } -template +template void TestIndexConversion(vtkm::Extent) { std::cout << "Testing index conversion for " << Dimensions << " dimensions." @@ -162,13 +162,13 @@ void TestIndexConversion(vtkm::Extent) vtkm::Extent extent; - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { extent.Min[dimIndex] = 0; extent.Max[dimIndex] = 10; } TryIndexConversion(extent); - for (int dimIndex = 0; dimIndex < Dimensions; dimIndex++) + for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions; dimIndex++) { extent.Min[dimIndex] = MIN_VALUES[dimIndex]; extent.Max[dimIndex] = MAX_VALUES[dimIndex]; diff --git a/vtkm/testing/UnitTestListTag.cxx b/vtkm/testing/UnitTestListTag.cxx index d0d9ea1fe..5264745e4 100644 --- a/vtkm/testing/UnitTestListTag.cxx +++ b/vtkm/testing/UnitTestListTag.cxx @@ -80,21 +80,21 @@ struct ConstantFunctor } }; -template +template void CheckSame(const vtkm::Tuple &expected, const std::vector &found) { VTKM_TEST_ASSERT(static_cast(found.size()) == N, "Got wrong number of items."); - for (int index = 0; index < N; index++) + for (vtkm::IdComponent index = 0; index < N; index++) { VTKM_TEST_ASSERT(expected[index] == found[index], "Got wrong type."); } } -template +template void TryList(const vtkm::Tuple &expected, ListTag) { std::cout << " Try mutable for each" << std::endl; diff --git a/vtkm/testing/UnitTestTypeListTag.cxx b/vtkm/testing/UnitTestTypeListTag.cxx index a925d0e88..122f75f13 100644 --- a/vtkm/testing/UnitTestTypeListTag.cxx +++ b/vtkm/testing/UnitTestTypeListTag.cxx @@ -57,21 +57,21 @@ struct TestFunctor } }; -template +template void CheckSame(const vtkm::Tuple &expected, const std::vector &found) { - VTKM_TEST_ASSERT(static_cast(found.size()) == N, + VTKM_TEST_ASSERT(static_cast(found.size()) == N, "Got wrong number of items."); - for (int index = 0; index < N; index++) + for (vtkm::IdComponent index = 0; index < N; index++) { VTKM_TEST_ASSERT(expected[index] == found[index], "Got wrong type."); } } -template +template void TryList(const vtkm::Tuple &expected, ListTag) { TestFunctor functor; diff --git a/vtkm/testing/UnitTestTypes.cxx b/vtkm/testing/UnitTestTypes.cxx index 0f62264b7..8f8214812 100644 --- a/vtkm/testing/UnitTestTypes.cxx +++ b/vtkm/testing/UnitTestTypes.cxx @@ -44,6 +44,20 @@ namespace { +void CheckTypeSizes() +{ + VTKM_TEST_ASSERT(sizeof(vtkm::Int8) == 1, "Int8 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::UInt8) == 1, "UInt8 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::Int16) == 2, "Int16 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::UInt16) == 2, "UInt16 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::Int32) == 4, "Int32 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::UInt32) == 4, "UInt32 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::Int64) == 8, "Int64 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::UInt64) == 8, "UInt64 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::Float32) == 4, "Float32 wrong size."); + VTKM_TEST_ASSERT(sizeof(vtkm::Float64) == 8, "Float32 wrong size."); +} + //general type test template void TypeTest() { @@ -51,7 +65,7 @@ template void TypeTest() T a, b, c; typename T::ComponentType s(5); - for(int i=0; i < T::NUM_COMPONENTS; ++i) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++i) { a[i]=typename T::ComponentType((i+1)*2); b[i]=typename T::ComponentType(i+1); @@ -69,31 +83,31 @@ template void TypeTest() T plus = a + b; T correct_plus; - for(int i=0; i < T::NUM_COMPONENTS; ++i) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++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) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++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) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++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) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++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) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++i) { correct_mult[i] = s * a[i]; } VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Scalar and Tuple did not multiply correctly."); @@ -104,7 +118,7 @@ template void TypeTest() typename T::ComponentType d = vtkm::dot(a, b); typename T::ComponentType correct_d = 0; - for(int i=0; i < T::NUM_COMPONENTS; ++i) + for(vtkm::IdComponent i=0; i < T::NUM_COMPONENTS; ++i) {correct_d += a[i] * b[i]; } VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong"); @@ -478,6 +492,8 @@ struct TypeTestFunctor void TestTypes() { + CheckTypeSizes(); + vtkm::testing::Testing::TryAllTypes(TypeTestFunctor()); //try with some custom tuple types diff --git a/vtkm/testing/UnitTestVectorTraits.cxx b/vtkm/testing/UnitTestVectorTraits.cxx index ec5ac02f5..bbcd626f0 100644 --- a/vtkm/testing/UnitTestVectorTraits.cxx +++ b/vtkm/testing/UnitTestVectorTraits.cxx @@ -35,7 +35,7 @@ struct TestVectorTypeFunctor VTKM_TEST_ASSERT(Traits::NUM_COMPONENTS <= MAX_VECTOR_SIZE, "Need to update test for larger vectors."); T vector; - for (int index = 0; index < Traits::NUM_COMPONENTS; index++) + for (vtkm::IdComponent index = 0; index < Traits::NUM_COMPONENTS; index++) { Traits::SetComponent(vector, index, ComponentType(VectorInit[index])); }