mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Add ArrayHandleIndex class.
This is the most common use case for ArrayHandleCounting, and this class is a bit easier to use and a bit faster.
This commit is contained in:
parent
4b70770d48
commit
891182ee19
59
vtkm/cont/ArrayHandleIndex.h
Normal file
59
vtkm/cont/ArrayHandleIndex.h
Normal file
@ -0,0 +1,59 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Copyright 2015 Sandia Corporation.
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//
|
||||
//=============================================================================
|
||||
#ifndef vtk_m_cont_ArrayHandleIndex_h
|
||||
#define vtk_m_cont_ArrayHandleIndex_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct IndexFunctor {
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Id operator()(vtkm::Id index) const { return index; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/// \brief An implicit array handle containing the its own indices.
|
||||
///
|
||||
/// \c ArrayHandleIndex is an implicit array handle containing the values
|
||||
/// 0, 1, 2, 3,... to a specified size. Every value in the array is the same
|
||||
/// as the index to that value.
|
||||
///
|
||||
class ArrayHandleIndex
|
||||
: public vtkm::cont::ArrayHandleImplicit<vtkm::Id, detail::IndexFunctor>
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandleImplicit<vtkm::Id, detail::IndexFunctor>
|
||||
Superclass;
|
||||
|
||||
public:
|
||||
ArrayHandleIndex(vtkm::Id length = 0)
|
||||
: Superclass(detail::IndexFunctor(), length) { }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtk_m_cont_ArrayHandleIndex_h
|
@ -27,6 +27,7 @@ set(headers
|
||||
ArrayHandleConstant.h
|
||||
ArrayHandleCounting.h
|
||||
ArrayHandleImplicit.h
|
||||
ArrayHandleIndex.h
|
||||
ArrayHandlePermutation.h
|
||||
ArrayHandleTransform.h
|
||||
ArrayHandleUniformPointCoordinates.h
|
||||
|
@ -21,8 +21,8 @@
|
||||
#define vtk_m_cont_internal_DeviceAdapterAlgorithmGeneral_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/ArrayHandleZip.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/StorageBasic.h>
|
||||
@ -1204,11 +1204,7 @@ template<typename T, typename U, class CIn, class CStencil, class COut>
|
||||
const vtkm::cont::ArrayHandle<T,CStencil> &stencil,
|
||||
vtkm::cont::ArrayHandle<vtkm::Id,COut> &output)
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandleCounting<vtkm::Id> CountingHandleType;
|
||||
|
||||
CountingHandleType input =
|
||||
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0),
|
||||
stencil.GetNumberOfValues());
|
||||
vtkm::cont::ArrayHandleIndex input(stencil.GetNumberOfValues());
|
||||
DerivedAlgorithm::StreamCompact(input, stencil, output);
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ public:
|
||||
IndexType indexArray;
|
||||
ValueType valuesScattered;
|
||||
|
||||
Copy( make_ArrayHandleCounting(0, keys.GetNumberOfValues()), indexArray);
|
||||
Copy( ArrayHandleIndex(keys.GetNumberOfValues()), indexArray);
|
||||
SortByKeyDirect(keys, indexArray, wrappedCompare);
|
||||
Scatter(values, indexArray, valuesScattered);
|
||||
Copy( valuesScattered, values );
|
||||
|
@ -35,6 +35,7 @@ set(unit_tests
|
||||
UnitTestArrayHandleCounting.cxx
|
||||
UnitTestArrayHandleFancy.cxx
|
||||
UnitTestArrayHandleImplicit.cxx
|
||||
UnitTestArrayHandleIndex.cxx
|
||||
UnitTestArrayHandlePermutation.cxx
|
||||
UnitTestArrayHandleTransform.cxx
|
||||
UnitTestArrayHandleUniformPointCoordinates.cxx
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/BinaryPredicates.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/ArrayHandlePermutation.h>
|
||||
#include <vtkm/cont/ArrayHandleZip.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
@ -765,8 +765,8 @@ private:
|
||||
std::cout << "Sort of a ArrayHandlePermutation" << std::endl;
|
||||
|
||||
//verify that we can use ArrayHandlePermutation inplace
|
||||
vtkm::cont::ArrayHandleCounting< vtkm::Id > index(0, ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandlePermutation< vtkm::cont::ArrayHandleCounting< vtkm::Id >,
|
||||
vtkm::cont::ArrayHandleIndex index(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandlePermutation< vtkm::cont::ArrayHandleIndex,
|
||||
IdArrayHandle> perm(index, sorted);
|
||||
|
||||
//verify we can use a custom operator sort with permutation handle
|
||||
|
47
vtkm/cont/testing/UnitTestArrayHandleIndex.cxx
Normal file
47
vtkm/cont/testing/UnitTestArrayHandleIndex.cxx
Normal file
@ -0,0 +1,47 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//
|
||||
// Copyright 2015 Sandia Corporation.
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace UnitTestArrayHandleIndexNamespace {
|
||||
|
||||
const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
void TestArrayHandleIndex()
|
||||
{
|
||||
vtkm::cont::ArrayHandleIndex array(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Bad size.");
|
||||
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
VTKM_TEST_ASSERT(array.GetPortalConstControl().Get(index) == index,
|
||||
"Index array has unexpected value.");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace UnitTestArrayHandleIndexNamespace
|
||||
|
||||
int UnitTestArrayHandleIndex(int, char *[])
|
||||
{
|
||||
using namespace UnitTestArrayHandleIndexNamespace;
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayHandleIndex);
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/ArrayHandlePermutation.h>
|
||||
#include <vtkm/cont/ArrayHandleZip.h>
|
||||
|
||||
@ -71,7 +71,7 @@ void AverageByKey(const vtkm::cont::ArrayHandle<KeyType, KeyInStorage> &keyArray
|
||||
typedef vtkm::cont::ArrayHandle<ValueType> ValueArray;
|
||||
|
||||
// sort the indexed array
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> indexArray(0, keyArray.GetNumberOfValues());
|
||||
vtkm::cont::ArrayHandleIndex indexArray(keyArray.GetNumberOfValues());
|
||||
IdArray indexArraySorted;
|
||||
vtkm::cont::ArrayHandle<KeyType> keyArraySorted;
|
||||
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/ArrayHandlePermutation.h>
|
||||
#include <vtkm/cont/CellSetExplicit.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
@ -280,7 +280,8 @@ public:
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> face2CellId;
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> localFaceIds;
|
||||
localFaceIds.Allocate(static_cast<vtkm::Id>(totalFaces));
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> countingArray(vtkm::Id(0), vtkm::Id(totalFaces));
|
||||
vtkm::cont::ArrayHandleIndex countingArray =
|
||||
vtkm::cont::ArrayHandleIndex(vtkm::Id(totalFaces));
|
||||
|
||||
#ifdef __VTKM_EXTERNAL_FACES_BENCHMARK
|
||||
timer.Reset();
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/DynamicArrayHandle.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
@ -309,7 +309,7 @@ public:
|
||||
if (numOutputCells == 0) return;
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> validCellIndicesArray, inputCellIterationNumber;
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> validCellCountImplicitArray(0, numOutputCells);
|
||||
vtkm::cont::ArrayHandleIndex validCellCountImplicitArray(numOutputCells);
|
||||
DeviceAlgorithms::UpperBounds(numOutputTrisPerCell,
|
||||
validCellCountImplicitArray,
|
||||
validCellIndicesArray);
|
||||
|
@ -75,7 +75,7 @@ vtkm::cont::DataSet MakeIsosurfaceTestDataSet(vtkm::Id3 dims)
|
||||
float maxs[3] = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> vertexCountImplicitArray(0, vdims[0]*vdims[1]*vdims[2]);
|
||||
vtkm::cont::ArrayHandleIndex vertexCountImplicitArray(vdims[0]*vdims[1]*vdims[2]);
|
||||
vtkm::worklet::DispatcherMapField<TangleField> tangleFieldDispatcher(TangleField(vdims, mins, maxs));
|
||||
tangleFieldDispatcher.Invoke(vertexCountImplicitArray, fieldArray);
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
@ -18,7 +18,7 @@
|
||||
// this software.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||
#include <vtkm/cont/DynamicArrayHandle.h>
|
||||
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
@ -76,7 +76,7 @@ struct DoTestWorklet
|
||||
inputArray[index] = TestValue(index, T()) + T(100);
|
||||
}
|
||||
|
||||
vtkm::cont::ArrayHandleCounting<vtkm::Id> counting(0,ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandleIndex counting(ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<T> inputHandle =
|
||||
vtkm::cont::make_ArrayHandle(inputArray, ARRAY_SIZE);
|
||||
vtkm::cont::ArrayHandle<T> outputHandle;
|
||||
|
Loading…
Reference in New Issue
Block a user