mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Remove GetIteratorBegin/End from all ArrayPortal classes.
Replace them (and their use) with the new ArrayPortalToIterators functionality.
This commit is contained in:
parent
9bbbaecab6
commit
8839e615e6
@ -254,19 +254,6 @@ public:
|
||||
throw vtkm::cont::ErrorControlInternal("Not implemented.");
|
||||
}
|
||||
|
||||
// Not a viable type, but there is no implementation.
|
||||
typedef ValueType *IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
throw vtkm::cont::ErrorControlInternal("Not implemented.");
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
throw vtkm::cont::ErrorControlInternal("Not implemented.");
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Id NumberOfValues;
|
||||
};
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/StorageImplicit.h>
|
||||
|
||||
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
@ -72,21 +70,6 @@ public:
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const { return StartingValue+ValueType(index); }
|
||||
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<
|
||||
ArrayPortalCounting < CountingValueType> > IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const
|
||||
{
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const
|
||||
{
|
||||
return IteratorType(*this, this->NumberOfValues);
|
||||
}
|
||||
|
||||
private:
|
||||
ValueType StartingValue;
|
||||
vtkm::Id NumberOfValues;
|
||||
|
@ -25,8 +25,6 @@
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/StorageImplicit.h>
|
||||
|
||||
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
@ -93,19 +91,6 @@ public:
|
||||
return this->GetCoordinatesForTopologyIndex(index + this->Extent.Min);
|
||||
}
|
||||
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<
|
||||
ArrayPortalUniformPointCoordinates> IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
return IteratorType(*this, this->NumberOfValues);
|
||||
}
|
||||
|
||||
private:
|
||||
vtkm::Extent3 Extent;
|
||||
vtkm::Id3 Dimensions;
|
||||
|
@ -78,25 +78,6 @@ public:
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
void Set(vtkm::Id index, const ValueType &value) const;
|
||||
|
||||
/// An iterator type that can be used as an alternate way to access the data.
|
||||
/// If the container being pointed to has a natural iterator that can be
|
||||
/// used, then use that. Otherwise, use IteratorForArrayPortal. Iterators are
|
||||
/// not necessary for array portals in the execution environment.
|
||||
///
|
||||
typedef ValueType *IteratorType;
|
||||
|
||||
/// Returns an iterator to the beginning of the array. Iterators are not
|
||||
/// necessary for array portals in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const;
|
||||
|
||||
/// Returns an iterator to the end of the array. Iterators are not necessary
|
||||
/// for array portals in the execution environment.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const;
|
||||
};
|
||||
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
@ -147,8 +147,7 @@ public:
|
||||
|
||||
/// \brief Frees any resources (i.e. memory) stored in this array.
|
||||
///
|
||||
/// After calling this method GetNumberOfValues will return 0 and
|
||||
/// GetIteratorBegin and GetIteratorEnd will return the same iterator. The
|
||||
/// After calling this method GetNumberOfValues will return 0. The
|
||||
/// resources should also be released when the Storage class is
|
||||
/// destroyed.
|
||||
VTKM_CONT_EXPORT
|
||||
|
@ -98,14 +98,12 @@ public:
|
||||
}
|
||||
|
||||
/// This method is a no-op (except for a few checks). Any data written to
|
||||
/// this class's iterators should already be written to the given \c
|
||||
/// this class's portals should already be written to the given \c
|
||||
/// controlArray (under correct operation).
|
||||
///
|
||||
VTKM_CONT_EXPORT void RetrieveOutputData(StorageType &controlArray) const
|
||||
{
|
||||
VTKM_ASSERT_CONT(this->ConstPortalValid);
|
||||
VTKM_ASSERT_CONT(controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
this->ConstPortal.GetIteratorBegin());
|
||||
controlArray.Shrink(this->ConstPortal.GetNumberOfValues());
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortal.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
#include <iterator>
|
||||
@ -76,30 +77,6 @@ public:
|
||||
*this->IteratorAt(index) = value;
|
||||
}
|
||||
|
||||
#ifndef VTKM_MSVC
|
||||
typedef IteratorT IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const { return this->BeginIterator; }
|
||||
#else // VTKM_MSVC
|
||||
// The MSVC compiler issues warnings if you use raw pointers with some
|
||||
// operations. To keep the compiler happy (and add some safety checks),
|
||||
// wrap the iterator in a check.
|
||||
typedef stdext::checked_array_iterator<IteratorT> IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return IteratorType(this->BeginIterator, this->GetNumberOfValues());
|
||||
}
|
||||
#endif // VTKM_MSVC
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
IteratorType iterator = this->GetIteratorBegin();
|
||||
std::advance(iterator, this->GetNumberOfValues());
|
||||
return iterator;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorT GetRawIterator() const {
|
||||
return this->BeginIterator;
|
||||
@ -123,4 +100,59 @@ private:
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
/// Partial specialization of \c ArrayPortalToIterators for \c
|
||||
/// ArrayPortalFromIterators. Returns the original array rather than
|
||||
/// the portal wrapped in an \c IteratorFromArrayPortal.
|
||||
///
|
||||
template<typename _IteratorType>
|
||||
class ArrayPortalToIterators<
|
||||
vtkm::cont::internal::ArrayPortalFromIterators<_IteratorType> >
|
||||
{
|
||||
typedef vtkm::cont::internal::ArrayPortalFromIterators<_IteratorType>
|
||||
PortalType;
|
||||
public:
|
||||
#ifndef VTKM_MSVC
|
||||
typedef _IteratorType IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalToIterators(const PortalType &portal)
|
||||
: Iterator(portal.GetRawIterator()),
|
||||
NumberOfValues(portal.GetNumberOfValues())
|
||||
{ }
|
||||
|
||||
#else // VTKM_MSVC
|
||||
// The MSVC compiler issues warnings if you use raw pointers with some
|
||||
// operations. To keep the compiler happy (and add some safety checks),
|
||||
// wrap the iterator in a check.
|
||||
typedef stdext::checked_array_iterator<_IteratorType> IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalToIterators(const PortalType &portal)
|
||||
: Iterator(portal.GetRawIterator(), portal.GetNumberOfValues()),
|
||||
NumberOfValues(portal.GetNumberOfValues())
|
||||
{ }
|
||||
|
||||
#endif // VTKM_MSVC
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetBegin() const { return this->Iterator; }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetEnd() const {
|
||||
IteratorType iterator = this->Iterator;
|
||||
std::advance(iterator, this->NumberOfValues);
|
||||
return iterator;
|
||||
}
|
||||
|
||||
private:
|
||||
IteratorType Iterator;
|
||||
vtkm::Id NumberOfValues;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtk_m_cont_internal_ArrayPortalFromIterators_h
|
||||
|
@ -22,8 +22,11 @@
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayPortal.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/Assert.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace internal {
|
||||
@ -38,7 +41,6 @@ public:
|
||||
typedef PortalT DelegatePortalType;
|
||||
|
||||
typedef typename DelegatePortalType::ValueType ValueType;
|
||||
typedef typename DelegatePortalType::IteratorType IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT ArrayPortalShrink() : NumberOfValues(0) { }
|
||||
|
||||
@ -84,20 +86,6 @@ public:
|
||||
this->DelegatePortal.Set(index, value);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const
|
||||
{
|
||||
return this->DelegatePortal.GetIteratorBegin();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const
|
||||
{
|
||||
IteratorType iterator = this->DelegatePortal.GetIteratorBegin();
|
||||
std::advance(iterator, this->GetNumberOfValues());
|
||||
return iterator;
|
||||
}
|
||||
|
||||
/// Special method in this ArrayPortal that allows you to shrink the
|
||||
/// (exposed) array.
|
||||
///
|
||||
@ -123,4 +111,45 @@ private:
|
||||
}
|
||||
} // namespace vtkm::cont::internal
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
template<typename DelegatePortalType>
|
||||
class ArrayPortalToIterators<
|
||||
vtkm::cont::internal::ArrayPortalShrink<DelegatePortalType> >
|
||||
{
|
||||
typedef vtkm::cont::internal::ArrayPortalShrink<DelegatePortalType>
|
||||
PortalType;
|
||||
typedef vtkm::cont::ArrayPortalToIterators<DelegatePortalType>
|
||||
DelegateArrayPortalToIterators;
|
||||
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
ArrayPortalToIterators(const PortalType &portal)
|
||||
: DelegateIterators(portal.GetDelegatePortal()),
|
||||
NumberOfValues(portal.GetNumberOfValues())
|
||||
{ }
|
||||
|
||||
typedef typename DelegateArrayPortalToIterators::IteratorType IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetBegin() const {
|
||||
return this->DelegateIterators.GetBegin();
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetEnd() const {
|
||||
IteratorType iterator = this->GetBegin();
|
||||
std::advance(iterator, this->NumberOfValues);
|
||||
return iterator;
|
||||
}
|
||||
|
||||
private:
|
||||
DelegateArrayPortalToIterators DelegateIterators;
|
||||
vtkm::Id NumberOfValues;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
||||
#endif //vtk_m_cont_internal_ArrayPortalShrink_h
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/StorageBasic.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
@ -207,14 +208,17 @@ private:
|
||||
// necessarily true, but it is true for the current uses of this general
|
||||
// function and I don't want to compete with STL if I don't have to.
|
||||
|
||||
typename InputPortalType::IteratorType resultPos =
|
||||
std::lower_bound(this->InputPortal.GetIteratorBegin(),
|
||||
this->InputPortal.GetIteratorEnd(),
|
||||
typedef vtkm::cont::ArrayPortalToIterators<InputPortalType>
|
||||
InputIteratorsType;
|
||||
InputIteratorsType inputIterators(this->InputPortal);
|
||||
typename InputIteratorsType::IteratorType resultPos =
|
||||
std::lower_bound(inputIterators.GetBegin(),
|
||||
inputIterators.GetEnd(),
|
||||
this->ValuesPortal.Get(index));
|
||||
|
||||
vtkm::Id resultIndex =
|
||||
static_cast<vtkm::Id>(
|
||||
std::distance(this->InputPortal.GetIteratorBegin(), resultPos));
|
||||
std::distance(inputIterators.GetBegin(), resultPos));
|
||||
this->OutputPortal.Set(index, resultIndex);
|
||||
}
|
||||
|
||||
@ -251,15 +255,18 @@ private:
|
||||
// necessarily true, but it is true for the current uses of this general
|
||||
// function and I don't want to compete with STL if I don't have to.
|
||||
|
||||
typename InputPortalType::IteratorType resultPos =
|
||||
std::lower_bound(this->InputPortal.GetIteratorBegin(),
|
||||
this->InputPortal.GetIteratorEnd(),
|
||||
typedef vtkm::cont::ArrayPortalToIterators<InputPortalType>
|
||||
InputIteratorsType;
|
||||
InputIteratorsType inputIterators(this->InputPortal);
|
||||
typename InputIteratorsType::IteratorType resultPos =
|
||||
std::lower_bound(inputIterators.GetBegin(),
|
||||
inputIterators.GetEnd(),
|
||||
this->ValuesPortal.Get(index),
|
||||
this->CompareFunctor);
|
||||
|
||||
vtkm::Id resultIndex =
|
||||
static_cast<vtkm::Id>(
|
||||
std::distance(this->InputPortal.GetIteratorBegin(), resultPos));
|
||||
std::distance(inputIterators.GetBegin(), resultPos));
|
||||
this->OutputPortal.Set(index, resultIndex);
|
||||
}
|
||||
|
||||
@ -886,14 +893,17 @@ private:
|
||||
// necessarily true, but it is true for the current uses of this general
|
||||
// function and I don't want to compete with STL if I don't have to.
|
||||
|
||||
typename InputPortalType::IteratorType resultPos =
|
||||
std::upper_bound(this->InputPortal.GetIteratorBegin(),
|
||||
this->InputPortal.GetIteratorEnd(),
|
||||
typedef vtkm::cont::ArrayPortalToIterators<InputPortalType>
|
||||
InputIteratorsType;
|
||||
InputIteratorsType inputIterators(this->InputPortal);
|
||||
typename InputIteratorsType::IteratorType resultPos =
|
||||
std::upper_bound(inputIterators.GetBegin(),
|
||||
inputIterators.GetEnd(),
|
||||
this->ValuesPortal.Get(index));
|
||||
|
||||
vtkm::Id resultIndex =
|
||||
static_cast<vtkm::Id>(
|
||||
std::distance(this->InputPortal.GetIteratorBegin(), resultPos));
|
||||
std::distance(inputIterators.GetBegin(), resultPos));
|
||||
this->OutputPortal.Set(index, resultIndex);
|
||||
}
|
||||
|
||||
@ -931,15 +941,18 @@ private:
|
||||
// necessarily true, but it is true for the current uses of this general
|
||||
// function and I don't want to compete with STL if I don't have to.
|
||||
|
||||
typename InputPortalType::IteratorType resultPos =
|
||||
std::upper_bound(this->InputPortal.GetIteratorBegin(),
|
||||
this->InputPortal.GetIteratorEnd(),
|
||||
typedef vtkm::cont::ArrayPortalToIterators<InputPortalType>
|
||||
InputIteratorsType;
|
||||
InputIteratorsType inputIterators(this->InputPortal);
|
||||
typename InputIteratorsType::IteratorType resultPos =
|
||||
std::upper_bound(inputIterators.GetBegin(),
|
||||
inputIterators.GetEnd(),
|
||||
this->ValuesPortal.Get(index),
|
||||
this->CompareFunctor);
|
||||
|
||||
vtkm::Id resultIndex =
|
||||
static_cast<vtkm::Id>(
|
||||
std::distance(this->InputPortal.GetIteratorBegin(), resultPos));
|
||||
std::distance(inputIterators.GetBegin(), resultPos));
|
||||
this->OutputPortal.Set(index, resultIndex);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_cont_internal_DeviceAdapterAlgorithmSerial_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/ErrorExecution.h>
|
||||
#include <vtkm/cont/internal/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h>
|
||||
@ -64,9 +65,9 @@ public:
|
||||
|
||||
if (numberOfValues <= 0) { return 0; }
|
||||
|
||||
std::partial_sum(inputPortal.GetIteratorBegin(),
|
||||
inputPortal.GetIteratorEnd(),
|
||||
outputPortal.GetIteratorBegin());
|
||||
std::partial_sum(vtkm::cont::ArrayPortalToIteratorBegin(inputPortal),
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(inputPortal),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(outputPortal));
|
||||
|
||||
// Return the value at the last index in the array, which is the full sum.
|
||||
return outputPortal.Get(numberOfValues - 1);
|
||||
@ -89,16 +90,16 @@ public:
|
||||
|
||||
if (numberOfValues <= 0) { return 0; }
|
||||
|
||||
std::partial_sum(inputPortal.GetIteratorBegin(),
|
||||
inputPortal.GetIteratorEnd(),
|
||||
outputPortal.GetIteratorBegin());
|
||||
std::partial_sum(vtkm::cont::ArrayPortalToIteratorBegin(inputPortal),
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(inputPortal),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(outputPortal));
|
||||
|
||||
T fullSum = outputPortal.Get(numberOfValues - 1);
|
||||
|
||||
// Shift right by one
|
||||
std::copy_backward(outputPortal.GetIteratorBegin(),
|
||||
outputPortal.GetIteratorEnd()-1,
|
||||
outputPortal.GetIteratorEnd());
|
||||
std::copy_backward(vtkm::cont::ArrayPortalToIteratorBegin(outputPortal),
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(outputPortal)-1,
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(outputPortal));
|
||||
outputPortal.Set(0, 0);
|
||||
return fullSum;
|
||||
}
|
||||
@ -163,7 +164,8 @@ public:
|
||||
::template ExecutionTypes<Device>::Portal PortalType;
|
||||
|
||||
PortalType arrayPortal = values.PrepareForInPlace(Device());
|
||||
std::sort(arrayPortal.GetIteratorBegin(), arrayPortal.GetIteratorEnd());
|
||||
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(arrayPortal);
|
||||
std::sort(iterators.GetBegin(), iterators.GetEnd());
|
||||
}
|
||||
|
||||
template<typename T, class Storage, class Compare>
|
||||
@ -174,7 +176,8 @@ public:
|
||||
::template ExecutionTypes<Device>::Portal PortalType;
|
||||
|
||||
PortalType arrayPortal = values.PrepareForInPlace(Device());
|
||||
std::sort(arrayPortal.GetIteratorBegin(), arrayPortal.GetIteratorEnd(),comp);
|
||||
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(arrayPortal);
|
||||
std::sort(iterators.GetBegin(), iterators.GetEnd(), comp);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT static void Synchronize()
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h>
|
||||
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/StorageBasic.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -43,33 +44,29 @@ struct TemplatedTests
|
||||
|
||||
void SetStorage(StorageType &array, const ValueType& value)
|
||||
{
|
||||
std::fill(array.GetPortal().GetIteratorBegin(),
|
||||
array.GetPortal().GetIteratorEnd(),
|
||||
value);
|
||||
vtkm::cont::ArrayPortalToIterators<typename StorageType::PortalType>
|
||||
iterators(array.GetPortal());
|
||||
std::fill(iterators.GetBegin(), iterators.GetEnd(), value);
|
||||
}
|
||||
|
||||
template <class IteratorType>
|
||||
bool CheckArray(IteratorType begin, IteratorType end, const ValueType& value)
|
||||
template <class PortalType>
|
||||
bool CheckPortal(const PortalType &portal, const ValueType &value)
|
||||
{
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
if (!test_equal(*iter, value)) { return false; }
|
||||
if (!test_equal(portal.Get(index), value)) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckStorage(StorageType &array, const ValueType& value)
|
||||
{
|
||||
return CheckArray(array.GetPortalConst().GetIteratorBegin(),
|
||||
array.GetPortalConst().GetIteratorEnd(),
|
||||
value);
|
||||
return CheckPortal(array.GetPortalConst(), value);
|
||||
}
|
||||
|
||||
bool CheckManager(ArrayManagerType &manager, const ValueType &value)
|
||||
{
|
||||
return CheckArray(manager.GetPortalConst().GetIteratorBegin(),
|
||||
manager.GetPortalConst().GetIteratorEnd(),
|
||||
value);
|
||||
return CheckPortal(manager.GetPortalConst(), value);
|
||||
}
|
||||
|
||||
void InputData()
|
||||
@ -87,8 +84,8 @@ struct TemplatedTests
|
||||
// control array portal in a different array portal, it should still
|
||||
// give the same iterator (to avoid any unnecessary indirection).
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
executionArray.GetPortalConst().GetIteratorBegin(),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(controlArray.GetPortalConst()) ==
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(executionArray.GetPortalConst()),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
|
||||
VTKM_TEST_ASSERT(CheckManager(executionArray, INPUT_VALUE),
|
||||
@ -110,12 +107,12 @@ struct TemplatedTests
|
||||
// control array portal in a different array portal, it should still
|
||||
// give the same iterator (to avoid any unnecessary indirection).
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortal().GetIteratorBegin() ==
|
||||
executionArray.GetPortal().GetIteratorBegin(),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(controlArray.GetPortal()) ==
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(executionArray.GetPortal()),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
VTKM_TEST_ASSERT(
|
||||
controlArray.GetPortalConst().GetIteratorBegin() ==
|
||||
executionArray.GetPortalConst().GetIteratorBegin(),
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(controlArray.GetPortalConst()) ==
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(executionArray.GetPortalConst()),
|
||||
"Execution array manager not holding control array iterators.");
|
||||
|
||||
VTKM_TEST_ASSERT(CheckManager(executionArray, INPUT_VALUE),
|
||||
@ -131,9 +128,9 @@ struct TemplatedTests
|
||||
ArrayManagerType executionArray;
|
||||
executionArray.AllocateArrayForOutput(controlArray, ARRAY_SIZE);
|
||||
|
||||
std::fill(executionArray.GetPortal().GetIteratorBegin(),
|
||||
executionArray.GetPortal().GetIteratorEnd(),
|
||||
OUTPUT_VALUE);
|
||||
vtkm::cont::ArrayPortalToIterators<typename ArrayManagerType::PortalType>
|
||||
iterators(executionArray.GetPortal());
|
||||
std::fill(iterators.GetBegin(), iterators.GetEnd(), OUTPUT_VALUE);
|
||||
|
||||
VTKM_TEST_ASSERT(CheckManager(executionArray, OUTPUT_VALUE),
|
||||
"Did not get correct array back.");
|
||||
|
@ -63,6 +63,13 @@ struct TemplatedTests
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class PortalType>
|
||||
bool CheckPortal(const PortalType &portal, ComponentType value)
|
||||
{
|
||||
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
||||
return CheckIterator(iterators.GetBegin(), iterators.GetEnd(), value);
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
ValueType array[ARRAY_SIZE];
|
||||
@ -71,9 +78,26 @@ struct TemplatedTests
|
||||
FillIterator(array, array+ARRAY_SIZE, ORIGINAL_VALUE);
|
||||
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<ValueType *>
|
||||
portal(array, array+ARRAY_SIZE);
|
||||
portal(array, array+ARRAY_SIZE);
|
||||
::vtkm::cont::internal::ArrayPortalFromIterators<const ValueType *>
|
||||
const_portal(array, array+ARRAY_SIZE);
|
||||
const_portal(array, array+ARRAY_SIZE);
|
||||
|
||||
std::cout << " Check that ArrayPortalToIterators is not doing indirection."
|
||||
<< std::endl;
|
||||
// If you get a compile error here about mismatched types, it might be
|
||||
// that ArrayPortalToIterators is not properly overloaded to return the
|
||||
// original iterator.
|
||||
VTKM_TEST_ASSERT(vtkm::cont::ArrayPortalToIteratorBegin(portal) == array,
|
||||
"Begin iterator wrong.");
|
||||
VTKM_TEST_ASSERT(vtkm::cont::ArrayPortalToIteratorEnd(portal) ==
|
||||
array+ARRAY_SIZE,
|
||||
"End iterator wrong.");
|
||||
VTKM_TEST_ASSERT(vtkm::cont::ArrayPortalToIteratorBegin(const_portal) ==
|
||||
array,
|
||||
"Begin const iterator wrong.");
|
||||
VTKM_TEST_ASSERT(vtkm::cont::ArrayPortalToIteratorEnd(const_portal) ==
|
||||
array+ARRAY_SIZE,
|
||||
"End const iterator wrong.");
|
||||
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Portal array size wrong.");
|
||||
@ -81,13 +105,9 @@ struct TemplatedTests
|
||||
"Const portal array size wrong.");
|
||||
|
||||
std::cout << " Check inital value." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
ORIGINAL_VALUE),
|
||||
VTKM_TEST_ASSERT(CheckPortal(portal, ORIGINAL_VALUE),
|
||||
"Portal iterator has bad value.");
|
||||
VTKM_TEST_ASSERT(CheckIterator(const_portal.GetIteratorBegin(),
|
||||
const_portal.GetIteratorEnd(),
|
||||
ORIGINAL_VALUE),
|
||||
VTKM_TEST_ASSERT(CheckPortal(const_portal, ORIGINAL_VALUE),
|
||||
"Const portal iterator has bad value.");
|
||||
|
||||
static const ComponentType SET_VALUE = 562;
|
||||
@ -106,9 +126,7 @@ struct TemplatedTests
|
||||
}
|
||||
|
||||
std::cout << " Make sure set has correct value." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
SET_VALUE),
|
||||
VTKM_TEST_ASSERT(CheckPortal(portal, SET_VALUE),
|
||||
"Portal iterator has bad value.");
|
||||
VTKM_TEST_ASSERT(CheckIterator(array, array+ARRAY_SIZE, SET_VALUE),
|
||||
"Array has bad value.");
|
||||
|
@ -65,6 +65,13 @@ struct TemplatedTests
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class PortalType>
|
||||
bool CheckPortal(const PortalType &portal, const ComponentType &value)
|
||||
{
|
||||
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
||||
return CheckIterator(iterators.GetBegin(), iterators.GetEnd(), value);
|
||||
}
|
||||
|
||||
ComponentType ORIGINAL_VALUE() { return 239; }
|
||||
|
||||
template<class ArrayPortalType>
|
||||
@ -114,9 +121,7 @@ struct TemplatedTests
|
||||
FillIterator(begin, end, WRITE_VALUE);
|
||||
|
||||
std::cout << " Check values in portal." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckIterator(portal.GetIteratorBegin(),
|
||||
portal.GetIteratorEnd(),
|
||||
WRITE_VALUE),
|
||||
VTKM_TEST_ASSERT(CheckPortal(portal, WRITE_VALUE),
|
||||
"Did not get correct values when writing to iterator.");
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define vtk_m_cont_testing_TestingDeviceAdapter_h
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/ErrorControlOutOfMemory.h>
|
||||
#include <vtkm/cont/ErrorExecution.h>
|
||||
#include <vtkm/cont/StorageBasic.h>
|
||||
@ -376,9 +377,10 @@ private:
|
||||
|
||||
// Copy array back.
|
||||
vtkm::Scalar outputArray[ARRAY_SIZE];
|
||||
std::copy(inputManager.GetPortalConst().GetIteratorBegin(),
|
||||
inputManager.GetPortalConst().GetIteratorEnd(),
|
||||
outputArray);
|
||||
vtkm::cont::ArrayPortalToIterators<
|
||||
typename ArrayManagerExecution::PortalConstType>
|
||||
iterators(inputManager.GetPortalConst());
|
||||
std::copy(iterators.GetBegin(), iterators.GetEnd(), outputArray);
|
||||
|
||||
// Check array.
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
@ -757,9 +759,10 @@ private:
|
||||
VTKM_TEST_ASSERT(handle.GetNumberOfValues() == RANDOMDATA_SIZE,
|
||||
"LowerBounds returned incorrect size");
|
||||
|
||||
std::copy(handle.GetPortalConstControl().GetIteratorBegin(),
|
||||
handle.GetPortalConstControl().GetIteratorEnd(),
|
||||
randomData);
|
||||
std::copy(
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(handle.GetPortalConstControl()),
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(handle.GetPortalConstControl()),
|
||||
randomData);
|
||||
VTKM_TEST_ASSERT(randomData[0] == 2, "Got bad value - LowerBounds");
|
||||
VTKM_TEST_ASSERT(randomData[1] == 3, "Got bad value - LowerBounds");
|
||||
VTKM_TEST_ASSERT(randomData[2] == 3, "Got bad value - LowerBounds");
|
||||
@ -770,9 +773,10 @@ private:
|
||||
VTKM_TEST_ASSERT(handle1.GetNumberOfValues() == RANDOMDATA_SIZE,
|
||||
"UppererBounds returned incorrect size");
|
||||
|
||||
std::copy(handle1.GetPortalConstControl().GetIteratorBegin(),
|
||||
handle1.GetPortalConstControl().GetIteratorEnd(),
|
||||
randomData);
|
||||
std::copy(
|
||||
vtkm::cont::ArrayPortalToIteratorBegin(handle1.GetPortalConstControl()),
|
||||
vtkm::cont::ArrayPortalToIteratorEnd(handle1.GetPortalConstControl()),
|
||||
randomData);
|
||||
VTKM_TEST_ASSERT(randomData[0] == 3, "Got bad value - UpperBound");
|
||||
VTKM_TEST_ASSERT(randomData[1] == 4, "Got bad value - UpperBound");
|
||||
VTKM_TEST_ASSERT(randomData[2] == 4, "Got bad value - UpperBound");
|
||||
|
@ -38,7 +38,7 @@ vtkm::Scalar TestValue(vtkm::Id index)
|
||||
}
|
||||
|
||||
template<class IteratorType>
|
||||
bool CheckValues(IteratorType begin, IteratorType end)
|
||||
bool CheckIterators(IteratorType begin, IteratorType end)
|
||||
{
|
||||
vtkm::Id index = 0;
|
||||
for (IteratorType iter = begin; iter != end; iter++)
|
||||
@ -49,11 +49,17 @@ bool CheckValues(IteratorType begin, IteratorType end)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool CheckValues(const vtkm::cont::ArrayHandle<T> &handle)
|
||||
template<class PortalType>
|
||||
bool CheckPortal(const PortalType &portal)
|
||||
{
|
||||
return CheckValues(handle.GetPortalConstControl().GetIteratorBegin(),
|
||||
handle.GetPortalConstControl().GetIteratorEnd());
|
||||
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
||||
return CheckIterators(iterators.GetBegin(), iterators.GetEnd());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool CheckArray(const vtkm::cont::ArrayHandle<T> &handle)
|
||||
{
|
||||
return CheckPortal(handle.GetPortalConstControl());
|
||||
}
|
||||
|
||||
void TestArrayHandle()
|
||||
@ -75,7 +81,7 @@ void TestArrayHandle()
|
||||
"ArrayHandle has wrong number of entries.");
|
||||
|
||||
std::cout << "Check basic array." << std::endl;
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
|
||||
"Array values not set correctly.");
|
||||
|
||||
std::cout << "Check out execution array behavior." << std::endl;
|
||||
@ -85,8 +91,7 @@ void TestArrayHandle()
|
||||
executionPortal;
|
||||
executionPortal =
|
||||
arrayHandle.PrepareForInput(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
VTKM_TEST_ASSERT(CheckValues(executionPortal.GetIteratorBegin(),
|
||||
executionPortal.GetIteratorEnd()),
|
||||
VTKM_TEST_ASSERT(CheckPortal(executionPortal),
|
||||
"Array not copied to execution correctly.");
|
||||
}
|
||||
|
||||
@ -112,26 +117,23 @@ void TestArrayHandle()
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForOutput(ARRAY_SIZE*2,
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
vtkm::Id index = 0;
|
||||
for (ExecutionPortalType::IteratorType iter =
|
||||
executionPortal.GetIteratorBegin();
|
||||
iter != executionPortal.GetIteratorEnd();
|
||||
iter++)
|
||||
for (vtkm::Id index = 0;
|
||||
index < executionPortal.GetNumberOfValues();
|
||||
index++)
|
||||
{
|
||||
*iter = TestValue(index);
|
||||
index++;
|
||||
executionPortal.Set(index, TestValue(index));
|
||||
}
|
||||
}
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE*2,
|
||||
"Array not allocated correctly.");
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
|
||||
"Array values not retrieved from execution.");
|
||||
|
||||
std::cout << "Try shrinking the array." << std::endl;
|
||||
arrayHandle.Shrink(ARRAY_SIZE);
|
||||
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"Array size did not shrink correctly.");
|
||||
VTKM_TEST_ASSERT(CheckValues(arrayHandle),
|
||||
VTKM_TEST_ASSERT(CheckArray(arrayHandle),
|
||||
"Array values not retrieved from execution.");
|
||||
|
||||
std::cout << "Try in place operation." << std::endl;
|
||||
@ -141,12 +143,11 @@ void TestArrayHandle()
|
||||
ExecutionPortalType;
|
||||
ExecutionPortalType executionPortal =
|
||||
arrayHandle.PrepareForInPlace(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
for (ExecutionPortalType::IteratorType iter =
|
||||
executionPortal.GetIteratorBegin();
|
||||
iter != executionPortal.GetIteratorEnd();
|
||||
iter++)
|
||||
for (vtkm::Id index = 0;
|
||||
index < executionPortal.GetNumberOfValues();
|
||||
index++)
|
||||
{
|
||||
*iter += 1;
|
||||
executionPortal.Set(index, executionPortal.Get(index) + 1);
|
||||
}
|
||||
}
|
||||
vtkm::cont::ArrayHandle<vtkm::Scalar>::PortalConstControl controlPortal =
|
||||
|
@ -71,19 +71,6 @@ struct UnusualPortal
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const { return TestValue(index, ValueType()); }
|
||||
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<UnusualPortal<T> >
|
||||
IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
return IteratorType(*this, this->GetNumberOfValues());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -85,19 +85,6 @@ struct UnusualPortal
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
ValueType Get(vtkm::Id index) const { return TestValue(index); }
|
||||
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<UnusualPortal>
|
||||
IteratorType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const {
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const {
|
||||
return IteratorType(*this, this->GetNumberOfValues());
|
||||
}
|
||||
};
|
||||
|
||||
class ArrayHandleWithUnusualStorage
|
||||
|
@ -36,25 +36,22 @@ struct TemplatedTests
|
||||
StorageType;
|
||||
typedef typename StorageType::ValueType ValueType;
|
||||
typedef typename StorageType::PortalType PortalType;
|
||||
typedef typename PortalType::IteratorType IteratorType;
|
||||
|
||||
void SetStorage(StorageType &array, const ValueType& value)
|
||||
{
|
||||
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
|
||||
iter != array.GetPortal().GetIteratorEnd();
|
||||
iter ++)
|
||||
PortalType portal = array.GetPortal();
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
*iter = value;
|
||||
portal.Set(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckStorage(StorageType &array, const ValueType& value)
|
||||
{
|
||||
for (IteratorType iter = array.GetPortal().GetIteratorBegin();
|
||||
iter != array.GetPortal().GetIteratorEnd();
|
||||
iter ++)
|
||||
PortalType portal = array.GetPortal();
|
||||
for (vtkm::Id index = 0; index < portal.GetNumberOfValues(); index++)
|
||||
{
|
||||
if (!test_equal(*iter, value)) { return false; }
|
||||
if (!test_equal(portal.Get(index), value)) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ struct TestImplicitStorage
|
||||
{
|
||||
typedef T ValueType;
|
||||
ValueType Temp;
|
||||
typedef vtkm::cont::internal::IteratorFromArrayPortal<
|
||||
TestImplicitStorage<T> > IteratorType;
|
||||
|
||||
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
@ -56,18 +54,6 @@ struct TestImplicitStorage
|
||||
return Temp;
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorBegin() const
|
||||
{
|
||||
return IteratorType(*this);
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
IteratorType GetIteratorEnd() const
|
||||
{
|
||||
return IteratorType(*this, this->GetNumberOfValues());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const vtkm::Id ARRAY_SIZE = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user