Skip to content
Snippets Groups Projects
Commit 4afb6fe5 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Merge branch 'constant-array-handle'

parents 59618b3a d77342a7
No related branches found
No related tags found
No related merge requests found
//=============================================================================
//
// 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.
//
// Copyright 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015. Los Alamos National Security
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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.
//
//=============================================================================
#ifndef vtk_m_cont_ArrayHandleConstant_h
#define vtk_m_cont_ArrayHandleConstant_h
#include <vtkm/cont/ArrayHandleImplicit.h>
namespace vtkm {
namespace cont {
namespace detail {
template<typename ValueType>
struct ConstantFunctor
{
VTKM_EXEC_CONT_EXPORT
ConstantFunctor(const ValueType &value = ValueType()) : Value(value) { }
VTKM_EXEC_CONT_EXPORT
ValueType operator()(vtkm::Id vtkmNotUsed(index)) const
{
return this->Value;
}
private:
ValueType Value;
};
} // namespace detail
/// \brief An array handle with a constant value.
///
/// ArrayHandleConstant is an implicit array handle with a constant value. A
/// constant array handle is constructed by giving a value and an array length.
/// The resulting array is of the given size with each entry the same value
/// given in the constructor. The array is defined implicitly, so there it
/// takes (almost) no memory.
///
template<typename T>
class ArrayHandleConstant
: public vtkm::cont::ArrayHandleImplicit<T, detail::ConstantFunctor<T> >
{
typedef vtkm::cont::ArrayHandleImplicit<T, detail::ConstantFunctor<T> >
Superclass;
public:
VTKM_CONT_EXPORT
ArrayHandleConstant(T value = T(), vtkm::Id numberOfValues = 0)
: Superclass(detail::ConstantFunctor<T>(value), numberOfValues) { }
};
/// make_ArrayHandleImplicit is convenience function to generate an
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
/// arry.
///
template<typename T>
vtkm::cont::ArrayHandleConstant<T>
make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
{
return vtkm::cont::ArrayHandleConstant<T>(value, numberOfValues);
}
}
} // vtkm::cont
#endif //vtk_m_cont_ArrayHandleConstant_h
......@@ -96,7 +96,7 @@ struct ArrayHandleCountingTraits
} // namespace internal
/// ArrayHandleCountings is a specialization of ArrayHandle. By default it
/// ArrayHandleCounting is a specialization of ArrayHandle. By default it
/// contains a increment value, that is increment for each step between zero
/// and the passed in length
template <typename CountingValueType>
......
......@@ -23,6 +23,7 @@ include_directories(${Boost_INCLUDE_DIRS})
set(headers
ArrayHandle.h
ArrayHandleCompositeVector.h
ArrayHandleConstant.h
ArrayHandleCounting.h
ArrayHandleImplicit.h
ArrayHandlePermutation.h
......
......@@ -22,6 +22,7 @@
#ifndef vtk_m_cont_testing_TestingFancyArrayHandles_h
#define vtk_m_cont_testing_TestingFancyArrayHandles_h
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleImplicit.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
......@@ -252,6 +253,33 @@ private:
}
};
struct TestConstantAsInput
{
template< typename ValueType >
VTKM_CONT_EXPORT void operator()(const ValueType vtkmNotUsed(v)) const
{
const ValueType value = TestValue(43, ValueType());
vtkm::cont::ArrayHandleConstant<ValueType> constant =
vtkm::cont::make_ArrayHandleConstant(value, ARRAY_SIZE);
vtkm::cont::ArrayHandle<ValueType> result;
vtkm::worklet::DispatcherMapField<PassThrough, DeviceAdapterTag> dispatcher;
dispatcher.Invoke(constant, result);
//verify that the control portal works
for(vtkm::Id i=0; i < ARRAY_SIZE; ++i)
{
const ValueType result_v = result.GetPortalConstControl().Get(i);
const ValueType control_value = constant.GetPortalConstControl().Get(i);
VTKM_TEST_ASSERT(test_equal(result_v, value),
"Counting Handle Failed");
VTKM_TEST_ASSERT(test_equal(result_v, control_value),
"Counting Handle Control Failed");
}
}
};
struct TestCountingAsInput
{
template< typename ValueType >
......@@ -556,6 +584,12 @@ struct TestPermutationAsOutput
TestingFancyArrayHandles<DeviceAdapterTag>::TestZipAsInput(),
ZipTypesToTest());
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing ArrayHandleConstant as Input" << std::endl;
vtkm::testing::Testing::TryTypes(
TestingFancyArrayHandles<DeviceAdapterTag>::TestConstantAsInput(),
HandleTypesToTest());
std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing ArrayHandleCounting as Input" << std::endl;
vtkm::testing::Testing::TryTypes(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment