mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add arithmetic assignment operators to RecombineVec
`RecombineVec` is the class used as the value type for `ArrayHandleRecombineVec`. It is a `Vec`-like object, but has several limitations (including arithmetic operators like `+` won't work). Arithmetic assignment operators are useful so you don't have to create impossible intermediate values.
This commit is contained in:
parent
1cc6dbb0c2
commit
ab9c0f7248
@ -91,6 +91,117 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator+=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] += VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator-=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] -= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator*=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] *= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator/=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] /= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator%=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] %= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator&=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] &= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator|=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] |= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator^=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] ^= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator>>=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] >>= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename T, typename = typename std::enable_if<vtkm::HasVecTraits<T>::value>::type>
|
||||
VTKM_EXEC_CONT RecombineVec& operator<<=(const T& src)
|
||||
{
|
||||
using VTraits = vtkm::VecTraits<T>;
|
||||
VTKM_ASSERT(this->GetNumberOfComponents() == VTraits::GetNumberOfComponents(src));
|
||||
for (vtkm::IdComponent cIndex = 0; cIndex < this->GetNumberOfComponents(); ++cIndex)
|
||||
{
|
||||
(*this)[cIndex] <<= VTraits::GetComponent(src, cIndex);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
VTKM_EXEC_CONT void DoCopy(const T& src)
|
||||
@ -159,6 +270,13 @@ struct VecTraits<vtkm::internal::RecombineVec<PortalType>>
|
||||
return vector[componentIndex];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT static void SetComponent(const VecType& vector,
|
||||
vtkm::IdComponent componentIndex,
|
||||
const ComponentType& component)
|
||||
{
|
||||
vector[componentIndex] = component;
|
||||
}
|
||||
|
||||
template <vtkm::IdComponent destSize>
|
||||
VTKM_EXEC_CONT static void CopyInto(const VecType& src, vtkm::Vec<ComponentType, destSize>& dest)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user