From dc6e7d1ac8dc3aa4d4503339711d3799a49db465 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 25 Apr 2018 10:48:28 -0400 Subject: [PATCH] Make all Vec types consistently mark methods as inline --- vtkm/Types.h | 119 +++++++++++++++++++++++---------------------- vtkm/VecVariable.h | 11 +++-- 2 files changed, 68 insertions(+), 62 deletions(-) diff --git a/vtkm/Types.h b/vtkm/Types.h index 4003074e6..6bf11c49d 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -200,7 +200,7 @@ template struct VecComponentWiseUnaryOperation { template - VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const + inline VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const { T result; for (vtkm::IdComponent i = 0; i < Size; ++i) @@ -215,7 +215,7 @@ template <> struct VecComponentWiseUnaryOperation<1> { template - VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const + inline VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const { return T(unaryOp(v[0])); } @@ -225,7 +225,7 @@ template <> struct VecComponentWiseUnaryOperation<2> { template - VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const + inline VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const { return T(unaryOp(v[0]), unaryOp(v[1])); } @@ -235,7 +235,7 @@ template <> struct VecComponentWiseUnaryOperation<3> { template - VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const + inline VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const { return T(unaryOp(v[0]), unaryOp(v[1]), unaryOp(v[2])); } @@ -245,7 +245,7 @@ template <> struct VecComponentWiseUnaryOperation<4> { template - VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const + inline VTKM_EXEC_CONT T operator()(const T& v, const UnaryOpType& unaryOp) const { return T(unaryOp(v[0]), unaryOp(v[1]), unaryOp(v[2]), unaryOp(v[3])); } @@ -312,7 +312,7 @@ private: struct Add { template - VTKM_EXEC_CONT T operator()(const T& a, const T& b) const + inline VTKM_EXEC_CONT T operator()(const T& a, const T& b) const { return T(a + b); } @@ -321,7 +321,7 @@ struct Add struct Subtract { template - VTKM_EXEC_CONT T operator()(const T& a, const T& b) const + inline VTKM_EXEC_CONT T operator()(const T& a, const T& b) const { return T(a - b); } @@ -330,7 +330,7 @@ struct Subtract struct Multiply { template - VTKM_EXEC_CONT T operator()(const T& a, const T& b) const + inline VTKM_EXEC_CONT T operator()(const T& a, const T& b) const { return T(a * b); } @@ -339,7 +339,7 @@ struct Multiply struct Divide { template - VTKM_EXEC_CONT T operator()(const T& a, const T& b) const + inline VTKM_EXEC_CONT T operator()(const T& a, const T& b) const { return T(a / b); } @@ -348,7 +348,7 @@ struct Divide struct Negate { template - VTKM_EXEC_CONT T operator()(const T& x) const + inline VTKM_EXEC_CONT T operator()(const T& x) const { return T(-x); } @@ -409,15 +409,15 @@ protected: private: // Only for internal use VTKM_EXEC_CONT - vtkm::IdComponent NumComponents() const { return this->Derived().GetNumberOfComponents(); } + inline vtkm::IdComponent NumComponents() const { return this->Derived().GetNumberOfComponents(); } // Only for internal use VTKM_EXEC_CONT - const T& Component(vtkm::IdComponent index) const { return this->Derived()[index]; } + inline const T& Component(vtkm::IdComponent index) const { return this->Derived()[index]; } // Only for internal use VTKM_EXEC_CONT - T& Component(vtkm::IdComponent index) { return this->Derived()[index]; } + inline T& Component(vtkm::IdComponent index) { return this->Derived()[index]; } public: template @@ -484,7 +484,7 @@ public: #endif // not using cuda < 8 template - VTKM_EXEC_CONT vtkm::Vec operator+( + inline VTKM_EXEC_CONT vtkm::Vec operator+( const vtkm::Vec& other) const { VTKM_ASSERT(Size == this->NumComponents()); @@ -497,7 +497,8 @@ public: } template - VTKM_EXEC_CONT DerivedClass& operator+=(const VecBaseCommon& other) + inline VTKM_EXEC_CONT DerivedClass& operator+=( + const VecBaseCommon& other) { const OtherClass& other_derived = static_cast(other); VTKM_ASSERT(this->NumComponents() == other_derived.GetNumberOfComponents()); @@ -509,7 +510,7 @@ public: } template - VTKM_EXEC_CONT vtkm::Vec operator-( + inline VTKM_EXEC_CONT vtkm::Vec operator-( const vtkm::Vec& other) const { VTKM_ASSERT(Size == this->NumComponents()); @@ -522,7 +523,8 @@ public: } template - VTKM_EXEC_CONT DerivedClass& operator-=(const VecBaseCommon& other) + inline VTKM_EXEC_CONT DerivedClass& operator-=( + const VecBaseCommon& other) { const OtherClass& other_derived = static_cast(other); VTKM_ASSERT(this->NumComponents() == other_derived.GetNumberOfComponents()); @@ -534,7 +536,7 @@ public: } template - VTKM_EXEC_CONT vtkm::Vec operator*( + inline VTKM_EXEC_CONT vtkm::Vec operator*( const vtkm::Vec& other) const { vtkm::Vec result; @@ -546,7 +548,8 @@ public: } template - VTKM_EXEC_CONT DerivedClass& operator*=(const VecBaseCommon& other) + inline VTKM_EXEC_CONT DerivedClass& operator*=( + const VecBaseCommon& other) { const OtherClass& other_derived = static_cast(other); VTKM_ASSERT(this->NumComponents() == other_derived.GetNumberOfComponents()); @@ -558,7 +561,7 @@ public: } template - VTKM_EXEC_CONT vtkm::Vec operator/( + inline VTKM_EXEC_CONT vtkm::Vec operator/( const vtkm::Vec& other) const { vtkm::Vec result; @@ -630,20 +633,16 @@ protected: } public: - VTKM_EXEC_CONT - vtkm::IdComponent GetNumberOfComponents() const { return NUM_COMPONENTS; } + inline VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const { return NUM_COMPONENTS; } - VTKM_EXEC_CONT - //DRP - /* inline */ const ComponentType& operator[](vtkm::IdComponent idx) const + inline VTKM_EXEC_CONT const ComponentType& operator[](vtkm::IdComponent idx) const { VTKM_ASSERT(idx >= 0); VTKM_ASSERT(idx < NUM_COMPONENTS); return this->Components[idx]; } - VTKM_EXEC_CONT - //DRP - /*inline*/ ComponentType& operator[](vtkm::IdComponent idx) + + inline VTKM_EXEC_CONT ComponentType& operator[](vtkm::IdComponent idx) { VTKM_ASSERT(idx >= 0); VTKM_ASSERT(idx < NUM_COMPONENTS); @@ -658,7 +657,7 @@ public: #endif // not using cuda < 8 template - VTKM_EXEC_CONT DerivedClass + inline VTKM_EXEC_CONT DerivedClass operator+(const VecBaseCommon& other) const { const OtherClass& other_derived = static_cast(other); @@ -673,7 +672,7 @@ public: } template - VTKM_EXEC_CONT DerivedClass + inline VTKM_EXEC_CONT DerivedClass operator-(const VecBaseCommon& other) const { const OtherClass& other_derived = static_cast(other); @@ -688,7 +687,7 @@ public: } template - VTKM_EXEC_CONT DerivedClass + inline VTKM_EXEC_CONT DerivedClass operator*(const VecBaseCommon& other) const { const OtherClass& other_derived = static_cast(other); @@ -703,7 +702,7 @@ public: } template - VTKM_EXEC_CONT DerivedClass + inline VTKM_EXEC_CONT DerivedClass operator/(const VecBaseCommon& other) const { const OtherClass& other_derived = static_cast(other); @@ -1043,24 +1042,24 @@ public: { } - VTKM_EXEC_CONT - const T& operator[](vtkm::IdComponent index) const + inline VTKM_EXEC_CONT const T& operator[](vtkm::IdComponent index) const { VTKM_ASSERT(index >= 0); VTKM_ASSERT(index < this->NumberOfComponents); return this->Components[index]; } - VTKM_EXEC_CONT - T& operator[](vtkm::IdComponent index) + inline VTKM_EXEC_CONT T& operator[](vtkm::IdComponent index) { VTKM_ASSERT(index >= 0); VTKM_ASSERT(index < this->NumberOfComponents); return this->Components[index]; } - VTKM_EXEC_CONT - vtkm::IdComponent GetNumberOfComponents() const { return this->NumberOfComponents; } + inline VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const + { + return this->NumberOfComponents; + } VTKM_EXEC_CONT VecC& operator=(const VecC& src) @@ -1144,16 +1143,17 @@ public: { } - VTKM_EXEC_CONT - const T& operator[](vtkm::IdComponent index) const + inline VTKM_EXEC_CONT const T& operator[](vtkm::IdComponent index) const { VTKM_ASSERT(index >= 0); VTKM_ASSERT(index < this->NumberOfComponents); return this->Components[index]; } - VTKM_EXEC_CONT - vtkm::IdComponent GetNumberOfComponents() const { return this->NumberOfComponents; } + inline VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents() const + { + return this->NumberOfComponents; + } private: const T* const Components; @@ -1171,7 +1171,7 @@ private: /// Creates a \c VecC from an input array. /// template -VTKM_EXEC_CONT static inline vtkm::VecC make_VecC(T* array, vtkm::IdComponent size) +static inline VTKM_EXEC_CONT vtkm::VecC make_VecC(T* array, vtkm::IdComponent size) { return vtkm::VecC(array, size); } @@ -1179,7 +1179,7 @@ VTKM_EXEC_CONT static inline vtkm::VecC make_VecC(T* array, vtkm::IdComponent /// Creates a \c VecCConst from a constant input array. /// template -VTKM_EXEC_CONT static inline vtkm::VecCConst make_VecC(const T* array, vtkm::IdComponent size) +static inline VTKM_EXEC_CONT vtkm::VecCConst make_VecC(const T* array, vtkm::IdComponent size) { return vtkm::VecCConst(array, size); } @@ -1265,7 +1265,7 @@ VTK_M_SCALAR_DOT(vtkm::Float32) VTK_M_SCALAR_DOT(vtkm::Float64) template -VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) { T result = a[0]; for (vtkm::IdComponent i = 1; i < Size; ++i) @@ -1276,25 +1276,25 @@ VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) } template -VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) { return a[0] + a[1]; } template -VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) { return a[0] + a[1] + a[2]; } template -VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceSum(const vtkm::Vec& a) { return a[0] + a[1] + a[2] + a[3]; } template -VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) { T result = a[0]; for (vtkm::IdComponent i = 1; i < Size; ++i) @@ -1305,19 +1305,19 @@ VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) } template -VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) { return a[0] * a[1]; } template -VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) { return a[0] * a[1] * a[2]; } template -VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) +inline VTKM_EXEC_CONT T ReduceProduct(const vtkm::Vec& a) { return a[0] * a[1] * a[2] * a[3]; } @@ -1332,28 +1332,30 @@ struct Pair; // Declared outside of vtkm namespace so that the operator works with all code. template -VTKM_EXEC_CONT vtkm::Vec operator*(T scalar, const vtkm::Vec& vec) +VTKM_EXEC_CONT vtkm::Vec inline operator*(T scalar, const vtkm::Vec& vec) { return vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindLeftBinaryOp(scalar)); } template -VTKM_EXEC_CONT vtkm::Vec operator*(const vtkm::Vec& vec, T scalar) +VTKM_EXEC_CONT vtkm::Vec inline operator*(const vtkm::Vec& vec, T scalar) { return vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindRightBinaryOp(scalar)); } template -VTKM_EXEC_CONT vtkm::Vec operator*(vtkm::Float64 scalar, const vtkm::Vec& vec) +VTKM_EXEC_CONT vtkm::Vec inline operator*(vtkm::Float64 scalar, + const vtkm::Vec& vec) { return vtkm::Vec(vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindLeftBinaryOp(scalar))); } template -VTKM_EXEC_CONT vtkm::Vec operator*(const vtkm::Vec& vec, vtkm::Float64 scalar) +VTKM_EXEC_CONT vtkm::Vec inline operator*(const vtkm::Vec& vec, + vtkm::Float64 scalar) { return vtkm::Vec(vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindRightBinaryOp(scalar))); @@ -1376,14 +1378,15 @@ VTKM_EXEC_CONT vtkm::Vec operator*(const vtkm::Vec -VTKM_EXEC_CONT vtkm::Vec operator/(const vtkm::Vec& vec, T scalar) +VTKM_EXEC_CONT vtkm::Vec inline operator/(const vtkm::Vec& vec, T scalar) { return vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindRightBinaryOp(scalar)); } template -VTKM_EXEC_CONT vtkm::Vec operator/(const vtkm::Vec& vec, vtkm::Float64 scalar) +VTKM_EXEC_CONT vtkm::Vec inline operator/(const vtkm::Vec& vec, + vtkm::Float64 scalar) { return vtkm::Vec(vtkm::internal::VecComponentWiseUnaryOperation()( vec, vtkm::internal::BindRightBinaryOp(scalar))); diff --git a/vtkm/VecVariable.h b/vtkm/VecVariable.h index 479d067de..85fbfd0bc 100644 --- a/vtkm/VecVariable.h +++ b/vtkm/VecVariable.h @@ -60,10 +60,10 @@ public: } VTKM_EXEC_CONT - vtkm::IdComponent GetNumberOfComponents() const { return this->NumComponents; } + inline vtkm::IdComponent GetNumberOfComponents() const { return this->NumComponents; } template - VTKM_EXEC_CONT void CopyInto(vtkm::Vec& dest) const + VTKM_EXEC_CONT inline void CopyInto(vtkm::Vec& dest) const { vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->NumComponents); for (vtkm::IdComponent index = 0; index < numComponents; index++) @@ -73,10 +73,13 @@ public: } VTKM_EXEC_CONT - const ComponentType& operator[](vtkm::IdComponent index) const { return this->Data[index]; } + inline const ComponentType& operator[](vtkm::IdComponent index) const + { + return this->Data[index]; + } VTKM_EXEC_CONT - ComponentType& operator[](vtkm::IdComponent index) { return this->Data[index]; } + inline ComponentType& operator[](vtkm::IdComponent index) { return this->Data[index]; } VTKM_EXEC_CONT void Append(ComponentType value)