mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-08 11:29:02 +00:00
Merge topic 'vecfromportal-operators'
508cc3acc Improve = operators in VecFromPortal Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Merge-request: !3113
This commit is contained in:
commit
9c7b36ab61
8
docs/changelog/vecfromportal-operators.md
Normal file
8
docs/changelog/vecfromportal-operators.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Improved = operators in VecFromPortal
|
||||||
|
|
||||||
|
Previously, `VecFromPortal` could only be set to a standard `Vec`.
|
||||||
|
However, because this is a `Vec`-like object with a runtime-size, it is
|
||||||
|
hard to do general arithmetic on it. It is easier to do in place so
|
||||||
|
there is some place to put the result. To make it easier to operate on
|
||||||
|
this as the result of other `Vec`-likes, extend the operators like `+=`,
|
||||||
|
`*=`, etc to support this.
|
@ -73,10 +73,11 @@ public:
|
|||||||
index + this->Offset);
|
index + this->Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, vtkm::IdComponent N>
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
VTKM_EXEC_CONT VecFromPortal& operator=(const vtkm::Vec<T, N>& src)
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT VecFromPortal& operator=(const OtherVecType& src)
|
||||||
{
|
{
|
||||||
vtkm::IdComponent numComponents = vtkm::Min(N, this->NumComponents);
|
vtkm::IdComponent numComponents = vtkm::Min(src.GetNumberOfComponents(), this->NumComponents);
|
||||||
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
||||||
{
|
{
|
||||||
this->Portal.Set(index + this->Offset, src[index]);
|
this->Portal.Set(index + this->Offset, src[index]);
|
||||||
@ -84,6 +85,96 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT VecFromPortal& operator+=(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
vtkm::IdComponent numComponents = vtkm::Min(other.GetNumberOfComponents(), this->NumComponents);
|
||||||
|
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
||||||
|
{
|
||||||
|
(*this)[index] += other[index];
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT VecFromPortal& operator-=(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
vtkm::IdComponent numComponents = vtkm::Min(other.GetNumberOfComponents(), this->NumComponents);
|
||||||
|
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
||||||
|
{
|
||||||
|
(*this)[index] -= other[index];
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT void Multiply(const OtherVecType& other, vtkm::TypeTraitsVectorTag)
|
||||||
|
{
|
||||||
|
vtkm::IdComponent numComponents = vtkm::Min(other.GetNumberOfComponents(), this->NumComponents);
|
||||||
|
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
||||||
|
{
|
||||||
|
(*this)[index] *= other[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ScalarType>
|
||||||
|
VTKM_EXEC_CONT void Multiply(ScalarType other, vtkm::TypeTraitsScalarTag)
|
||||||
|
{
|
||||||
|
for (vtkm::IdComponent index = 0; index < this->NumComponents; ++index)
|
||||||
|
{
|
||||||
|
(*this)[index] *= other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT VecFromPortal& operator*=(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
this->Multiply(other, typename vtkm::TypeTraits<OtherVecType>::DimensionalityTag{});
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT VecFromPortal& operator/=(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
vtkm::IdComponent numComponents = vtkm::Min(other.GetNumberOfComponents(), this->NumComponents);
|
||||||
|
for (vtkm::IdComponent index = 0; index < numComponents; ++index)
|
||||||
|
{
|
||||||
|
(*this)[index] /= other[index];
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT bool operator==(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
if (this->NumComponents != other.GetNumberOfComponents())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (vtkm::IdComponent index = 0; index < this->NumComponents; ++index)
|
||||||
|
{
|
||||||
|
if (this->Portal.Get(index + this->Offset) != other[index])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only works with Vec-like objects with operator[] and GetNumberofComponents
|
||||||
|
template <typename OtherVecType>
|
||||||
|
VTKM_EXEC_CONT bool operator!=(const OtherVecType& other)
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
VTKM_EXEC_CONT const PortalType& GetPortal() const { return this->Portal; }
|
VTKM_EXEC_CONT const PortalType& GetPortal() const { return this->Portal; }
|
||||||
VTKM_EXEC_CONT vtkm::Id GetOffset() const { return this->Offset; }
|
VTKM_EXEC_CONT vtkm::Id GetOffset() const { return this->Offset; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user