Commit e50ec6b6 authored by Kenneth Moreland's avatar Kenneth Moreland

Fix type error in ScanExclusiveByKey

The implementation of ScanExclusiveByKey in
DeviceAdapterAlgorithmGeneral by shifting values in the input values
array and then calling ScanInclusiveByKey. However, the temporary
shifted values array was created using the key type instead of the
values type. This caused a compile error when the keys and values had
different types.
parent ef6a3b82
......@@ -475,11 +475,16 @@ public:
//--------------------------------------------------------------------------
// Scan Exclusive By Key
template <typename T, typename U, typename KIn, typename VIn, typename VOut, class BinaryFunctor>
VTKM_CONT static void ScanExclusiveByKey(const vtkm::cont::ArrayHandle<T, KIn>& keys,
const vtkm::cont::ArrayHandle<U, VIn>& values,
vtkm::cont::ArrayHandle<U, VOut>& output,
const U& initialValue,
template <typename KeyT,
typename ValueT,
typename KIn,
typename VIn,
typename VOut,
class BinaryFunctor>
VTKM_CONT static void ScanExclusiveByKey(const vtkm::cont::ArrayHandle<KeyT, KIn>& keys,
const vtkm::cont::ArrayHandle<ValueT, VIn>& values,
vtkm::cont::ArrayHandle<ValueT, VOut>& output,
const ValueT& initialValue,
BinaryFunctor binaryFunctor)
{
VTKM_ASSERT(keys.GetNumberOfValues() == values.GetNumberOfValues());
......@@ -513,13 +518,16 @@ public:
}
// 2. Shift input and initialize elements at head flags position to initValue
vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic> temp;
vtkm::cont::ArrayHandle<ValueT, vtkm::cont::StorageTagBasic> temp;
{
auto inputPortal = values.PrepareForInput(DeviceAdapterTag());
auto keyStatePortal = keystate.PrepareForInput(DeviceAdapterTag());
auto tempPortal = temp.PrepareForOutput(numberOfKeys, DeviceAdapterTag());
ShiftCopyAndInit<U, decltype(inputPortal), decltype(keyStatePortal), decltype(tempPortal)>
ShiftCopyAndInit<ValueT,
decltype(inputPortal),
decltype(keyStatePortal),
decltype(tempPortal)>
kernel(inputPortal, keyStatePortal, tempPortal, initialValue);
DerivedAlgorithm::Schedule(kernel, numberOfKeys);
}
......@@ -527,13 +535,13 @@ public:
DerivedAlgorithm::ScanInclusiveByKey(keys, temp, output, binaryFunctor);
}
template <typename T, typename U, class KIn, typename VIn, typename VOut>
VTKM_CONT static void ScanExclusiveByKey(const vtkm::cont::ArrayHandle<T, KIn>& keys,
const vtkm::cont::ArrayHandle<U, VIn>& values,
vtkm::cont::ArrayHandle<U, VOut>& output)
template <typename KeyT, typename ValueT, class KIn, typename VIn, typename VOut>
VTKM_CONT static void ScanExclusiveByKey(const vtkm::cont::ArrayHandle<KeyT, KIn>& keys,
const vtkm::cont::ArrayHandle<ValueT, VIn>& values,
vtkm::cont::ArrayHandle<ValueT, VOut>& output)
{
DerivedAlgorithm::ScanExclusiveByKey(
keys, values, output, vtkm::TypeTraits<U>::ZeroInitialization(), vtkm::Sum());
keys, values, output, vtkm::TypeTraits<ValueT>::ZeroInitialization(), vtkm::Sum());
}
//--------------------------------------------------------------------------
......@@ -632,18 +640,18 @@ public:
return GetExecutionValue(output, numValues - 1);
}
template <typename T, typename U, class KIn, class VIn, class VOut>
VTKM_CONT static void ScanInclusiveByKey(const vtkm::cont::ArrayHandle<T, KIn>& keys,
const vtkm::cont::ArrayHandle<U, VIn>& values,
vtkm::cont::ArrayHandle<U, VOut>& values_output)
template <typename KeyT, typename ValueT, class KIn, class VIn, class VOut>
VTKM_CONT static void ScanInclusiveByKey(const vtkm::cont::ArrayHandle<KeyT, KIn>& keys,
const vtkm::cont::ArrayHandle<ValueT, VIn>& values,
vtkm::cont::ArrayHandle<ValueT, VOut>& values_output)
{
return DerivedAlgorithm::ScanInclusiveByKey(keys, values, values_output, vtkm::Add());
}
template <typename T, typename U, class KIn, class VIn, class VOut, class BinaryFunctor>
VTKM_CONT static void ScanInclusiveByKey(const vtkm::cont::ArrayHandle<T, KIn>& keys,
const vtkm::cont::ArrayHandle<U, VIn>& values,
vtkm::cont::ArrayHandle<U, VOut>& values_output,
template <typename KeyT, typename ValueT, class KIn, class VIn, class VOut, class BinaryFunctor>
VTKM_CONT static void ScanInclusiveByKey(const vtkm::cont::ArrayHandle<KeyT, KIn>& keys,
const vtkm::cont::ArrayHandle<ValueT, VIn>& values,
vtkm::cont::ArrayHandle<ValueT, VOut>& values_output,
BinaryFunctor binary_functor)
{
VTKM_ASSERT(keys.GetNumberOfValues() == values.GetNumberOfValues());
......@@ -675,7 +683,7 @@ public:
// the value summed currently, the second being 0 or 1, with 1 being used
// when this is a value of a key we need to write ( END or START_AND_END)
{
vtkm::cont::ArrayHandle<U, VOut> reducedValues;
vtkm::cont::ArrayHandle<ValueT, VOut> reducedValues;
vtkm::cont::ArrayHandle<ReduceKeySeriesStates> stencil;
auto scanInput = vtkm::cont::make_ArrayHandleZip(values, keystate);
auto scanOutput = vtkm::cont::make_ArrayHandleZip(reducedValues, stencil);
......
......@@ -73,6 +73,7 @@ private:
using StorageTag = vtkm::cont::StorageTagBasic;
using IdArrayHandle = vtkm::cont::ArrayHandle<vtkm::Id, StorageTag>;
using IdComponentArrayHandle = vtkm::cont::ArrayHandle<vtkm::IdComponent, StorageTag>;
using ScalarArrayHandle = vtkm::cont::ArrayHandle<vtkm::FloatDefault, StorageTag>;
......@@ -1182,15 +1183,16 @@ private:
{
const vtkm::Id inputLength = 12;
const vtkm::Id expectedLength = 6;
vtkm::Id inputKeys[inputLength] = { 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 }; // input keys
vtkm::Id inputValues[inputLength] = { 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 }; // input keys
vtkm::Id expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 };
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 }; // in keys
vtkm::Id inputValues[inputLength] = { 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 }; // in values
vtkm::IdComponent expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 };
vtkm::Id expectedValues[expectedLength] = { 10, 2, 0, 3, 10, -42 };
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle keysOut, valuesOut;
IdComponentArrayHandle keysOut;
IdArrayHandle valuesOut;
Algorithm::ReduceByKey(keys, values, keysOut, valuesOut, vtkm::Add());
VTKM_TEST_ASSERT(keysOut.GetNumberOfValues() == expectedLength,
......@@ -1405,13 +1407,13 @@ private:
std::cout << "Testing Scan Inclusive By Key" << std::endl;
const vtkm::Id inputLength = 10;
vtkm::Id inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 };
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut;
......@@ -1529,14 +1531,14 @@ private:
std::cout << "Testing Scan Exclusive By Key" << std::endl;
const vtkm::Id inputLength = 10;
vtkm::Id inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
vtkm::Id init = 5;
const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 };
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment