Commit 5b8389f9 authored by Kenneth Moreland's avatar Kenneth Moreland

Use printSummary_ArrayHandle when testing fancy arrays

This makes it easier to see what is going on in the fancy arrays and do
diagnostics.

This change required some changes to printSummary_ArrayHandle to support
more array types.
parent 873ceefc
......@@ -499,58 +499,119 @@ make_ArrayHandle(const std::vector<T,Allocator> &array)
}
}
template<typename T, typename StorageT>
namespace detail {
template<typename T>
VTKM_NEVER_EXPORT
VTKM_CONT
void
printSummary_ArrayHandle(const vtkm::cont::ArrayHandle<T,StorageT> &array,
std::ostream &out)
inline void printSummary_ArrayHandle_Value(const T &value,
std::ostream &out,
vtkm::VecTraitsTagSingleComponent)
{
vtkm::Id sz = array.GetNumberOfValues();
out<<"sz= "<<sz<<" [";
if (sz <= 7)
for (vtkm::Id i = 0 ; i < sz; i++)
{
out<<array.GetPortalConstControl().Get(i);
if (i != (sz-1)) out<<" ";
}
else
{
out<<array.GetPortalConstControl().Get(0)<<" ";
out<<array.GetPortalConstControl().Get(1)<<" ";
out<<array.GetPortalConstControl().Get(2);
out<<" ... ";
out<<array.GetPortalConstControl().Get(sz-3)<<" ";
out<<array.GetPortalConstControl().Get(sz-2)<<" ";
out<<array.GetPortalConstControl().Get(sz-1);
}
out<<"]";
out << value;
}
template<typename T>
VTKM_NEVER_EXPORT
VTKM_CONT
inline void printSummary_ArrayHandle_Value(const T &value,
std::ostream &out,
vtkm::VecTraitsTagMultipleComponents)
{
using Traits = vtkm::VecTraits<T>;
using ComponentType = typename Traits::ComponentType;
using IsVecOfVec = typename vtkm::VecTraits<ComponentType>::HasMultipleComponents;
vtkm::IdComponent numComponents = Traits::GetNumberOfComponents(value);
out << "(";
printSummary_ArrayHandle_Value(Traits::GetComponent(value,0), out, IsVecOfVec());
for (vtkm::IdComponent index = 1; index < numComponents; ++index)
{
out << ",";
printSummary_ArrayHandle_Value(Traits::GetComponent(value,index), out, IsVecOfVec());
}
out << ")";
}
VTKM_NEVER_EXPORT
VTKM_CONT
inline void printSummary_ArrayHandle_Value(UInt8 value,
std::ostream &out,
vtkm::VecTraitsTagSingleComponent)
{
out << static_cast<int>(value);
}
VTKM_NEVER_EXPORT
VTKM_CONT
inline void printSummary_ArrayHandle_Value(Int8 value,
std::ostream &out,
vtkm::VecTraitsTagSingleComponent)
{
out << static_cast<int>(value);
}
template<typename T1, typename T2>
VTKM_NEVER_EXPORT
VTKM_CONT
inline void printSummary_ArrayHandle_Value(const vtkm::Pair<T1,T2> &value,
std::ostream &out,
vtkm::VecTraitsTagSingleComponent)
{
out << "{";
printSummary_ArrayHandle_Value(
value.first,
out,
typename vtkm::VecTraits<T1>::HasMultipleComponents());
out << ",";
printSummary_ArrayHandle_Value(
value.second,
out,
typename vtkm::VecTraits<T2>::HasMultipleComponents());
out << "}";
}
template<typename StorageT>
} // namespace detail
template<typename T, typename StorageT>
VTKM_NEVER_EXPORT
VTKM_CONT
void
printSummary_ArrayHandle(const vtkm::cont::ArrayHandle<vtkm::UInt8,StorageT> &array,
inline void
printSummary_ArrayHandle(const vtkm::cont::ArrayHandle<T,StorageT> &array,
std::ostream &out)
{
vtkm::Id sz = array.GetNumberOfValues();
out<<"sz= "<<sz<<" [";
if (sz <= 7)
for (vtkm::Id i = 0 ; i < sz; i++)
{
out<<static_cast<int>(array.GetPortalConstControl().Get(i));
if (i != (sz-1)) out<<" ";
}
else
using ArrayType = vtkm::cont::ArrayHandle<T,StorageT>;
using PortalType = typename ArrayType::PortalConstControl;
using IsVec = typename vtkm::VecTraits<T>::HasMultipleComponents;
vtkm::Id sz = array.GetNumberOfValues();
out<<"sz= "<<sz<<" [";
PortalType portal = array.GetPortalConstControl();
if (sz <= 7)
{
for (vtkm::Id i = 0 ; i < sz; i++)
{
out<<static_cast<int>(array.GetPortalConstControl().Get(0))<<" ";
out<<static_cast<int>(array.GetPortalConstControl().Get(1))<<" ";
out<<static_cast<int>(array.GetPortalConstControl().Get(2));
out<<" ... ";
out<<static_cast<int>(array.GetPortalConstControl().Get(sz-3))<<" ";
out<<static_cast<int>(array.GetPortalConstControl().Get(sz-2))<<" ";
out<<static_cast<int>(array.GetPortalConstControl().Get(sz-1));
detail::printSummary_ArrayHandle_Value(portal.Get(i), out, IsVec());
if (i != (sz-1))
{
out<<" ";
}
}
out<<"]";
}
else
{
detail::printSummary_ArrayHandle_Value(portal.Get(0), out, IsVec());
out << " ";
detail::printSummary_ArrayHandle_Value(portal.Get(1), out, IsVec());
out << " ";
detail::printSummary_ArrayHandle_Value(portal.Get(2), out, IsVec());
out << " ... ";
detail::printSummary_ArrayHandle_Value(portal.Get(sz-3), out, IsVec());
out << " ";
detail::printSummary_ArrayHandle_Value(portal.Get(sz-2), out, IsVec());
out << " ";
detail::printSummary_ArrayHandle_Value(portal.Get(sz-1), out, IsVec());
}
out<<"]";
}
}
......
......@@ -39,6 +39,7 @@ template<>
struct VecTraits<std::string>
{
static const vtkm::IdComponent NUM_COMPONENTS = 1;
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent;
};
} // namespace vtkm
......
......@@ -167,6 +167,9 @@ private:
compositeInput, 1,
compositeInput, 2);
vtkm::cont::printSummary_ArrayHandle(composite, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< vtkm::Vec<ValueType, 3> > result;
vtkm::worklet::DispatcherMapField<PassThrough, DeviceAdapterTag> dispatcher;
......@@ -203,6 +206,9 @@ private:
vtkm::worklet::DispatcherMapField<PassThrough, DeviceAdapterTag> dispatcher;
dispatcher.Invoke(constant, result);
vtkm::cont::printSummary_ArrayHandle(constant, std::cout);
std::cout << std::endl;
//verify that the control portal works
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
......@@ -237,6 +243,9 @@ private:
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(counting, result);
vtkm::cont::printSummary_ArrayHandle(counting, std::cout);
std::cout << std::endl;
//verify that the control portal works
for(vtkm::Id i=0; i < length; ++i)
{
......@@ -264,6 +273,9 @@ private:
vtkm::cont::ArrayHandleImplicit< ValueType, FunctorType > implicit =
vtkm::cont::make_ArrayHandleImplicit<ValueType>(functor, length);
vtkm::cont::printSummary_ArrayHandle(implicit, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< ValueType > result;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
......@@ -300,7 +312,7 @@ private:
ConcatenateType;
FunctorType functor;
for( vtkm::Id start_pos = 0; start_pos < (length-10); start_pos+=10)
for( vtkm::Id start_pos = 0; start_pos < length; start_pos+=length/4)
{
vtkm::Id implicitLen = length - start_pos;
vtkm::Id basicLen = start_pos;
......@@ -321,6 +333,8 @@ private:
// concatenate two arrays together
ConcatenateType concatenate = vtkm::cont::make_ArrayHandleConcatenate
( implicit, basic );
vtkm::cont::printSummary_ArrayHandle(concatenate, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< ValueType > result;
......@@ -364,7 +378,7 @@ private:
> PermutationHandleType;
FunctorType functor;
for( vtkm::Id start_pos = 0; start_pos < (length-10); start_pos+=10)
for( vtkm::Id start_pos = 0; start_pos < length; start_pos+=length/4)
{
const vtkm::Id counting_length = length - start_pos;
......@@ -381,6 +395,9 @@ private:
vtkm::cont::make_ArrayHandlePermutation(counting,
implicit);
vtkm::cont::printSummary_ArrayHandle(permutation, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< ValueType > result;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
......@@ -423,27 +440,26 @@ private:
typedef typename vtkm::cont::ArrayHandle<ValueType>::PortalControl Portal;
input.Allocate(length);
Portal portal = input.GetPortalControl();
for(vtkm::Id i=0; i < length; ++i)
{
portal.Set(i, TestValue(i, ValueType()) );
}
SetPortal(input.GetPortalControl());
vtkm::cont::printSummary_ArrayHandle(transformed, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< ValueType > result;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(transformed, result);
//verify that the control portal works
for(vtkm::Id i=0; i < length; ++i)
//verify that the control portal works
for(vtkm::Id i=0; i < length; ++i)
{
const ValueType result_v = result.GetPortalConstControl().Get(i);
const ValueType correct_value = functor(TestValue(i, ValueType()));
const ValueType control_value = transformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Transform Handle Control Failed");
const ValueType result_v = result.GetPortalConstControl().Get(i);
const ValueType correct_value = functor(TestValue(i, ValueType()));
const ValueType control_value = transformed.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, correct_value),
"Transform Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Transform Handle Control Failed");
}
}
};
......@@ -477,6 +493,9 @@ private:
vtkm::cont::make_ArrayHandleTransform<OutputValueType>(counting,
functor);
vtkm::cont::printSummary_ArrayHandle(countingTransformed, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< OutputValueType > result;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
......@@ -516,6 +535,9 @@ private:
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(castArray, result);
vtkm::cont::printSummary_ArrayHandle(castArray, std::cout);
std::cout << std::endl;
// verify results
vtkm::Id length = ARRAY_SIZE;
for (vtkm::Id i = 0; i < length; ++i)
......@@ -552,6 +574,9 @@ private:
VTKM_TEST_ASSERT(groupArray.GetNumberOfValues() == ARRAY_SIZE,
"Group array reporting wrong array size.");
vtkm::cont::printSummary_ArrayHandle(groupArray, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle<ValueType> resultArray;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
......@@ -588,14 +613,9 @@ private:
{
typedef vtkm::Vec<ComponentType, NUM_COMPONENTS> ValueType;
ValueType testValues[ARRAY_SIZE];
for(vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
testValues[index] = TestValue(index, ValueType());
}
vtkm::cont::ArrayHandle<ValueType> baseArray =
vtkm::cont::make_ArrayHandle(testValues, ARRAY_SIZE);
vtkm::cont::ArrayHandle<ValueType> baseArray;
baseArray.Allocate(ARRAY_SIZE);
SetPortal(baseArray.GetPortalControl());
vtkm::cont::ArrayHandle<ComponentType> resultArray;
......@@ -606,6 +626,11 @@ private:
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(baseArray, groupArray);
vtkm::cont::printSummary_ArrayHandle(groupArray, std::cout);
std::cout << std::endl;
vtkm::cont::printSummary_ArrayHandle(resultArray, std::cout);
std::cout << std::endl;
VTKM_TEST_ASSERT(groupArray.GetNumberOfValues() == ARRAY_SIZE,
"Group array reporting wrong array size.");
......@@ -685,6 +710,12 @@ private:
sourceArray.Allocate(sourceArraySize);
SetPortal(sourceArray.GetPortalControl());
vtkm::cont::printSummary_ArrayHandle(
vtkm::cont::make_ArrayHandleGroupVecVariable(sourceArray,
offsetsArray),
std::cout);
std::cout << std::endl;
vtkm::worklet::DispatcherMapField<GroupVariableInputWorklet,DeviceAdapterTag> dispatcher;
dispatcher.Invoke(
vtkm::cont::make_ArrayHandleGroupVecVariable(
......@@ -746,6 +777,14 @@ private:
vtkm::cont::make_ArrayHandleGroupVecVariable(
sourceArray, offsetsArray));
vtkm::cont::printSummary_ArrayHandle(
vtkm::cont::make_ArrayHandleGroupVecVariable(sourceArray,
offsetsArray),
std::cout);
std::cout << std::endl;
vtkm::cont::printSummary_ArrayHandle(sourceArray, std::cout);
std::cout << std::endl;
CheckPortal(sourceArray.GetPortalConstControl());
}
};
......@@ -779,6 +818,9 @@ private:
vtkm::cont::ArrayHandle< ValueType > > zip =
vtkm::cont::make_ArrayHandleZip(keys, values);
vtkm::cont::printSummary_ArrayHandle(zip, std::cout);
std::cout << std::endl;
vtkm::cont::ArrayHandle< PairType > result;
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
......@@ -862,6 +904,9 @@ private:
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(input, permutation);
vtkm::cont::printSummary_ArrayHandle(permutation, std::cout);
std::cout << std::endl;
//verify that the control portal works
for(vtkm::Id i=0; i <length; ++i)
{
......@@ -904,6 +949,9 @@ private:
vtkm::worklet::DispatcherMapField< PassThrough, DeviceAdapterTag > dispatcher;
dispatcher.Invoke(input, result_zip);
vtkm::cont::printSummary_ArrayHandle(result_zip, std::cout);
std::cout << std::endl;
//now the two arrays we have zipped should have data inside them
for(int i=0; i < ARRAY_SIZE; ++i)
{
......@@ -936,6 +984,9 @@ private:
vtkm::worklet::DispatcherMapField<InplaceFunctorPair,DeviceAdapterTag> dispatcher;
dispatcher.Invoke(vtkm::cont::make_ArrayHandleZip(inputValues,outputValues));
vtkm::cont::printSummary_ArrayHandle(outputValues, std::cout);
std::cout << std::endl;
CheckPortal(outputValues.GetPortalConstControl());
}
};
......
......@@ -54,6 +54,7 @@ template<>
struct VecTraits<std::string>
{
static const vtkm::IdComponent NUM_COMPONENTS = 1;
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent;
};
} // namespace vtkm
......
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