vtk-m2/vtkm/cont/testing/UnitTestArrayHandleImplicit.cxx

91 lines
2.7 KiB
C++
Raw Normal View History

2015-02-13 06:24:43 +00:00
//=============================================================================
//
// 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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2015-02-13 06:24:43 +00:00
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
2015-02-13 06:24:43 +00:00
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2015-02-13 06:24:43 +00:00
// 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.
//
//=============================================================================
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleImplicit.h>
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
2015-02-13 06:24:43 +00:00
#include <vtkm/VecTraits.h>
2015-02-13 06:24:43 +00:00
#include <vtkm/cont/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace
{
2015-02-13 06:24:43 +00:00
const vtkm::Id ARRAY_SIZE = 10;
2017-05-18 14:29:41 +00:00
template <typename ValueType>
2015-02-13 06:24:43 +00:00
struct IndexSquared
{
VTKM_EXEC_CONT
2015-02-13 06:24:43 +00:00
ValueType operator()(vtkm::Id i) const
{
using ComponentType = typename vtkm::VecTraits<ValueType>::ComponentType;
2017-05-18 14:29:41 +00:00
return ValueType(static_cast<ComponentType>(i * i));
}
2015-02-13 06:24:43 +00:00
};
struct ImplicitTests
{
2017-05-18 14:29:41 +00:00
template <typename ValueType>
2015-02-13 06:24:43 +00:00
void operator()(const ValueType) const
{
using FunctorType = IndexSquared<ValueType>;
2015-02-13 06:24:43 +00:00
FunctorType functor;
using ImplicitHandle = vtkm::cont::ArrayHandleImplicit<FunctorType>;
2015-02-13 06:24:43 +00:00
2017-05-30 15:13:18 +00:00
ImplicitHandle implict = vtkm::cont::make_ArrayHandleImplicit(functor, ARRAY_SIZE);
2015-02-13 06:24:43 +00:00
//verify that the control portal works
2017-05-18 14:29:41 +00:00
for (int i = 0; i < ARRAY_SIZE; ++i)
{
2015-02-13 06:24:43 +00:00
const ValueType v = implict.GetPortalConstControl().Get(i);
const ValueType correct_value = functor(i);
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
}
2015-02-13 06:24:43 +00:00
//verify that the execution portal works
using Device = vtkm::cont::DeviceAdapterTagSerial;
using CEPortal = typename ImplicitHandle::template ExecutionTypes<Device>::PortalConst;
2015-02-13 06:24:43 +00:00
CEPortal execPortal = implict.PrepareForInput(Device());
2017-05-18 14:29:41 +00:00
for (int i = 0; i < ARRAY_SIZE; ++i)
{
2015-02-13 06:24:43 +00:00
const ValueType v = execPortal.Get(i);
const ValueType correct_value = functor(i);
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
2017-05-18 14:29:41 +00:00
}
2015-02-13 06:24:43 +00:00
}
};
void TestArrayHandleImplicit()
{
vtkm::testing::Testing::TryTypes(ImplicitTests(), vtkm::TypeListTagCommon());
}
} // anonymous namespace
2015-02-13 06:24:43 +00:00
int UnitTestArrayHandleImplicit(int argc, char* argv[])
2015-02-13 06:24:43 +00:00
{
return vtkm::cont::testing::Testing::Run(TestArrayHandleImplicit, argc, argv);
2015-02-13 06:24:43 +00:00
}