2016-12-16 21:25:09 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-12-16 21:25:09 +00:00
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-12-16 21:25:09 +00:00
|
|
|
// 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/worklet/Keys.h>
|
|
|
|
|
2017-09-25 22:54:46 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
|
|
|
|
2016-12-16 21:25:09 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2016-12-16 21:25:09 +00:00
|
|
|
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::Id ARRAY_SIZE = 1033;
|
|
|
|
static constexpr vtkm::Id NUM_UNIQUE = ARRAY_SIZE / 10;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
template <typename KeyPortal, typename IdPortal, typename IdComponentPortal>
|
2017-05-26 17:53:28 +00:00
|
|
|
void CheckKeyReduce(const KeyPortal& originalKeys,
|
|
|
|
const KeyPortal& uniqueKeys,
|
|
|
|
const IdPortal& sortedValuesMap,
|
|
|
|
const IdPortal& offsets,
|
2017-05-18 14:29:41 +00:00
|
|
|
const IdComponentPortal& counts)
|
2016-12-16 21:25:09 +00:00
|
|
|
{
|
|
|
|
using KeyType = typename KeyPortal::ValueType;
|
|
|
|
vtkm::Id originalSize = originalKeys.GetNumberOfValues();
|
|
|
|
vtkm::Id uniqueSize = uniqueKeys.GetNumberOfValues();
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(originalSize == sortedValuesMap.GetNumberOfValues(), "Inconsistent array size.");
|
|
|
|
VTKM_TEST_ASSERT(uniqueSize == offsets.GetNumberOfValues(), "Inconsistent array size.");
|
|
|
|
VTKM_TEST_ASSERT(uniqueSize == counts.GetNumberOfValues(), "Inconsistent array size.");
|
2016-12-16 21:25:09 +00:00
|
|
|
|
|
|
|
for (vtkm::Id uniqueIndex = 0; uniqueIndex < uniqueSize; uniqueIndex++)
|
|
|
|
{
|
|
|
|
KeyType key = uniqueKeys.Get(uniqueIndex);
|
|
|
|
vtkm::Id offset = offsets.Get(uniqueIndex);
|
|
|
|
vtkm::IdComponent groupCount = counts.Get(uniqueIndex);
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent groupIndex = 0; groupIndex < groupCount; groupIndex++)
|
2016-12-16 21:25:09 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id originalIndex = sortedValuesMap.Get(offset + groupIndex);
|
2016-12-16 21:25:09 +00:00
|
|
|
KeyType originalKey = originalKeys.Get(originalIndex);
|
|
|
|
VTKM_TEST_ASSERT(key == originalKey, "Bad key lookup.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename KeyType>
|
2016-12-16 21:25:09 +00:00
|
|
|
void TryKeyType(KeyType)
|
|
|
|
{
|
|
|
|
KeyType keyBuffer[ARRAY_SIZE];
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
keyBuffer[index] = TestValue(index % NUM_UNIQUE, KeyType());
|
2016-12-16 21:25:09 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<KeyType> keyArray = vtkm::cont::make_ArrayHandle(keyBuffer, ARRAY_SIZE);
|
2016-12-16 21:25:09 +00:00
|
|
|
|
2017-01-23 20:44:09 +00:00
|
|
|
vtkm::cont::ArrayHandle<KeyType> sortedKeys;
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::cont::ArrayCopy(keyArray, sortedKeys);
|
2017-01-23 20:44:09 +00:00
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::worklet::Keys<KeyType> keys(sortedKeys);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(keys.GetInputRange() == NUM_UNIQUE, "Keys has bad input range.");
|
2016-12-16 21:25:09 +00:00
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
CheckKeyReduce(keyArray.GetPortalConstControl(),
|
|
|
|
keys.GetUniqueKeys().GetPortalConstControl(),
|
2016-12-16 21:25:09 +00:00
|
|
|
keys.GetSortedValuesMap().GetPortalConstControl(),
|
|
|
|
keys.GetOffsets().GetPortalConstControl(),
|
|
|
|
keys.GetCounts().GetPortalConstControl());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestKeys()
|
|
|
|
{
|
|
|
|
std::cout << "Testing vtkm::Id keys." << std::endl;
|
|
|
|
TryKeyType(vtkm::Id());
|
|
|
|
|
|
|
|
std::cout << "Testing vtkm::IdComponent keys." << std::endl;
|
|
|
|
TryKeyType(vtkm::IdComponent());
|
|
|
|
|
|
|
|
std::cout << "Testing vtkm::UInt8 keys." << std::endl;
|
|
|
|
TryKeyType(vtkm::UInt8());
|
|
|
|
|
|
|
|
std::cout << "Testing vtkm::Id3 keys." << std::endl;
|
|
|
|
TryKeyType(vtkm::Id3());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestKeys(int argc, char* argv[])
|
2016-12-16 21:25:09 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestKeys, argc, argv);
|
2016-12-16 21:25:09 +00:00
|
|
|
}
|