mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Fix inverted ArrayCopy
arguments
Also fix condition where a `UnknownArrayHandle` destination does not have an underlying `ArrayHandle` set yet.
This commit is contained in:
parent
fa4da95eb2
commit
4c524de625
@ -26,7 +26,7 @@ struct CopyWorklet : vtkm::worklet::WorkletMapField
|
||||
using InputDomain = _1;
|
||||
|
||||
template <typename InType, typename OutType>
|
||||
void operator()(const InType& in, OutType& out) const
|
||||
VTKM_EXEC void operator()(const InType& in, OutType& out) const
|
||||
{
|
||||
out = in;
|
||||
}
|
||||
@ -68,7 +68,7 @@ struct UnknownCopyFunctor2
|
||||
struct UnknownCopyFunctor1
|
||||
{
|
||||
template <typename InArrayType>
|
||||
void operator()(const InArrayType& in, const vtkm::cont::UnknownArrayHandle& out) const
|
||||
void operator()(const InArrayType& in, vtkm::cont::UnknownArrayHandle& out) const
|
||||
{
|
||||
out.Allocate(in.GetNumberOfValues());
|
||||
|
||||
@ -79,7 +79,7 @@ struct UnknownCopyFunctor1
|
||||
}
|
||||
|
||||
template <typename InArrayType>
|
||||
void DoIt(const InArrayType& in, const vtkm::cont::UnknownArrayHandle& out, std::false_type) const
|
||||
void DoIt(const InArrayType& in, vtkm::cont::UnknownArrayHandle& out, std::false_type) const
|
||||
{
|
||||
// Source is not float.
|
||||
using BaseComponentType = typename InArrayType::ValueType::ComponentType;
|
||||
@ -104,7 +104,7 @@ struct UnknownCopyFunctor1
|
||||
}
|
||||
|
||||
template <typename InArrayType>
|
||||
void DoIt(const InArrayType& in, const vtkm::cont::UnknownArrayHandle& out, std::true_type) const
|
||||
void DoIt(const InArrayType& in, vtkm::cont::UnknownArrayHandle& out, std::true_type) const
|
||||
{
|
||||
// Source array is FloatDefault. That should be copiable to anything.
|
||||
out.CastAndCallWithExtractedArray(UnknownCopyFunctor2{}, in);
|
||||
@ -119,9 +119,14 @@ namespace cont
|
||||
{
|
||||
|
||||
void ArrayCopy(const vtkm::cont::UnknownArrayHandle& source,
|
||||
const vtkm::cont::UnknownArrayHandle& destination)
|
||||
vtkm::cont::UnknownArrayHandle& destination)
|
||||
{
|
||||
destination.CastAndCallWithExtractedArray(UnknownCopyFunctor1{}, source);
|
||||
if (!destination.IsValid())
|
||||
{
|
||||
destination = source.NewInstanceBasic();
|
||||
}
|
||||
|
||||
source.CastAndCallWithExtractedArray(UnknownCopyFunctor1{}, destination);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ VTKM_CONT void ArrayCopy(const vtkm::cont::ArrayHandle<InValueType, InStorage>&
|
||||
|
||||
|
||||
VTKM_CONT_EXPORT void ArrayCopy(const vtkm::cont::UnknownArrayHandle& source,
|
||||
const vtkm::cont::UnknownArrayHandle& destination);
|
||||
vtkm::cont::UnknownArrayHandle& destination);
|
||||
|
||||
template <typename T, typename S>
|
||||
VTKM_CONT void ArrayCopy(const vtkm::cont::UnknownArrayHandle& source,
|
||||
@ -175,7 +175,10 @@ VTKM_CONT void ArrayCopy(const vtkm::cont::UnknownArrayHandle& source,
|
||||
}
|
||||
else
|
||||
{
|
||||
ArrayCopy(source, vtkm::cont::UnknownArrayHandle(destination));
|
||||
vtkm::cont::UnknownArrayHandle destWrapper(destination);
|
||||
ArrayCopy(source, destWrapper);
|
||||
// Destination array should not change, but just in case.
|
||||
destWrapper.AsArrayHandle(destination);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,11 @@ VTKM_CONT bool UnknownArrayHandle::IsBaseComponentTypeImpl(
|
||||
return this->Container->BaseComponentType == type;
|
||||
}
|
||||
|
||||
VTKM_CONT bool UnknownArrayHandle::IsValid() const
|
||||
{
|
||||
return static_cast<bool>(this->Container);
|
||||
}
|
||||
|
||||
VTKM_CONT UnknownArrayHandle UnknownArrayHandle::NewInstance() const
|
||||
{
|
||||
UnknownArrayHandle newArray;
|
||||
|
@ -386,6 +386,14 @@ public:
|
||||
|
||||
UnknownArrayHandle& operator=(const vtkm::cont::UnknownArrayHandle&) = default;
|
||||
|
||||
/// \brief Returns whether an array is stored in this `UnknownArrayHandle`.
|
||||
///
|
||||
/// If the `UnknownArrayHandle` is constructed without an `ArrayHandle`, it
|
||||
/// will not have an underlying type, and therefore the operations will be
|
||||
/// invalid. It is still possible to set this `UnknownArrayHandle` to an
|
||||
/// `ArrayHandle`.
|
||||
VTKM_CONT bool IsValid() const;
|
||||
|
||||
/// \brief Create a new array of the same type as this array.
|
||||
///
|
||||
/// This method creates a new array that is the same type as this one and
|
||||
|
Loading…
Reference in New Issue
Block a user