mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 09:59:12 +00:00
d77c5812c3
The `vtkm::worklet::Keys` object held a `SortedValuesMap` array, an `Offsets` array, a `Counts` array, and (optionally) a `UniqueKeys` array. Of these, the `Counts` array is redundant because the counts are trivially computed by subtracting adjacent entries in the offsets array. This pattern shows up a lot in VTK-m, and most places we have moved to removing the counts and just using the offsets. This change removes the `Count` array from the `Keys` object. Where the count is needed internally, adjacent offsets are subtracted. The deprecated `GetCounts` method is implemented by copying values into a new array.
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
//============================================================================
|
|
// Copyright (c) Kitware, Inc.
|
|
// All rights reserved.
|
|
// See LICENSE.txt for details.
|
|
//
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
//============================================================================
|
|
#ifndef vtk_m_exec_internal_ReduceByKeyLookup_h
|
|
#define vtk_m_exec_internal_ReduceByKeyLookup_h
|
|
|
|
#include <vtkm/cont/ExecutionObjectBase.h>
|
|
|
|
#include <vtkm/StaticAssert.h>
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <type_traits>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace exec
|
|
{
|
|
namespace internal
|
|
{
|
|
|
|
/// A superclass of `ReduceBykeyLookup` that can be used when no key values are provided.
|
|
///
|
|
template <typename IdPortalType, typename IdComponentPortalType>
|
|
struct ReduceByKeyLookupBase
|
|
{
|
|
VTKM_STATIC_ASSERT((std::is_same<typename IdPortalType::ValueType, vtkm::Id>::value));
|
|
VTKM_STATIC_ASSERT(
|
|
(std::is_same<typename IdComponentPortalType::ValueType, vtkm::IdComponent>::value));
|
|
|
|
IdPortalType SortedValuesMap;
|
|
IdPortalType Offsets;
|
|
|
|
VTKM_EXEC_CONT
|
|
ReduceByKeyLookupBase(const IdPortalType& sortedValuesMap, const IdPortalType& offsets)
|
|
: SortedValuesMap(sortedValuesMap)
|
|
, Offsets(offsets)
|
|
{
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
VTKM_EXEC_CONT
|
|
ReduceByKeyLookupBase() {}
|
|
};
|
|
|
|
/// \brief Execution object holding lookup info for reduce by key.
|
|
///
|
|
/// A WorkletReduceByKey needs several arrays to map the current output object
|
|
/// to the respective key and group of values. This execution object holds that
|
|
/// state.
|
|
///
|
|
template <typename KeyPortalType, typename IdPortalType, typename IdComponentPortalType>
|
|
struct ReduceByKeyLookup : ReduceByKeyLookupBase<IdPortalType, IdComponentPortalType>
|
|
{
|
|
using KeyType = typename KeyPortalType::ValueType;
|
|
|
|
KeyPortalType UniqueKeys;
|
|
|
|
VTKM_EXEC_CONT
|
|
ReduceByKeyLookup(const KeyPortalType& uniqueKeys,
|
|
const IdPortalType& sortedValuesMap,
|
|
const IdPortalType& offsets)
|
|
: ReduceByKeyLookupBase<IdPortalType, IdComponentPortalType>(sortedValuesMap, offsets)
|
|
, UniqueKeys(uniqueKeys)
|
|
{
|
|
}
|
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
|
VTKM_EXEC_CONT
|
|
ReduceByKeyLookup() {}
|
|
};
|
|
}
|
|
}
|
|
} // namespace vtkm::exec::internal
|
|
|
|
#endif //vtk_m_exec_internal_ReduceByKeyLookup_h
|