From 2139d93206ce02ed186ef193e64a13c6bb239e1a Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 7 Oct 2014 17:17:03 -0600 Subject: [PATCH] Change vtkm::Tuple to vtkm::Vec There are multiple reasons for this name change: * The name Tuple conflicts with the boost::Tuple class, which as a different interface and feature set. This gets confusing, especially since VTK-m uses boost quite a bit. * The use of this class is usually (although not always) as a mathematical vector. * The vtkm::Scalar and vtkm::Vector* classes are going to go away soon to better support multiple base data type widths. Having this abbriviated name will hopefully make the code a bit nicer when these types have to be explicitly specified. Also modified the implementation a bit to consolidate some of the code. --- vtkm/Extent.h | 42 +- vtkm/TypeTraits.h | 2 +- vtkm/Types.h | 1108 +++++++++++------ vtkm/VectorTraits.h | 47 +- vtkm/cont/ArrayHandleCompositeVector.h | 16 +- .../UnitTestArrayHandleCompositeVector.cxx | 2 +- .../testing/UnitTestDynamicArrayHandle.cxx | 4 +- vtkm/cont/testing/UnitTestStorageListTag.cxx | 6 +- vtkm/testing/Testing.h | 6 +- vtkm/testing/UnitTestExtent.cxx | 6 +- vtkm/testing/UnitTestListTag.cxx | 16 +- vtkm/testing/UnitTestTypeListTag.cxx | 26 +- vtkm/testing/UnitTestTypeTraits.cxx | 4 +- vtkm/testing/UnitTestTypes.cxx | 10 +- vtkm/testing/UnitTestVectorTraits.cxx | 4 +- vtkm/testing/VectorTraitsTests.h | 10 +- 16 files changed, 793 insertions(+), 516 deletions(-) diff --git a/vtkm/Extent.h b/vtkm/Extent.h index b4d7687a6..3c712adbb 100644 --- a/vtkm/Extent.h +++ b/vtkm/Extent.h @@ -30,15 +30,15 @@ namespace vtkm { template struct Extent { - vtkm::Tuple Min; - vtkm::Tuple Max; + vtkm::Vec Min; + vtkm::Vec Max; VTKM_EXEC_CONT_EXPORT Extent() : Min(0), Max(0) { } VTKM_EXEC_CONT_EXPORT - Extent(const vtkm::Tuple &min, - const vtkm::Tuple &max) + Extent(const vtkm::Vec &min, + const vtkm::Vec &max) : Min(min), Max(max) { } VTKM_EXEC_CONT_EXPORT @@ -68,10 +68,10 @@ typedef vtkm::Extent<2> Extent2; /// template VTKM_EXEC_CONT_EXPORT -vtkm::Tuple +vtkm::Vec ExtentPointDimensions(const vtkm::Extent &extent) { - return extent.Max - extent.Min + vtkm::Tuple(1); + return extent.Max - extent.Min + vtkm::Vec(1); } VTKM_EXEC_CONT_EXPORT @@ -95,7 +95,7 @@ vtkm::Id2 ExtentPointDimensions(const vtkm::Extent2 &extent) /// template VTKM_EXEC_CONT_EXPORT -vtkm::Tuple +vtkm::Vec ExtentCellDimensions(const vtkm::Extent &extent) { return extent.Max - extent.Min; @@ -107,7 +107,7 @@ template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentNumberOfPoints(const vtkm::Extent &extent) { - return internal::product_vector()( + return internal::VecProduct()( vtkm::ExtentPointDimensions(extent)); } @@ -138,7 +138,7 @@ template VTKM_EXEC_CONT_EXPORT vtkm::Id ExtentNumberOfCells(const vtkm::Extent &extent) { - return internal::product_vector()( + return internal::VecProduct()( vtkm::ExtentCellDimensions(extent)); } @@ -170,13 +170,13 @@ vtkm::Id ExtentNumberOfCells(const vtkm::Extent2 &extent) /// template VTKM_EXEC_CONT_EXPORT -vtkm::Tuple +vtkm::Vec ExtentPointFlatIndexToTopologyIndex(vtkm::Id index, const vtkm::Extent &extent) { - const vtkm::Tuple dims = + const vtkm::Vec dims = vtkm::ExtentPointDimensions(extent); - vtkm::Tuple ijkIndex; + vtkm::Vec ijkIndex; vtkm::Id indexOnDim = index; for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) { @@ -218,13 +218,13 @@ vtkm::Id2 ExtentPointFlatIndexToTopologyIndex(vtkm::Id index, /// template VTKM_EXEC_CONT_EXPORT -vtkm::Tuple +vtkm::Vec ExtentCellFlatIndexToTopologyIndex(vtkm::Id index, const vtkm::Extent &extent) { - const vtkm::Tuple dims = + const vtkm::Vec dims = vtkm::ExtentCellDimensions(extent); - vtkm::Tuple ijkIndex; + vtkm::Vec ijkIndex; vtkm::Id indexOnDim = index; for (vtkm::IdComponent dimIndex = 0; dimIndex < Dimensions-1; dimIndex++) { @@ -267,11 +267,11 @@ vtkm::Id2 ExtentCellFlatIndexToTopologyIndex(vtkm::Id index, template VTKM_EXEC_CONT_EXPORT vtkm::Id -ExtentPointTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, +ExtentPointTopologyIndexToFlatIndex(const vtkm::Vec &ijk, const vtkm::Extent &extent) { - const vtkm::Tuple dims = ExtentPointDimensions(extent); - const vtkm::Tuple deltas = ijk - extent.Min; + const vtkm::Vec dims = ExtentPointDimensions(extent); + const vtkm::Vec deltas = ijk - extent.Min; vtkm::Id flatIndex = deltas[Dimensions-1]; for (vtkm::IdComponent dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) { @@ -288,11 +288,11 @@ ExtentPointTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, template VTKM_EXEC_CONT_EXPORT vtkm::Id -ExtentCellTopologyIndexToFlatIndex(const vtkm::Tuple &ijk, +ExtentCellTopologyIndexToFlatIndex(const vtkm::Vec &ijk, const vtkm::Extent &extent) { - const vtkm::Tuple dims = ExtentCellDimensions(extent); - const vtkm::Tuple deltas = ijk - extent.Min; + const vtkm::Vec dims = ExtentCellDimensions(extent); + const vtkm::Vec deltas = ijk - extent.Min; vtkm::Id flatIndex = deltas[Dimensions-1]; for (vtkm::IdComponent dimIndex = Dimensions-2; dimIndex >= 0; dimIndex--) { diff --git a/vtkm/TypeTraits.h b/vtkm/TypeTraits.h index 37c216817..069185cd8 100644 --- a/vtkm/TypeTraits.h +++ b/vtkm/TypeTraits.h @@ -137,7 +137,7 @@ VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag); /// Traits for tuples. /// template -struct TypeTraits > +struct TypeTraits > { typedef typename TypeTraits::NumericTag NumericTag; typedef TypeTraitsVectorTag DimensionalityTag; diff --git a/vtkm/Types.h b/vtkm/Types.h index ee1f9158a..7a49d18fa 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -171,17 +171,24 @@ namespace internal { //----------------------------------------------------------------------------- template -struct equals +struct VecEquals { template VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const { - return equals()(a,b) && a[Size-1] == b[Size-1]; + bool equal = true; + for (vtkm::IdComponent componentIndex = 0; + equal && (componentIndex < Size); + componentIndex++) + { + equal &= a[componentIndex] == b[componentIndex]; + } + return equal; } }; template<> -struct equals<1> +struct VecEquals<1> { template VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const @@ -191,39 +198,56 @@ struct equals<1> }; template<> -struct equals<2> +struct VecEquals<2> { template VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const { - return a[0] == b[0] && a[1] == b[1]; + return ((a[0] == b[0]) && (a[1] == b[1])); } }; template<> -struct equals<3> +struct VecEquals<3> { template VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const { - return a[0] == b[0] && a[1] == b[1] && a[2] == b[2]; + return ((a[0] == b[0]) && (a[1] == b[1]) && (a[2] == b[2])); + } +}; + +template<> +struct VecEquals<4> +{ + template + VTKM_EXEC_CONT_EXPORT bool operator()(const T& a, const T& b) const + { + return ((a[0] == b[0]) + && (a[1] == b[1]) + && (a[2] == b[2]) + && (a[3] == b[3])); } }; template -struct assign_scalar_to_vector +struct AssignScalarToVec { template VTKM_EXEC_CONT_EXPORT void operator()(VectorType &dest, const ComponentType &src) { - assign_scalar_to_vector()(dest, src); - dest[Size-1] = src; + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) + { + dest[componentIndex] = src; + } } }; template<> -struct assign_scalar_to_vector<1> +struct AssignScalarToVec<1> { template VTKM_EXEC_CONT_EXPORT @@ -234,7 +258,7 @@ struct assign_scalar_to_vector<1> }; template<> -struct assign_scalar_to_vector<2> +struct AssignScalarToVec<2> { template VTKM_EXEC_CONT_EXPORT @@ -246,7 +270,7 @@ struct assign_scalar_to_vector<2> }; template<> -struct assign_scalar_to_vector<3> +struct AssignScalarToVec<3> { template VTKM_EXEC_CONT_EXPORT @@ -258,19 +282,37 @@ struct assign_scalar_to_vector<3> } }; +template<> +struct AssignScalarToVec<4> +{ + template + VTKM_EXEC_CONT_EXPORT + void operator()(VectorType &dest, const ComponentType &src) + { + dest[0] = src; + dest[1] = src; + dest[2] = src; + dest[3] = src; + } +}; + template -struct copy_vector +struct VecCopy { template VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src) { - copy_vector()(dest, src); - dest[Size-1] = src[Size-1]; + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) + { + dest[componentIndex] = src[componentIndex]; + } } }; template<> -struct copy_vector<1> +struct VecCopy<1> { template VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src) @@ -280,7 +322,7 @@ struct copy_vector<1> }; template<> -struct copy_vector<2> +struct VecCopy<2> { template VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src) @@ -291,7 +333,7 @@ struct copy_vector<2> }; template<> -struct copy_vector<3> +struct VecCopy<3> { template VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src) @@ -302,19 +344,50 @@ struct copy_vector<3> } }; +template<> +struct VecCopy<4> +{ + template + VTKM_EXEC_CONT_EXPORT void operator()(T1 &dest, const T2 &src) + { + dest[0] = src[0]; + dest[1] = src[1]; + dest[2] = src[2]; + dest[3] = src[3]; + } +}; + template -struct sum_vector +struct VecSum { template VTKM_EXEC_CONT_EXPORT typename T::ComponentType operator()(const T &x) { - return sum_vector()(x) + x[Size-1]; + typename T::ComponentType sum = x[0]; + for (vtkm::IdComponent componentIndex = 1; + componentIndex < Size; + componentIndex++) + { + sum += x[componentIndex]; + } + return sum; } }; template<> -struct sum_vector<1> +struct VecSum<0> +{ + template + VTKM_EXEC_CONT_EXPORT + typename T::ComponentType operator()(const T &) + { + return T::ComponentType(0); + } +}; + +template<> +struct VecSum<1> { template VTKM_EXEC_CONT_EXPORT @@ -325,7 +398,7 @@ struct sum_vector<1> }; template<> -struct sum_vector<2> +struct VecSum<2> { template VTKM_EXEC_CONT_EXPORT @@ -336,7 +409,7 @@ struct sum_vector<2> }; template<> -struct sum_vector<3> +struct VecSum<3> { template VTKM_EXEC_CONT_EXPORT @@ -347,7 +420,7 @@ struct sum_vector<3> }; template<> -struct sum_vector<4> +struct VecSum<4> { template VTKM_EXEC_CONT_EXPORT @@ -358,18 +431,36 @@ struct sum_vector<4> }; template -struct product_vector +struct VecProduct { template VTKM_EXEC_CONT_EXPORT typename T::ComponentType operator()(const T &x) { - return product_vector()(x) * x[Size-1]; + typename T::ComponentType product = x[0]; + for (vtkm::IdComponent componentIndex = 1; + componentIndex < Size; + componentIndex++) + { + product *= x[componentIndex]; + } + return product; } }; template<> -struct product_vector<1> +struct VecProduct<0> +{ + template + VTKM_EXEC_CONT_EXPORT + typename T::ComponentType operator()(const T &) + { + return T::ComponentType(1); + } +}; + +template<> +struct VecProduct<1> { template VTKM_EXEC_CONT_EXPORT @@ -380,7 +471,7 @@ struct product_vector<1> }; template<> -struct product_vector<2> +struct VecProduct<2> { template VTKM_EXEC_CONT_EXPORT @@ -391,7 +482,7 @@ struct product_vector<2> }; template<> -struct product_vector<3> +struct VecProduct<3> { template VTKM_EXEC_CONT_EXPORT @@ -402,7 +493,7 @@ struct product_vector<3> }; template<> -struct product_vector<4> +struct VecProduct<4> { template VTKM_EXEC_CONT_EXPORT @@ -412,51 +503,248 @@ struct product_vector<4> } }; +template +struct VecComponentWiseBinaryOperation +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &a, const T &b, const BinaryOpType &binaryOp) const + { + T result; + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) + { + result[componentIndex] = binaryOp(a[componentIndex], b[componentIndex]); + } + return result; + } +}; + +template<> +struct VecComponentWiseBinaryOperation<1> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &a, const T &b, const BinaryOpType &binaryOp) const + { + return T(binaryOp(a[0], b[0])); + } +}; + +template<> +struct VecComponentWiseBinaryOperation<2> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &a, const T &b, const BinaryOpType &binaryOp) const + { + return T(binaryOp(a[0], b[0]), + binaryOp(a[1], b[1])); + } +}; + +template<> +struct VecComponentWiseBinaryOperation<3> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &a, const T &b, const BinaryOpType &binaryOp) const + { + return T(binaryOp(a[0], b[0]), + binaryOp(a[1], b[1]), + binaryOp(a[2], b[2])); + } +}; + +template<> +struct VecComponentWiseBinaryOperation<4> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &a, const T &b, const BinaryOpType &binaryOp) const + { + return T(binaryOp(a[0], b[0]), + binaryOp(a[1], b[1]), + binaryOp(a[2], b[2]), + binaryOp(a[3], b[3])); + } +}; + +template +struct VecComponentWiseUnaryOperation +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &v, const UnaryOpType &unaryOp) const + { + T result; + for (vtkm::IdComponent componentIndex = 0; + componentIndex < Size; + componentIndex++) + { + result[componentIndex] = unaryOp(v[componentIndex]); + } + return result; + } +}; + +template<> +struct VecComponentWiseUnaryOperation<1> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &v, const UnaryOpType &unaryOp) const + { + return T(unaryOp(v[0])); + } +}; + +template<> +struct VecComponentWiseUnaryOperation<2> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &v, const UnaryOpType &unaryOp) const + { + return T(unaryOp(v[0]), unaryOp(v[1])); + } +}; + +template<> +struct VecComponentWiseUnaryOperation<3> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &v, const UnaryOpType &unaryOp) const + { + return T(unaryOp(v[0]), unaryOp(v[1]), unaryOp(v[2])); + } +}; + +template<> +struct VecComponentWiseUnaryOperation<4> +{ + template + VTKM_EXEC_CONT_EXPORT + T operator()(const T &v, const UnaryOpType &unaryOp) const + { + return T(unaryOp(v[0]), unaryOp(v[1]), unaryOp(v[2]), unaryOp(v[3])); + } +}; + +template +struct BindLeftBinaryOp +{ + // Warning: a reference. + const T &LeftValue; + const BinaryOpType BinaryOp; + VTKM_EXEC_CONT_EXPORT + BindLeftBinaryOp(const T &leftValue, BinaryOpType binaryOp = BinaryOpType()) + : LeftValue(leftValue), BinaryOp(binaryOp) { } + VTKM_EXEC_CONT_EXPORT + T operator()(const T &rightValue) const + { + return this->BinaryOp(this->LeftValue, rightValue); + } +}; + +template +struct BindRightBinaryOp +{ + // Warning: a reference. + const T &RightValue; + const BinaryOpType BinaryOp; + VTKM_EXEC_CONT_EXPORT + BindRightBinaryOp(const T &rightValue, BinaryOpType binaryOp = BinaryOpType()) + : RightValue(rightValue), BinaryOp(binaryOp) { } + VTKM_EXEC_CONT_EXPORT + T operator()(const T &leftValue) const + { + return this->BinaryOp(leftValue, this->RightValue); + } +}; + +struct Add +{ + template + VTKM_EXEC_CONT_EXPORT T operator()(const T &a, const T &b) const + { + return a + b; + } +}; + +struct Subtract +{ + template + VTKM_EXEC_CONT_EXPORT T operator()(const T &a, const T &b) const + { + return a - b; + } +}; + +struct Multiply +{ + template + VTKM_EXEC_CONT_EXPORT T operator()(const T &a, const T &b) const + { + return a * b; + } +}; + +struct Divide +{ + template + VTKM_EXEC_CONT_EXPORT T operator()(const T &a, const T &b) const + { + return a / b; + } +}; } // namespace internal //----------------------------------------------------------------------------- -/// Tuple corresponds to a Size-tuple of type T -template -class Tuple +namespace detail { + +/// Base implementation of all Vec classes. +/// +template +class VecBase { public: typedef T ComponentType; static const vtkm::IdComponent NUM_COMPONENTS=Size; - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) - { - for(vtkm::IdComponent i=0; i < NUM_COMPONENTS; ++i) - { - this->Components[i]=value; - } - } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values) - { - for(vtkm::IdComponent i=0; i < NUM_COMPONENTS; ++i) - { - this->Components[i]=values[i]; - } - } +protected: VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &src) + VecBase() {} + + VTKM_EXEC_CONT_EXPORT + explicit VecBase(const ComponentType& value) { - for (vtkm::IdComponent i = 0; i < NUM_COMPONENTS; i++) - { - this->Components[i] = src[i]; - } + vtkm::internal::AssignScalarToVec()( + this->Components, value); } VTKM_EXEC_CONT_EXPORT - Tuple &operator=(const Tuple &src) + explicit VecBase(const ComponentType* values) { - for (vtkm::IdComponent i = 0; i < NUM_COMPONENTS; i++) - { - this->Components[i] = src[i]; - } - return *this; + vtkm::internal::VecCopy()(this->Components, values); + } + + VTKM_EXEC_CONT_EXPORT + VecBase(const DerivedClass &src) + { + vtkm::internal::VecCopy()(this->Components, src); + } + +public: + VTKM_EXEC_CONT_EXPORT + DerivedClass &operator=(const DerivedClass &src) + { + vtkm::internal::VecCopy()(this->Components, src); + return *reinterpret_cast(this); } VTKM_EXEC_CONT_EXPORT @@ -464,68 +752,245 @@ public: { return this->Components[idx]; } - VTKM_EXEC_CONT_EXPORT ComponentType &operator[](vtkm::IdComponent idx) + VTKM_EXEC_CONT_EXPORT + ComponentType &operator[](vtkm::IdComponent idx) { return this->Components[idx]; } VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &other) const + bool operator==(const DerivedClass &other) const { - bool same = true; - for (vtkm::IdComponent componentIndex = 0; - componentIndex < NUM_COMPONENTS; - componentIndex++) - { - same &= (this->Components[componentIndex] == other[componentIndex]); - } - return same; + return vtkm::internal::VecEquals()( + *reinterpret_cast(this), other); } VTKM_EXEC_CONT_EXPORT - bool operator<(const Tuple &other) const + bool operator<(const DerivedClass &other) const { - for(vtkm::Id i=0; i < NUM_COMPONENTS; ++i) + for(vtkm::IdComponent componentIndex = 0; + componentIndex < NUM_COMPONENTS; + ++componentIndex) { //ignore equals as that represents check next value - if(this->Components[i] < other[i]) - { return true; } - else if(other[i] < this->Components[i]) - { return false; } + if(this->Components[componentIndex] < other[componentIndex]) + { + return true; + } + else if(other[componentIndex] < this->Components[componentIndex]) + { + return false; + } } //if all same we are not less + return false; } VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &other) const + bool operator!=(const DerivedClass &other) const { return !(this->operator==(other)); } + VTKM_EXEC_CONT_EXPORT + ComponentType Dot(const DerivedClass &other) const + { + ComponentType result = this->Components[0]*other[0]; + for (vtkm::IdComponent componentIndex = 1; + componentIndex < Size; + componentIndex++) + { + result += this->Components[componentIndex]*other[componentIndex]; + } + return result; + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator+(const DerivedClass &other) const + { + return vtkm::internal::VecComponentWiseBinaryOperation()( + *reinterpret_cast(this), + other, + vtkm::internal::Add()); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator-(const DerivedClass &other) const + { + return vtkm::internal::VecComponentWiseBinaryOperation()( + *reinterpret_cast(this), + other, + vtkm::internal::Subtract()); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(const DerivedClass &other) const + { + return vtkm::internal::VecComponentWiseBinaryOperation()( + *reinterpret_cast(this), + other, + vtkm::internal::Multiply()); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Int8 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::UInt8 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Int16 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::UInt16 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Int32 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::UInt32 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Int64 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::UInt64 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Float32 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator*(vtkm::Float64 scalar) const + { + return vtkm::internal::VecComponentWiseUnaryOperation()( + *reinterpret_cast(this), + vtkm::internal::BindRightBinaryOp< + ComponentType,vtkm::internal::Multiply>(scalar)); + } + + VTKM_EXEC_CONT_EXPORT + DerivedClass operator/(const DerivedClass &other) const + { + return vtkm::internal::VecComponentWiseBinaryOperation()( + *reinterpret_cast(this), + other, + vtkm::internal::Divide()); + } + protected: ComponentType Components[NUM_COMPONENTS]; }; -//----------------------------------------------------------------------------- -// Specializations for small tuples. These are not exactly common but can occur -// with generalizations. We implement them a bit special. +} // namespace detail +//----------------------------------------------------------------------------- + +/// \brief A short fixed-length array. +/// +/// The \c Vec templated class holds a short array of values of a size and +/// type specified by the template arguments. +/// +/// The \c Vec class is most often used to represent vectors in the +/// mathematical sense as a quantity with a magnitude and direction. Vectors +/// are, of course, used extensively in computational geometry as well as +/// phyiscal simulations. The \c Vec class can be (and is) repurposed for more +/// general usage of holding a fixed-length sequence of objects. +/// +/// There is no real limit to the size of the sequence (other than the largest +/// number representable by vtkm::IdComponent), but the \c Vec class is really +/// designed for small sequences (seldom more than 10). +/// +template +class Vec : public detail::VecBase > +{ + typedef detail::VecBase > Superclass; +public: +#ifdef VTKM_DOXYGEN_ONLY + typedef T ComponentType; + static const vtkm::IdComponent NUM_COMPONENTS=Size; +#endif + + VTKM_EXEC_CONT_EXPORT Vec() {} + VTKM_EXEC_CONT_EXPORT explicit Vec(const T& value) : Superclass(value) { } + VTKM_EXEC_CONT_EXPORT explicit Vec(const T* values) : Superclass(values) { } + VTKM_EXEC_CONT_EXPORT Vec(const Vec &src) : Superclass(src) { } +}; + +//----------------------------------------------------------------------------- +// Specializations for common small tuples. We implement them a bit specially. + +// A vector of size 0 cannot use VecBase because it will try to create a +// zero length array which troubles compilers. Vecs of size 0 are a bit +// pointless but might occur in some generic functions or classes. template -class Tuple +class Vec { public: typedef T ComponentType; - static const vtkm::IdComponent NUM_COMPONENTS = 1; + static const vtkm::IdComponent NUM_COMPONENTS = 0; - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType&) { } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType*) { } - VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &) { } + VTKM_EXEC_CONT_EXPORT Vec() {} + VTKM_EXEC_CONT_EXPORT explicit Vec(const ComponentType&) { } + VTKM_EXEC_CONT_EXPORT explicit Vec(const ComponentType*) { } + VTKM_EXEC_CONT_EXPORT Vec(const Vec &) { } VTKM_EXEC_CONT_EXPORT - Tuple & - operator=(const Tuple &) + Vec & + operator=(const Vec &) { return *this; } @@ -537,314 +1002,95 @@ public: } VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &vtkmNotUsed(other)) const + bool operator==(const Vec &vtkmNotUsed(other)) const { return true; } VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &vtkmNotUsed(other)) const + bool operator!=(const Vec &vtkmNotUsed(other)) const { return false; } }; -template -class Tuple -{ -public: - typedef T ComponentType; - static const vtkm::IdComponent NUM_COMPONENTS = 1; - - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) - : Component(value) { } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values) - : Component(*values) { } - VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &src) - : Component(src.Component) { } - - VTKM_EXEC_CONT_EXPORT - Tuple & - operator=(const Tuple &src) - { - this->Component = src.Component; - return *this; - } - - VTKM_EXEC_CONT_EXPORT - const ComponentType &operator[](vtkm::IdComponent vtkmNotUsed(idx)) const - { - return this->Component; - } - VTKM_EXEC_CONT_EXPORT - ComponentType &operator[](vtkm::IdComponent vtkmNotUsed(idx)) - { - return this->Component; - } - - VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &other) const - { - return this->Component == other.Component; - } - VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &other) const - { - return !(this->operator==(other)); - } - - VTKM_EXEC_CONT_EXPORT - bool operator<(const Tuple &other) const - { - return this->Component < other.Component; - } - -protected: - ComponentType Component; -}; - //----------------------------------------------------------------------------- // Specializations for common tuple sizes (with special names). template -class Tuple +class Vec : public detail::VecBase > { -public: - typedef T ComponentType; - static const vtkm::IdComponent NUM_COMPONENTS = 2; + typedef detail::VecBase > Superclass; - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) - { - internal::assign_scalar_to_vector()(this->Components,value); - } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values) - { - internal::copy_vector()(this->Components, values); - } - VTKM_EXEC_CONT_EXPORT Tuple(ComponentType x, ComponentType y) +public: + VTKM_EXEC_CONT_EXPORT Vec() {} + VTKM_EXEC_CONT_EXPORT explicit Vec(const T& value) : Superclass(value) { } + VTKM_EXEC_CONT_EXPORT explicit Vec(const T* values) : Superclass(values) { } + VTKM_EXEC_CONT_EXPORT Vec(const Vec &src) : Superclass(src) { } + + VTKM_EXEC_CONT_EXPORT + Vec(const T &x, const T &y) { this->Components[0] = x; this->Components[1] = y; } - VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - } - - VTKM_EXEC_CONT_EXPORT - Tuple & - operator=(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - return *this; - } - - VTKM_EXEC_CONT_EXPORT - const ComponentType &operator[](vtkm::IdComponent idx) const - { - return this->Components[idx]; - } - VTKM_EXEC_CONT_EXPORT - ComponentType &operator[](vtkm::IdComponent idx) - { - return this->Components[idx]; - } - - VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &other) const - { - return internal::equals()(*this, other); - } - VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &other) const - { - return !(this->operator==(other)); - } - - VTKM_EXEC_CONT_EXPORT - bool operator<(const Tuple &other) const - { - return( (this->Components[0] < other[0]) || - (!(other[0] < this->Components[0]) && (this->Components[1] < other[1])) - ); - } - -protected: - ComponentType Components[NUM_COMPONENTS]; }; /// Vector2 corresponds to a 2-tuple -typedef vtkm::Tuple Vector2; - +typedef vtkm::Vec Vector2; /// Id2 corresponds to a 2-dimensional index -typedef vtkm::Tuple Id2; +typedef vtkm::Vec Id2; + template -class Tuple +class Vec : public detail::VecBase > { + typedef detail::VecBase > Superclass; public: - typedef T ComponentType; - static const vtkm::IdComponent NUM_COMPONENTS = 3; + VTKM_EXEC_CONT_EXPORT Vec() {} + VTKM_EXEC_CONT_EXPORT explicit Vec(const T& value) : Superclass(value) { } + VTKM_EXEC_CONT_EXPORT explicit Vec(const T* values) : Superclass(values) { } + VTKM_EXEC_CONT_EXPORT Vec(const Vec &src) : Superclass(src) { } - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) - { - internal::assign_scalar_to_vector()(this->Components,value); - } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values) - { - internal::copy_vector()(this->Components, values); - } VTKM_EXEC_CONT_EXPORT - Tuple(ComponentType x, ComponentType y, ComponentType z) + Vec(const T &x, const T &y, const T &z) { this->Components[0] = x; this->Components[1] = y; this->Components[2] = z; } - VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - } - - VTKM_EXEC_CONT_EXPORT - Tuple & - operator=(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - return *this; - } - - VTKM_EXEC_CONT_EXPORT - const ComponentType &operator[](vtkm::IdComponent idx) const - { - return this->Components[idx]; - } - VTKM_EXEC_CONT_EXPORT - ComponentType &operator[](vtkm::IdComponent idx) - { - return this->Components[idx]; - } - - VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &other) const - { - return internal::equals()(*this, other); - } - VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &other) const - { - return !(this->operator==(other)); - } - - VTKM_EXEC_CONT_EXPORT - bool operator<(const Tuple &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]) ) ); - } - -protected: - ComponentType Components[NUM_COMPONENTS]; }; /// Vector3 corresponds to a 3-tuple -typedef vtkm::Tuple Vector3; +typedef vtkm::Vec Vector3; /// Id3 corresponds to a 3-dimensional index for 3d arrays. Note that /// the precision of each index may be less than vtkm::Id. -typedef vtkm::Tuple Id3; +typedef vtkm::Vec Id3; + template -class Tuple +class Vec : public detail::VecBase > { + typedef detail::VecBase > Superclass; public: - typedef T ComponentType; - static const vtkm::IdComponent NUM_COMPONENTS = 4; + VTKM_EXEC_CONT_EXPORT Vec() {} + VTKM_EXEC_CONT_EXPORT explicit Vec(const T& value) : Superclass(value) { } + VTKM_EXEC_CONT_EXPORT explicit Vec(const T* values) : Superclass(values) { } + VTKM_EXEC_CONT_EXPORT Vec(const Vec &src) : Superclass(src) { } - VTKM_EXEC_CONT_EXPORT Tuple() {} - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType& value) - { - internal::assign_scalar_to_vector()(this->Components,value); - } - VTKM_EXEC_CONT_EXPORT explicit Tuple(const ComponentType* values) - { - internal::copy_vector()(this->Components, values); - } VTKM_EXEC_CONT_EXPORT - Tuple(ComponentType x, ComponentType y, ComponentType z, ComponentType w) + Vec(const T &x, const T &y, const T &z, const T &w) { this->Components[0] = x; this->Components[1] = y; this->Components[2] = z; this->Components[3] = w; } - VTKM_EXEC_CONT_EXPORT - Tuple(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - } - - VTKM_EXEC_CONT_EXPORT - Tuple & - operator=(const Tuple &src) - { - internal::copy_vector()(this->Components, src.Components); - return *this; - } - - VTKM_EXEC_CONT_EXPORT - const ComponentType &operator[](vtkm::IdComponent idx) const - { - return this->Components[idx]; - } - VTKM_EXEC_CONT_EXPORT - ComponentType &operator[](vtkm::IdComponent idx) - { - return this->Components[idx]; - } - - VTKM_EXEC_CONT_EXPORT - bool operator==(const Tuple &other) const - { - return internal::equals()(*this, other); - } - VTKM_EXEC_CONT_EXPORT - bool operator!=(const Tuple &other) const - { - return !(this->operator==(other)); - } - - VTKM_EXEC_CONT_EXPORT - bool operator<(const Tuple &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])) ); - } - -protected: - ComponentType Components[NUM_COMPONENTS]; }; /// Vector4 corresponds to a 4-tuple -typedef vtkm::Tuple Vector4; +typedef vtkm::Vec Vector4; /// Initializes and returns a Vector2. @@ -878,8 +1124,8 @@ VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z) } template -VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Tuple &a, - const vtkm::Tuple &b) +VTKM_EXEC_CONT_EXPORT +T dot(const vtkm::Vec &a, const vtkm::Vec &b) { T result = a[0]*b[0]; for (vtkm::IdComponent componentIndex = 1; componentIndex < Size; componentIndex++) @@ -889,90 +1135,128 @@ VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Tuple &a, return result; } -VTKM_EXEC_CONT_EXPORT vtkm::Id dot(vtkm::Id a, vtkm::Id b) +template +VTKM_EXEC_CONT_EXPORT +T dot(const vtkm::Vec &a, const vtkm::Vec &b) { - return a * b; + return (a[0]*b[0]) + (a[1]*b[1]); } -VTKM_EXEC_CONT_EXPORT vtkm::Scalar dot(vtkm::Scalar a, vtkm::Scalar b) +template +VTKM_EXEC_CONT_EXPORT +T dot(const vtkm::Vec &a, const vtkm::Vec &b) { - return a * b; + return (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]); } +template +VTKM_EXEC_CONT_EXPORT +T dot(const vtkm::Vec &a, const vtkm::Vec &b) +{ + return (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) + (a[3]*b[3]); +} + +#define VTK_M_SCALAR_DOT(type) \ + VTKM_EXEC_CONT_EXPORT type dot(type a, type b) { return a * b; } +VTK_M_SCALAR_DOT(vtkm::Int8) +VTK_M_SCALAR_DOT(vtkm::Int16) +VTK_M_SCALAR_DOT(vtkm::Int32) +VTK_M_SCALAR_DOT(vtkm::Int64) +VTK_M_SCALAR_DOT(vtkm::Float32) +VTK_M_SCALAR_DOT(vtkm::Float64) + } // End of namespace vtkm +// Declared outside of vtkm namespace so that the operator works with all code. + template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator+(const vtkm::Tuple &a, - const vtkm::Tuple &b) +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Int8 scalar, const vtkm::Vec &vec) { - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) - { - result[componentIndex] = a[componentIndex] + b[componentIndex]; - } - return result; -} -template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator-(const vtkm::Tuple &a, - const vtkm::Tuple &b) -{ - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) - { - result[componentIndex] = a[componentIndex] - b[componentIndex]; - } - return result; -} -template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const vtkm::Tuple &a, - const vtkm::Tuple &b) -{ - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; - componentIndex < Size; - componentIndex++) - { - result[componentIndex] = a[componentIndex] * b[componentIndex]; - } - return result; -} -template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator/(const vtkm::Tuple &a, - const vtkm::Tuple &b) -{ - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++) - { - result[componentIndex] = a[componentIndex] / b[componentIndex]; - } - return result; + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); } -template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const vtkm::Tuple &a, - const Tb &b) +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::UInt8 scalar, const vtkm::Vec &vec) { - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; - componentIndex < Size; - componentIndex++) - { - result[componentIndex] = a[componentIndex] * b; - } - return result; + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); } -template -VTKM_EXEC_CONT_EXPORT vtkm::Tuple operator*(const Ta &a, - const vtkm::Tuple &b) + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Int16 scalar, const vtkm::Vec &vec) { - vtkm::Tuple result; - for (vtkm::IdComponent componentIndex = 0; - componentIndex < Size; - componentIndex++) - { - result[componentIndex] = a * b[componentIndex]; - } - return result; + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::UInt16 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Int32 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::UInt32 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Int64 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::UInt64 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Float32 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); +} + +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec operator*(vtkm::Float64 scalar, const vtkm::Vec &vec) +{ + return vtkm::internal::VecComponentWiseUnaryOperation()( + vec, + vtkm::internal::BindLeftBinaryOp(scalar)); } #endif //vtk_m_Types_h diff --git a/vtkm/VectorTraits.h b/vtkm/VectorTraits.h index 25bc6d79d..8b2357c32 100644 --- a/vtkm/VectorTraits.h +++ b/vtkm/VectorTraits.h @@ -88,11 +88,11 @@ struct VectorTraits vtkm::IdComponent component, ComponentType value); - /// Converts whatever type this vector is into the standard VTKm Tuple. + /// Converts whatever type this vector is into the standard VTK-m Vec. /// VTKM_EXEC_CONT_EXPORT - static vtkm::Tuple - ToTuple(const VectorType &vector); + static vtkm::Vec + ToVec(const VectorType &vector); }; #else // VTKM_DOXYGEN_ONLY ; @@ -106,9 +106,9 @@ struct VectorTraits : VectorTraits { }; template -struct VectorTraits > +struct VectorTraits > { - typedef vtkm::Tuple VectorType; + typedef vtkm::Vec VectorType; /// Type of the components in the vector. /// @@ -149,8 +149,8 @@ struct VectorTraits > /// Converts whatever type this vector is into the standard VTKm Tuple. /// VTKM_EXEC_CONT_EXPORT - static vtkm::Tuple - ToTuple(const VectorType &vector) + static vtkm::Vec + ToVec(const VectorType &vector) { return vector; } @@ -182,9 +182,9 @@ struct VectorTraitsBasic { } VTKM_EXEC_CONT_EXPORT - static vtkm::Tuple ToTuple(const ScalarType &vector) + static vtkm::Vec ToVec(const ScalarType &vector) { - return vtkm::Tuple(vector); + return vtkm::Vec(vector); } }; } @@ -192,30 +192,23 @@ struct VectorTraitsBasic { #define VTKM_BASIC_TYPE_VECTOR(type) \ template<> \ struct VectorTraits \ - : public vtkm::internal::VectorTraitsBasic { };/* \ + : public vtkm::internal::VectorTraitsBasic { }/*; \ template<> \ struct VectorTraits \ : public vtkm::internal::VectorTraitsBasic { }*/ /// Allows you to treat basic types as if they were vectors. -VTKM_BASIC_TYPE_VECTOR(float); -VTKM_BASIC_TYPE_VECTOR(double); -VTKM_BASIC_TYPE_VECTOR(char); -VTKM_BASIC_TYPE_VECTOR(unsigned char); -VTKM_BASIC_TYPE_VECTOR(short); -VTKM_BASIC_TYPE_VECTOR(unsigned short); -VTKM_BASIC_TYPE_VECTOR(int); -VTKM_BASIC_TYPE_VECTOR(unsigned int); -#if VTKM_SIZE_LONG == 8 -VTKM_BASIC_TYPE_VECTOR(long); -VTKM_BASIC_TYPE_VECTOR(unsigned long); -#elif VTKM_SIZE_LONG_LONG == 8 -VTKM_BASIC_TYPE_VECTOR(long long); -VTKM_BASIC_TYPE_VECTOR(unsigned long long); -#else -#error No implementation for 64-bit vector traits. -#endif +VTKM_BASIC_TYPE_VECTOR(vtkm::Float32); +VTKM_BASIC_TYPE_VECTOR(vtkm::Float64); +VTKM_BASIC_TYPE_VECTOR(vtkm::Int8); +VTKM_BASIC_TYPE_VECTOR(vtkm::UInt8); +VTKM_BASIC_TYPE_VECTOR(vtkm::Int16); +VTKM_BASIC_TYPE_VECTOR(vtkm::UInt16); +VTKM_BASIC_TYPE_VECTOR(vtkm::Int32); +VTKM_BASIC_TYPE_VECTOR(vtkm::UInt32); +VTKM_BASIC_TYPE_VECTOR(vtkm::Int64); +VTKM_BASIC_TYPE_VECTOR(vtkm::UInt64); #undef VTKM_BASIC_TYPE_VECTOR diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index e48c497e0..39587c567 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -42,7 +42,7 @@ struct CompositeVectorSwizzleFunctor { static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VectorTraits::NUM_COMPONENTS; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Vec ComponentMapType; // Caution! This is a reference. const ComponentMapType &SourceComponents; @@ -166,7 +166,7 @@ template class ArrayPortalCompositeVector { typedef vtkm::internal::FunctionInterface PortalTypes; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Vec ComponentMapType; public: typedef typename PortalTypes::ResultType ValueType; @@ -181,7 +181,7 @@ public: VTKM_CONT_EXPORT ArrayPortalCompositeVector( const PortalTypes portals, - vtkm::Tuple sourceComponents) + vtkm::Vec sourceComponents) : Portals(portals), SourceComponents(sourceComponents) { } VTKM_EXEC_EXPORT @@ -223,7 +223,7 @@ public: typedef typename FunctionInterfaceArrays::ResultType ValueType; static const vtkm::IdComponent NUM_COMPONENTS = vtkm::VectorTraits::NUM_COMPONENTS; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Vec 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 @@ -284,7 +284,7 @@ class Storage< typedef vtkm::internal::FunctionInterface FunctionInterfaceWithArrays; static const vtkm::IdComponent NUM_COMPONENTS = FunctionInterfaceWithArrays::ARITY; - typedef vtkm::Tuple ComponentMapType; + typedef vtkm::Vec ComponentMapType; public: typedef ArrayPortalCompositeVectorCont PortalType; @@ -609,7 +609,7 @@ struct ArrayHandleCompositeVectorType private: typedef typename vtkm::VectorTraits::ComponentType ComponentType; - typedef vtkm::Tuple Signature( + typedef vtkm::Vec Signature( ArrayHandleType1,ArrayHandleType2,ArrayHandleType3,ArrayHandleType4); public: typedef vtkm::cont::ArrayHandleCompositeVector type; @@ -624,7 +624,7 @@ struct ArrayHandleCompositeVectorType< private: typedef typename vtkm::VectorTraits::ComponentType ComponentType; - typedef vtkm::Tuple Signature( + typedef vtkm::Vec Signature( ArrayHandleType1,ArrayHandleType2,ArrayHandleType3); public: typedef vtkm::cont::ArrayHandleCompositeVector type; @@ -637,7 +637,7 @@ struct ArrayHandleCompositeVectorType private: typedef typename vtkm::VectorTraits::ComponentType ComponentType; - typedef vtkm::Tuple Signature( + typedef vtkm::Vec Signature( ArrayHandleType1,ArrayHandleType2); public: typedef vtkm::cont::ArrayHandleCompositeVector type; diff --git a/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx b/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx index 4de4a01d4..4c93b4aec 100644 --- a/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx +++ b/vtkm/cont/testing/UnitTestArrayHandleCompositeVector.cxx @@ -121,7 +121,7 @@ void TryScalarArray() std::cout << "Creating a scalar array from one of " << inComponents << " components." << std::endl; - typedef vtkm::Tuple InValueType; + typedef vtkm::Vec InValueType; typedef vtkm::cont::ArrayHandle InArrayType; int inArrayId = 0; InArrayType inArray = MakeInputArray(inArrayId); diff --git a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx index 4642d97f9..79f823555 100644 --- a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx @@ -44,8 +44,8 @@ vtkm::Scalar TestValue(vtkm::Id index, vtkm::Scalar) { } template -vtkm::Tuple TestValue(vtkm::Id index, vtkm::Tuple) { - vtkm::Tuple value; +vtkm::Vec TestValue(vtkm::Id index, vtkm::Vec) { + vtkm::Vec value; 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 1def83894..b99bcfb72 100644 --- a/vtkm/cont/testing/UnitTestStorageListTag.cxx +++ b/vtkm/cont/testing/UnitTestStorageListTag.cxx @@ -44,7 +44,7 @@ struct TestFunctor }; template -void CheckSame(const vtkm::Tuple &expected, +void CheckSame(const vtkm::Vec &expected, const std::vector &found) { VTKM_TEST_ASSERT(static_cast(found.size()) == N, @@ -58,7 +58,7 @@ void CheckSame(const vtkm::Tuple &expected, } template -void TryList(const vtkm::Tuple &expected, ListTag) +void TryList(const vtkm::Vec &expected, ListTag) { TestFunctor functor; vtkm::ListForEach(functor, ListTag()); @@ -68,7 +68,7 @@ void TryList(const vtkm::Tuple &expected, ListTag) void TestLists() { std::cout << "StorageListTagBasic" << std::endl; - TryList(vtkm::Tuple(BASIC), vtkm::cont::StorageListTagBasic()); + TryList(vtkm::Vec(BASIC), vtkm::cont::StorageListTagBasic()); } } // anonymous namespace diff --git a/vtkm/testing/Testing.h b/vtkm/testing/Testing.h index 5c6bc8117..1bc8d10d1 100644 --- a/vtkm/testing/Testing.h +++ b/vtkm/testing/Testing.h @@ -344,14 +344,14 @@ bool test_equal(const std::string &string1, const std::string &string2) /// template VTKM_EXEC_CONT_EXPORT -std::ostream &operator<<(std::ostream &stream, const vtkm::Tuple &tuple) +std::ostream &operator<<(std::ostream &stream, const vtkm::Vec &vec) { stream << "["; for (vtkm::IdComponent component = 0; component < Size-1; component++) { - stream << tuple[component] << ","; + stream << vec[component] << ","; } - return stream << tuple[Size-1] << "]"; + return stream << vec[Size-1] << "]"; } #endif //vtk_m_testing_Testing_h diff --git a/vtkm/testing/UnitTestExtent.cxx b/vtkm/testing/UnitTestExtent.cxx index 21a25a9bd..ec5a78920 100644 --- a/vtkm/testing/UnitTestExtent.cxx +++ b/vtkm/testing/UnitTestExtent.cxx @@ -38,8 +38,8 @@ void TestDimensions(vtkm::Extent) << std::endl; vtkm::Extent extent; - vtkm::Tuple pointDims; - vtkm::Tuple cellDims; + vtkm::Vec pointDims; + vtkm::Vec cellDims; vtkm::Id numPoints; vtkm::Id numCells; @@ -82,7 +82,7 @@ void TestDimensions(vtkm::Extent) template void TryIndexConversion(const vtkm::Extent &extent) { - typedef vtkm::Tuple IdX; + typedef vtkm::Vec IdX; vtkm::Id lastFlatIndex; IdX correctTopologyIndex; diff --git a/vtkm/testing/UnitTestListTag.cxx b/vtkm/testing/UnitTestListTag.cxx index 5264745e4..b768b0da7 100644 --- a/vtkm/testing/UnitTestListTag.cxx +++ b/vtkm/testing/UnitTestListTag.cxx @@ -81,7 +81,7 @@ struct ConstantFunctor }; template -void CheckSame(const vtkm::Tuple &expected, +void CheckSame(const vtkm::Vec &expected, const std::vector &found) { VTKM_TEST_ASSERT(static_cast(found.size()) == N, @@ -95,7 +95,7 @@ void CheckSame(const vtkm::Tuple &expected, } template -void TryList(const vtkm::Tuple &expected, ListTag) +void TryList(const vtkm::Vec &expected, ListTag) { std::cout << " Try mutable for each" << std::endl; MutableFunctor functor; @@ -110,22 +110,22 @@ void TryList(const vtkm::Tuple &expected, ListTag) void TestLists() { std::cout << "ListTagEmpty" << std::endl; - TryList(vtkm::Tuple(), vtkm::ListTagEmpty()); + TryList(vtkm::Vec(), vtkm::ListTagEmpty()); std::cout << "ListTagBase" << std::endl; - TryList(vtkm::Tuple(11), TestListTag1()); + TryList(vtkm::Vec(11), TestListTag1()); std::cout << "ListTagBase2" << std::endl; - TryList(vtkm::Tuple(21,22), TestListTag2()); + TryList(vtkm::Vec(21,22), TestListTag2()); std::cout << "ListTagBase3" << std::endl; - TryList(vtkm::Tuple(31,32,33), TestListTag3()); + TryList(vtkm::Vec(31,32,33), TestListTag3()); std::cout << "ListTagBase4" << std::endl; - TryList(vtkm::Tuple(41,42,43,44), TestListTag4()); + TryList(vtkm::Vec(41,42,43,44), TestListTag4()); std::cout << "ListTagJoin" << std::endl; - TryList(vtkm::Tuple(31,32,33,11), TestListTagJoin()); + TryList(vtkm::Vec(31,32,33,11), TestListTagJoin()); } } // anonymous namespace diff --git a/vtkm/testing/UnitTestTypeListTag.cxx b/vtkm/testing/UnitTestTypeListTag.cxx index 122f75f13..b8c4b5fc1 100644 --- a/vtkm/testing/UnitTestTypeListTag.cxx +++ b/vtkm/testing/UnitTestTypeListTag.cxx @@ -58,7 +58,7 @@ struct TestFunctor }; template -void CheckSame(const vtkm::Tuple &expected, +void CheckSame(const vtkm::Vec &expected, const std::vector &found) { VTKM_TEST_ASSERT(static_cast(found.size()) == N, @@ -72,7 +72,7 @@ void CheckSame(const vtkm::Tuple &expected, } template -void TryList(const vtkm::Tuple &expected, ListTag) +void TryList(const vtkm::Vec &expected, ListTag) { TestFunctor functor; vtkm::ListForEach(functor, ListTag()); @@ -82,38 +82,38 @@ void TryList(const vtkm::Tuple &expected, ListTag) void TestLists() { std::cout << "TypeListTagId" << std::endl; - TryList(vtkm::Tuple(ID), vtkm::TypeListTagId()); + TryList(vtkm::Vec(ID), vtkm::TypeListTagId()); std::cout << "TypeListTagId2" << std::endl; - TryList(vtkm::Tuple(ID2), vtkm::TypeListTagId2()); + TryList(vtkm::Vec(ID2), vtkm::TypeListTagId2()); std::cout << "TypeListTagId3" << std::endl; - TryList(vtkm::Tuple(ID3), vtkm::TypeListTagId3()); + TryList(vtkm::Vec(ID3), vtkm::TypeListTagId3()); std::cout << "TypeListTagScalar" << std::endl; - TryList(vtkm::Tuple(SCALAR), vtkm::TypeListTagScalar()); + TryList(vtkm::Vec(SCALAR), vtkm::TypeListTagScalar()); std::cout << "TypeListTagVector2" << std::endl; - TryList(vtkm::Tuple(VECTOR2), vtkm::TypeListTagVector2()); + TryList(vtkm::Vec(VECTOR2), vtkm::TypeListTagVector2()); std::cout << "TypeListTagVector3" << std::endl; - TryList(vtkm::Tuple(VECTOR3), vtkm::TypeListTagVector3()); + TryList(vtkm::Vec(VECTOR3), vtkm::TypeListTagVector3()); std::cout << "TypeListTagVector4" << std::endl; - TryList(vtkm::Tuple(VECTOR4), vtkm::TypeListTagVector4()); + TryList(vtkm::Vec(VECTOR4), vtkm::TypeListTagVector4()); std::cout << "TypeListTagIndex" << std::endl; - TryList(vtkm::Tuple(ID,ID2,ID3), vtkm::TypeListTagIndex()); + TryList(vtkm::Vec(ID,ID2,ID3), vtkm::TypeListTagIndex()); std::cout << "TypeListTagReal" << std::endl; - TryList(vtkm::Tuple(SCALAR,VECTOR2,VECTOR3,VECTOR4), + TryList(vtkm::Vec(SCALAR,VECTOR2,VECTOR3,VECTOR4), vtkm::TypeListTagReal()); std::cout << "TypeListTagCommon" << std::endl; - TryList(vtkm::Tuple(ID,SCALAR,VECTOR3), vtkm::TypeListTagCommon()); + TryList(vtkm::Vec(ID,SCALAR,VECTOR3), vtkm::TypeListTagCommon()); std::cout << "TypeListTagAll" << std::endl; - vtkm::Tuple allTags; + vtkm::Vec allTags; allTags[0] = ID; allTags[1] = ID2; allTags[2] = ID3; diff --git a/vtkm/testing/UnitTestTypeTraits.cxx b/vtkm/testing/UnitTestTypeTraits.cxx index f2178fbe6..7f4497844 100644 --- a/vtkm/testing/UnitTestTypeTraits.cxx +++ b/vtkm/testing/UnitTestTypeTraits.cxx @@ -75,8 +75,8 @@ static void TestTypeTraits() { TypeTraitTest test; vtkm::testing::Testing::TryAllTypes(test); - std::cout << "vtkm::Tuple" << std::endl; - test(vtkm::Tuple()); + std::cout << "vtkm::Vec" << std::endl; + test(vtkm::Vec()); } } // anonymous namespace diff --git a/vtkm/testing/UnitTestTypes.cxx b/vtkm/testing/UnitTestTypes.cxx index 8f8214812..b134ed524 100644 --- a/vtkm/testing/UnitTestTypes.cxx +++ b/vtkm/testing/UnitTestTypes.cxx @@ -497,11 +497,11 @@ void TestTypes() vtkm::testing::Testing::TryAllTypes(TypeTestFunctor()); //try with some custom tuple types - TypeTestFunctor()( vtkm::Tuple() ); - TypeTestFunctor()( vtkm::Tuple() ); - TypeTestFunctor()( vtkm::Tuple() ); - TypeTestFunctor()( vtkm::Tuple() ); - TypeTestFunctor()( vtkm::Tuple() ); + TypeTestFunctor()( vtkm::Vec() ); + TypeTestFunctor()( vtkm::Vec() ); + TypeTestFunctor()( vtkm::Vec() ); + TypeTestFunctor()( vtkm::Vec() ); + TypeTestFunctor()( vtkm::Vec() ); } } // anonymous namespace diff --git a/vtkm/testing/UnitTestVectorTraits.cxx b/vtkm/testing/UnitTestVectorTraits.cxx index bbcd626f0..9ba378410 100644 --- a/vtkm/testing/UnitTestVectorTraits.cxx +++ b/vtkm/testing/UnitTestVectorTraits.cxx @@ -47,8 +47,8 @@ void TestVectorTraits() { TestVectorTypeFunctor test; vtkm::testing::Testing::TryAllTypes(test); - std::cout << "vtkm::Tuple" << std::endl; - test(vtkm::Tuple()); + std::cout << "vtkm::Vec" << std::endl; + test(vtkm::Vec()); vtkm::testing::TestVectorComponentsTag(); vtkm::testing::TestVectorComponentsTag(); diff --git a/vtkm/testing/VectorTraitsTests.h b/vtkm/testing/VectorTraitsTests.h index b5ec58196..57b29f32e 100644 --- a/vtkm/testing/VectorTraitsTests.h +++ b/vtkm/testing/VectorTraitsTests.h @@ -62,8 +62,8 @@ static void TestVectorTypeImpl( { Traits::SetComponent(result, i, multiplier*Traits::GetComponent(vector, i)); } - VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result), - multiplier*Traits::ToTuple(vector)), + VTKM_TEST_ASSERT(test_equal(Traits::ToVec(result), + multiplier*Traits::ToVec(vector)), "Got bad result for scalar multiple"); } @@ -75,8 +75,8 @@ static void TestVectorTypeImpl( Traits::GetComponent(result, i) = multiplier * Traits::GetComponent(vector, i); } - VTKM_TEST_ASSERT(test_equal(Traits::ToTuple(result), - multiplier*Traits::ToTuple(vector)), + VTKM_TEST_ASSERT(test_equal(Traits::ToVec(result), + multiplier*Traits::ToVec(vector)), "Got bad result for scalar multiple"); } @@ -90,7 +90,7 @@ static void TestVectorTypeImpl( } VTKM_TEST_ASSERT( test_equal(result, - vtkm::dot(Traits::ToTuple(vector), Traits::ToTuple(vector))), + vtkm::dot(Traits::ToVec(vector), Traits::ToVec(vector))), "Got bad result for dot product"); }