mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 10:35:42 +00:00
Merge topic 'fix-ArrayHandleTransform'
f3560116 Fix ArrayHandleTransform to use supplied functor object instead of a default Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !224
This commit is contained in:
commit
757891cfcc
@ -205,6 +205,11 @@ public:
|
||||
return this->Array;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
const FunctorType &GetFunctor() const {
|
||||
return this->Functor;
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayHandleType Array;
|
||||
FunctorType Functor;
|
||||
@ -237,7 +242,8 @@ public:
|
||||
FunctorType> PortalConstExecution;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayTransfer(StorageType *storage) : Array(storage->GetArray()) { }
|
||||
ArrayTransfer(StorageType *storage)
|
||||
: Array(storage->GetArray()), Functor(storage->GetFunctor()) { }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Id GetNumberOfValues() const {
|
||||
@ -246,7 +252,7 @@ public:
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData)) {
|
||||
return PortalConstExecution(this->Array.PrepareForInput(Device()));
|
||||
return PortalConstExecution(this->Array.PrepareForInput(Device()), this->Functor);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
@ -283,6 +289,7 @@ public:
|
||||
|
||||
private:
|
||||
ArrayHandleType Array;
|
||||
FunctorType Functor;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -65,6 +65,35 @@ struct ValueSquared
|
||||
{ return vtkm::dot(u, u); }
|
||||
};
|
||||
|
||||
struct ValueScale
|
||||
{
|
||||
ValueScale() : Factor()
|
||||
{ }
|
||||
|
||||
ValueScale(vtkm::Float64 factor) : Factor(factor)
|
||||
{ }
|
||||
|
||||
template<typename ValueType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType operator()(const ValueType &v) const
|
||||
{
|
||||
typedef vtkm::VecTraits<ValueType> Traits;
|
||||
typedef typename Traits::ComponentType ComponentType;
|
||||
|
||||
ValueType result;
|
||||
for (vtkm::IdComponent i = 0; i < Traits::GetNumberOfComponents(v); ++i)
|
||||
{
|
||||
vtkm::Float64 vi = static_cast<vtkm::Float64>(Traits::GetComponent(v, i));
|
||||
vtkm::Float64 ri = vi * this->Factor;
|
||||
Traits::SetComponent(result, i, static_cast<ComponentType>(ri));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Float64 Factor;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace vtkm {
|
||||
@ -293,19 +322,17 @@ private:
|
||||
template< typename ValueType>
|
||||
VTKM_CONT_EXPORT void operator()(const ValueType vtkmNotUsed(v)) const
|
||||
{
|
||||
typedef typename vtkm::VecTraits<ValueType>::ComponentType OutputValueType;
|
||||
typedef fancy_array_detail::ValueSquared<OutputValueType> FunctorType;
|
||||
typedef fancy_array_detail::ValueScale FunctorType;
|
||||
|
||||
const vtkm::Id length = ARRAY_SIZE;
|
||||
FunctorType functor;
|
||||
FunctorType functor(2.0);
|
||||
|
||||
vtkm::cont::ArrayHandle<ValueType> input;
|
||||
vtkm::cont::ArrayHandleTransform<
|
||||
OutputValueType,
|
||||
ValueType,
|
||||
vtkm::cont::ArrayHandle<ValueType>,
|
||||
FunctorType> transformed =
|
||||
vtkm::cont::make_ArrayHandleTransform<OutputValueType>(input,
|
||||
functor);
|
||||
vtkm::cont::make_ArrayHandleTransform<ValueType>(input, functor);
|
||||
|
||||
typedef typename vtkm::cont::ArrayHandle<ValueType>::PortalControl Portal;
|
||||
input.Allocate(length);
|
||||
@ -315,7 +342,7 @@ private:
|
||||
portal.Set(i, TestValue(i, ValueType()) );
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandle< OutputValueType > result;
|
||||
vtkm::cont::ArrayHandle< ValueType > result;
|
||||
|
||||
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
|
||||
dispatcher.Invoke(transformed, result);
|
||||
@ -323,10 +350,9 @@ private:
|
||||
//verify that the control portal works
|
||||
for(vtkm::Id i=0; i < length; ++i)
|
||||
{
|
||||
const OutputValueType result_v = result.GetPortalConstControl().Get(i);
|
||||
const OutputValueType correct_value = functor(TestValue(i, ValueType()));
|
||||
const OutputValueType control_value =
|
||||
transformed.GetPortalConstControl().Get(i);
|
||||
const ValueType result_v = result.GetPortalConstControl().Get(i);
|
||||
const ValueType correct_value = functor(TestValue(i, ValueType()));
|
||||
const ValueType control_value = transformed.GetPortalConstControl().Get(i);
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
|
||||
"Transform Handle Failed");
|
||||
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
|
||||
|
Loading…
Reference in New Issue
Block a user