From 64bcc34389710ee3f186718eb579696d5b6939d4 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 25 Nov 2016 13:04:26 -0500 Subject: [PATCH] Refactor MinAndMax to use vtkm::Vec instead of Pair. The types are the same which makes Vec a more suitable container. --- vtkm/BinaryOperators.h | 23 +++++++++++------------ vtkm/cont/Field.h | 10 ++++------ vtkm/cont/testing/TestingDeviceAdapter.h | 8 ++++---- vtkm/worklet/FieldHistogram.h | 9 ++++----- vtkm/worklet/FieldStatistics.h | 9 ++++----- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/vtkm/BinaryOperators.h b/vtkm/BinaryOperators.h index 14f109c80..c38292142 100644 --- a/vtkm/BinaryOperators.h +++ b/vtkm/BinaryOperators.h @@ -22,7 +22,6 @@ #include #include -#include namespace vtkm { @@ -94,35 +93,35 @@ struct Minimum /// Binary Predicate that takes two arguments argument \c x, and \c y and -/// returns a vtkm::Pair that represents the minimum and maximum values +/// returns a vtkm::Vec that represents the minimum and maximum values /// Note: Requires Type \p T implement the vtkm::Min and vtkm::Max functions. template struct MinAndMax { VTKM_EXEC_CONT - vtkm::Pair operator()(const T& a, const T& b) const + vtkm::Vec operator()(const T& a, const T& b) const { - return vtkm::make_Pair(vtkm::Min(a, b), vtkm::Max(a, b)); + return vtkm::make_Vec(vtkm::Min(a, b), vtkm::Max(a, b)); } VTKM_EXEC_CONT - vtkm::Pair operator()( - const vtkm::Pair& a, const vtkm::Pair& b) const + vtkm::Vec operator()( + const vtkm::Vec& a, const vtkm::Vec& b) const { - return vtkm::make_Pair( - vtkm::Min(a.first, b.first), vtkm::Max(a.second, b.second)); + return vtkm::make_Vec( + vtkm::Min(a[0], b[0]), vtkm::Max(a[1], b[1])); } VTKM_EXEC_CONT - vtkm::Pair operator()(const T& a, const vtkm::Pair& b) const + vtkm::Vec operator()(const T& a, const vtkm::Vec& b) const { - return vtkm::make_Pair(vtkm::Min(a, b.first), vtkm::Max(a, b.second)); + return vtkm::make_Vec(vtkm::Min(a, b[0]), vtkm::Max(a, b[1])); } VTKM_EXEC_CONT - vtkm::Pair operator()(const vtkm::Pair& a, const T& b) const + vtkm::Vec operator()(const vtkm::Vec& a, const T& b) const { - return vtkm::make_Pair(vtkm::Min(a.first, b), vtkm::Max(a.second, b)); + return vtkm::make_Vec(vtkm::Min(a[0], b), vtkm::Max(a[1], b)); } }; diff --git a/vtkm/cont/Field.h b/vtkm/cont/Field.h index 753e7ea89..a6346974a 100644 --- a/vtkm/cont/Field.h +++ b/vtkm/cont/Field.h @@ -56,19 +56,17 @@ public: //not the greatest way of doing this for performance reasons. But //this implementation should generate the smallest amount of code - const vtkm::Pair initial( - input.GetPortalConstControl().Get(0), - input.GetPortalConstControl().Get(0)); + vtkm::Vec initial(input.GetPortalConstControl().Get(0)); - vtkm::Pair result = + vtkm::Vec result = Algorithm::Reduce(input, initial, vtkm::MinAndMax()); this->Range->Allocate(NumberOfComponents); for (vtkm::IdComponent i = 0; i < NumberOfComponents; ++i) { this->Range->GetPortalControl().Set( - i, vtkm::Range(VecType::GetComponent(result.first, i), - VecType::GetComponent(result.second, i))); + i, vtkm::Range(VecType::GetComponent(result[0], i), + VecType::GetComponent(result[1], i))); } } diff --git a/vtkm/cont/testing/TestingDeviceAdapter.h b/vtkm/cont/testing/TestingDeviceAdapter.h index bad2c5339..e05122fbb 100644 --- a/vtkm/cont/testing/TestingDeviceAdapter.h +++ b/vtkm/cont/testing/TestingDeviceAdapter.h @@ -1088,14 +1088,14 @@ private: testData[ARRAY_SIZE/2] = maxValue; IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData, ARRAY_SIZE); - vtkm::Pair range = Algorithm::Reduce(input, - vtkm::Pair(0,0), + vtkm::Vec range = Algorithm::Reduce(input, + vtkm::Vec(0,0), vtkm::MinAndMax()); - VTKM_TEST_ASSERT(maxValue == range.second, + VTKM_TEST_ASSERT(maxValue == range[1], "Got bad value from Reduce with comparison object"); - VTKM_TEST_ASSERT(0 == range.first, + VTKM_TEST_ASSERT(0 == range[0], "Got bad value from Reduce with comparison object"); } diff --git a/vtkm/worklet/FieldHistogram.h b/vtkm/worklet/FieldHistogram.h index e2a9708e7..728e6d7f6 100644 --- a/vtkm/worklet/FieldHistogram.h +++ b/vtkm/worklet/FieldHistogram.h @@ -147,15 +147,14 @@ public: const vtkm::Id numberOfValues = fieldArray.GetNumberOfValues(); - const vtkm::Pair initValue( - fieldArray.GetPortalConstControl().Get(0), + const vtkm::Vec initValue( fieldArray.GetPortalConstControl().Get(0)); - vtkm::Pair result = + vtkm::Vec result = DeviceAlgorithms::Reduce(fieldArray, initValue, vtkm::MinAndMax()); - const FieldType& fieldMinValue = result.first; - const FieldType& fieldMaxValue = result.second; + const FieldType& fieldMinValue = result[0]; + const FieldType& fieldMaxValue = result[1]; const FieldType fieldDelta = compute_delta(fieldMinValue, fieldMaxValue, numberOfBins); diff --git a/vtkm/worklet/FieldStatistics.h b/vtkm/worklet/FieldStatistics.h index daf1884a9..bcafc2b63 100644 --- a/vtkm/worklet/FieldStatistics.h +++ b/vtkm/worklet/FieldStatistics.h @@ -137,12 +137,11 @@ public: statinfo.median = tempPortal.Get(dataSize / 2); // Minimum and maximum - const vtkm::Pair initValue(tempPortal.Get(0), - tempPortal.Get(0)); - vtkm::Pair result = + const vtkm::Vec initValue(tempPortal.Get(0)); + vtkm::Vec result = DeviceAlgorithms::Reduce(fieldArray, initValue, vtkm::MinAndMax()); - statinfo.minimum = result.first; - statinfo.maximum = result.second; + statinfo.minimum = result[0]; + statinfo.maximum = result[1]; // Mean FieldType sum = DeviceAlgorithms::ScanInclusive(fieldArray, tempArray);