Commit 9c1012b7 authored by Robert Maynard's avatar Robert Maynard
Browse files

Merge branch 'verify_permutation_array' into 'master'

Verify permutation array works with Sort and Reduce.

See merge request !46
parents bd62ec39 011b79ba
......@@ -36,11 +36,16 @@ class ArrayPortalPermutationExec
{
public:
typedef typename ValuePortalType::ValueType ValueType;
typedef ValueType IteratorType;
VTKM_EXEC_CONT_EXPORT
ArrayPortalPermutationExec( )
: IndexPortal(), ValuePortal() { }
VTKM_EXEC_CONT_EXPORT
ArrayPortalPermutationExec(
const IndexPortalType &indexPortal = IndexPortalType(),
const ValuePortalType &valuePortal = ValuePortalType())
const IndexPortalType &indexPortal,
const ValuePortalType &valuePortal)
: IndexPortal(indexPortal), ValuePortal(valuePortal) { }
/// Copy constructor for any other ArrayPortalPermutation with delegate
......@@ -55,7 +60,7 @@ public:
: IndexPortal(src.GetIndexPortal()), ValuePortal(src.GetValuePortal())
{ }
VTKM_EXEC_EXPORT
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
return this->IndexPortal.GetNumberOfValues();
}
......@@ -97,11 +102,16 @@ class ArrayPortalPermutationCont
{
public:
typedef typename ValuePortalType::ValueType ValueType;
typedef ValueType IteratorType;
VTKM_CONT_EXPORT
ArrayPortalPermutationCont( )
: IndexPortal(), ValuePortal() { }
VTKM_CONT_EXPORT
ArrayPortalPermutationCont(
const IndexPortalType &indexPortal = IndexPortalType(),
const ValuePortalType &valuePortal = ValuePortalType())
const IndexPortalType &indexPortal,
const ValuePortalType &valuePortal)
: IndexPortal(indexPortal), ValuePortal(valuePortal) { }
/// Copy constructor for any other ArrayPortalPermutation with delegate
......@@ -110,7 +120,7 @@ public:
/// const cast).
///
template<typename OtherIP, typename OtherVP>
VTKM_EXEC_CONT_EXPORT
VTKM_CONT_EXPORT
ArrayPortalPermutationCont(
const ArrayPortalPermutationCont<OtherIP,OtherVP> &src)
: IndexPortal(src.GetIndexPortal()), ValuePortal(src.GetValuePortal())
......
......@@ -22,12 +22,11 @@
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleZip.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/ArrayHandleZip.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleZip.h>
#include <vtkm/cont/ErrorControlOutOfMemory.h>
#include <vtkm/cont/ErrorExecution.h>
#include <vtkm/cont/StorageBasic.h>
......@@ -719,27 +718,10 @@ private:
vtkm::Id sorted2 = sorted.GetPortalConstControl().Get(i+1);
VTKM_TEST_ASSERT(sorted1 <= sorted2, "Values not properly sorted.");
}
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort of a ArrayHandleZip" << std::endl;
//verify that we can use ArrayHandleZip inplace
vtkm::cont::ArrayHandleZip< IdArrayHandle, IdArrayHandle> zipped(unsorted, sorted);
//verify we can use the default an custom operator sort with zip handle
Algorithm::Sort(zipped, comparison::SortGreater());
Algorithm::Sort(zipped);
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Pair<vtkm::Id,vtkm::Id> kv_sorted = zipped.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(( OFFSET + ( i / (ARRAY_SIZE/50)) ) == kv_sorted.first,
"ArrayZipHandle improperly sorted");
}
}
static VTKM_CONT_EXPORT void TestSortWithComparisonObject()
{
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort with comparison object" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
......@@ -778,6 +760,62 @@ private:
}
}
static VTKM_CONT_EXPORT void TestSortWithFancyArrays()
{
std::cout << "-------------------------------------------------" << std::endl;
std::cout << "Sort of a ArrayHandleZip" << std::endl;
vtkm::Id testData[ARRAY_SIZE];
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
testData[i]= OFFSET+((ARRAY_SIZE-i) % 50);
}
IdArrayHandle unsorted = MakeArrayHandle(testData, ARRAY_SIZE);
IdArrayHandle sorted;
Algorithm::Copy(unsorted, sorted);
//verify that we can use ArrayHandleZip inplace
vtkm::cont::ArrayHandleZip< IdArrayHandle, IdArrayHandle> zipped(unsorted, sorted);
//verify we can use sort with zip handle
Algorithm::Sort(zipped, comparison::SortGreater());
Algorithm::Sort(zipped);
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Pair<vtkm::Id,vtkm::Id> kv_sorted = zipped.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(( OFFSET + ( i / (ARRAY_SIZE/50)) ) == kv_sorted.first,
"ArrayZipHandle improperly sorted");
}
std::cout << "-------------------------------------------------" << std::endl;
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 >,
IdArrayHandle> perm(index, sorted);
//verify we can use a custom operator sort with permutation handle
Algorithm::Sort(perm, comparison::SortGreater());
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted_value = perm.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(( OFFSET + ( (ARRAY_SIZE-(i+1)) / (ARRAY_SIZE/50)) ) == sorted_value,
"ArrayZipPermutation improperly sorted");
}
//verify we can use the default sort with permutation handle
Algorithm::Sort(perm);
for (vtkm::Id i = 0; i < ARRAY_SIZE; ++i)
{
vtkm::Id sorted_value = perm.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(( OFFSET + ( i / (ARRAY_SIZE/50)) ) == sorted_value,
"ArrayZipPermutation improperly sorted");
}
}
static VTKM_CONT_EXPORT void TestSortByKey()
{
std::cout << "-------------------------------------------------" << std::endl;
......@@ -950,7 +988,6 @@ private:
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce" << std::endl;
{
//construct the index array
IdArrayHandle array;
Algorithm::Schedule(
......@@ -971,8 +1008,34 @@ private:
VTKM_TEST_ASSERT(reduce_sum == inclusive_sum,
"Got different sums from Reduce and ScanInclusive");
}
static VTKM_CONT_EXPORT void TestReduceWithComparisonObject()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with comparison object " << std::endl;
//construct the index array. Assign an abnormally large value
//to the middle of the array, that should be what we see as our sum.
vtkm::Id testData[ARRAY_SIZE];
const vtkm::Id maxValue = ARRAY_SIZE*2;
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
testData[i]= i;
}
testData[ARRAY_SIZE/2] = maxValue;
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
vtkm::Id largestValue = Algorithm::Reduce(input,
vtkm::Id(),
comparison::MaxValue());
VTKM_TEST_ASSERT(largestValue == maxValue,
"Got bad value from Reduce with comparison object");
}
static VTKM_CONT_EXPORT void TestReduceWithFancyArrays()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with ArrayHandleZip" << std::endl;
{
......@@ -1001,31 +1064,34 @@ private:
"Got bad sum from Reduce with initial value");
}
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with ArrayHandlePermutation" << std::endl;
{
//lastly test with heterogeneous zip values ( vec3, and constant array handle),
//and a custom reduce binary functor
const vtkm::Id indexLength = 30;
const vtkm::Id valuesLength = 10;
typedef vtkm::Float32 ValueType;
vtkm::Id indexs[indexLength] = {0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,
5,5,5,1,4,9,7,7,7,8,8,8,0,1,2};
ValueType values[valuesLength] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
6.0f, 7.0f, 8.0f, 9.0f, -2.0f};
const ValueType expectedSum = 125;
}
IdArrayHandle indexHandle = MakeArrayHandle(indexs, indexLength);
vtkm::cont::ArrayHandle<ValueType> valueHandle = MakeArrayHandle(values, valuesLength);
static VTKM_CONT_EXPORT void TestReduceWithComparisonObject()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce with comparison object " << std::endl;
vtkm::cont::ArrayHandlePermutation< IdArrayHandle, vtkm::cont::ArrayHandle<ValueType> > perm;
perm = vtkm::cont::make_ArrayHandlePermutation(indexHandle, valueHandle);
//construct the index array. Assign an abnormally large value
//to the middle of the array, that should be what we see as our sum.
vtkm::Id testData[ARRAY_SIZE];
const vtkm::Id maxValue = ARRAY_SIZE*2;
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
testData[i]= i;
}
testData[ARRAY_SIZE/2] = maxValue;
const ValueType sum = Algorithm::Reduce(perm, ValueType(0.0f));
IdArrayHandle input = MakeArrayHandle(testData, ARRAY_SIZE);
vtkm::Id largestValue = Algorithm::Reduce(input,
vtkm::Id(),
comparison::MaxValue());
std::cout << "sum: " << sum << std::endl;
VTKM_TEST_ASSERT( ( sum == expectedSum),
"Got bad sum from Reduce with permutation handle");
}
VTKM_TEST_ASSERT(largestValue == maxValue,
"Got bad value from Reduce with comparison object");
}
static VTKM_CONT_EXPORT void TestReduceByKey()
......@@ -1116,11 +1182,17 @@ private:
VTKM_TEST_ASSERT( expectedKeys[i] == k, "Incorrect reduced key");
VTKM_TEST_ASSERT( expectedValues[i] == v, "Incorrect reduced vale");
}
}
}
static VTKM_CONT_EXPORT void TestReduceByKeyWithFancyArrays()
{
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce By Key with Fancy Arrays" << std::endl;
//lastly test with heterogeneous zip values ( vec3, and constant array handle),
//and a custom reduce binary functor
{
const vtkm::Id inputLength = 30;
const vtkm::Id expectedLength = 10;
typedef vtkm::Float32 ValueType;
......@@ -1175,8 +1247,6 @@ private:
VTKM_TEST_ASSERT( expectedValues1[i] == v.first, "Incorrect reduced value1");
VTKM_TEST_ASSERT( expectedValues2[i] == v.second, "Incorrect reduced value2");
}
}
}
static VTKM_CONT_EXPORT void TestScanInclusive()
......@@ -1415,8 +1485,10 @@ private:
TestReduce();
TestReduceWithComparisonObject();
TestReduceWithFancyArrays();
TestReduceByKey();
TestReduceByKeyWithFancyArrays();
TestScanExclusive();
......@@ -1425,6 +1497,7 @@ private:
TestSort();
TestSortWithComparisonObject();
TestSortWithFancyArrays();
TestSortByKey();
TestLowerBoundsWithComparisonObject();
......
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