Add ability to zip function interface objects.

The zip capability allows you to parameter-wise combine two
FunctionInterface objects. The result is another FunctionInterface with
each parameter a Pair containing the respective values of the two
inputs.

Being able to zip allows you to do transforms and invokes on data that
is divided among multiple function interface objects.
This commit is contained in:
Kenneth Moreland 2014-10-16 16:31:55 -06:00
parent 01d6619774
commit b78688f4f4
8 changed files with 1158 additions and 2 deletions

@ -23,6 +23,7 @@ include_directories(${Boost_INCLUDE_DIRS})
set(headers
Extent.h
ListTag.h
Pair.h
TypeListTag.h
Types.h
TypeTraits.h

141
vtkm/Pair.h Normal file

@ -0,0 +1,141 @@
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. 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_Pair_h
#define vtk_m_Pair_h
#include <vtkm/internal/Configure.h>
#include <vtkm/internal/ExportMacros.h>
namespace vtkm {
/// A \c vtkm::Pair is essentially the same as an STL pair object except that
/// the methods (constructors and operators) are defined to work in both the
/// control and execution environments (whereas std::pair is likely to work
/// only in the control environment).
///
template <typename T1, typename T2>
struct Pair
{
/// The type of the first object.
///
typedef T1 FirstType;
/// The type of the second object.
///
typedef T2 SecondType;
/// The same as FirstType, but follows the naming convention of std::pair.
///
typedef FirstType first_type;
/// The same as SecondType, but follows the naming convention of std::pair.
///
typedef SecondType second_type;
/// The pair's first object. Note that this field breaks VTK-m's naming
/// conventions to make vtkm::Pair more compatible with std::pair.
///
FirstType first;
/// The pair's second object. Note that this field breaks VTK-m's naming
/// conventions to make vtkm::Pair more compatible with std::pair.
///
SecondType second;
VTKM_EXEC_CONT_EXPORT
Pair() : first(), second() { }
VTKM_EXEC_CONT_EXPORT
Pair(const FirstType &firstSrc, const SecondType &secondSrc)
: first(firstSrc), second(secondSrc) { }
template <typename U1, typename U2>
VTKM_EXEC_CONT_EXPORT
Pair(const vtkm::Pair<U1,U2> &src)
: first(src.first), second(src.second) { }
template <typename U1, typename U2>
VTKM_EXEC_CONT_EXPORT
Pair(const std::pair<U1,U2> &src)
: first(src.first), second(src.second) { }
VTKM_EXEC_CONT_EXPORT
vtkm::Pair<FirstType,SecondType> &
operator=(const vtkm::Pair<FirstType,SecondType> &src) {
this->first = src.first;
this->second = src.second;
return *this;
}
VTKM_EXEC_CONT_EXPORT
bool operator==(const vtkm::Pair<FirstType,SecondType> &other) const {
return ((this->first == other.first) && (this->second == other.second));
}
VTKM_EXEC_CONT_EXPORT
bool operator!=(const vtkm::Pair<FirstType,SecondType> &other) const {
return !(*this == other);
}
/// Tests ordering on the first object, and then on the second object if the
/// first are equal.
///
VTKM_EXEC_CONT_EXPORT
bool operator<(const vtkm::Pair<FirstType,SecondType> &other) const {
return ((this->first < other.first)
|| (!(other.first < this->first) && (this->second < other.second)));
}
/// Tests ordering on the first object, and then on the second object if the
/// first are equal.
///
VTKM_EXEC_CONT_EXPORT
bool operator>(const vtkm::Pair<FirstType,SecondType> &other) const {
return (other < *this);
}
/// Tests ordering on the first object, and then on the second object if the
/// first are equal.
///
VTKM_EXEC_CONT_EXPORT
bool operator<=(const vtkm::Pair<FirstType,SecondType> &other) const {
return !(other < *this);
}
/// Tests ordering on the first object, and then on the second object if the
/// first are equal.
///
VTKM_EXEC_CONT_EXPORT
bool operator>=(const vtkm::Pair<FirstType,SecondType> &other) const {
return !(*this < other);
}
};
template <typename T1, typename T2>
VTKM_EXEC_CONT_EXPORT
vtkm::Pair<T1,T2> make_Pair(const T1 &firstSrc, const T2 &secondSrc)
{
return vtkm::Pair<T1,T2>(firstSrc, secondSrc);
}
} // namespace vtkm
#endif //vtk_m_Pair_h

@ -20,6 +20,7 @@
#ifndef vtk_m_internal_FunctionInterface_h
#define vtk_m_internal_FunctionInterface_h
#include <vtkm/Pair.h>
#include <vtkm/Types.h>
#include <boost/function_types/components.hpp>
@ -745,8 +746,27 @@ private:
const FinishFunctor &Finish;
};
template<typename FirstType, typename SecondType>
struct FunctionInterfaceZipReturn
{
typedef vtkm::Pair<FirstType,SecondType> type;
};
template<>
struct FunctionInterfaceZipReturn<void, void>
{
typedef void type;
};
} // namespace detail
/// Used to determine the type returned from \c make_FunctionInterfaceZip.
/// Contains a typedef named \c type that is the appropriate \c
/// FunctionInterface type.
///
template<typename FirstFunctionInterface, typename SecondFunctionInterface>
struct FunctionInterfaceZipType;
}
} // namespace vtkm::internal

@ -641,6 +641,753 @@ make_FunctionInterface(
}
template<typename TR,
typename UR>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR()>,
vtkm::internal::FunctionInterface<UR()> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
)> type;
};
template<typename TR,
typename TP1,
typename UR,
typename UP1>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1)>,
vtkm::internal::FunctionInterface<UR(UP1)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename UR,
typename UP1,
typename UP2>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename UR,
typename UP1,
typename UP2,
typename UP3>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>,
vtkm::Pair<TP6, UP6>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>,
vtkm::Pair<TP6, UP6>,
vtkm::Pair<TP7, UP7>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>,
vtkm::Pair<TP6, UP6>,
vtkm::Pair<TP7, UP7>,
vtkm::Pair<TP8, UP8>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename TP9,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8,
typename UP9>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>,
vtkm::Pair<TP6, UP6>,
vtkm::Pair<TP7, UP7>,
vtkm::Pair<TP8, UP8>,
vtkm::Pair<TP9, UP9>
)> type;
};
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename TP9,
typename TP10,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8,
typename UP9,
typename UP10>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9,TP10)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9,UP10)> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<TR,UR>::type (
vtkm::Pair<TP1, UP1>,
vtkm::Pair<TP2, UP2>,
vtkm::Pair<TP3, UP3>,
vtkm::Pair<TP4, UP4>,
vtkm::Pair<TP5, UP5>,
vtkm::Pair<TP6, UP6>,
vtkm::Pair<TP7, UP7>,
vtkm::Pair<TP8, UP8>,
vtkm::Pair<TP9, UP9>,
vtkm::Pair<TP10, UP10>
)> type;
};
/// Creates a "zipped" version of two \c FunctionInterface objects. Each
/// parameter in the returned object is a \c vtkm::Pair that is a combination
/// of the corresponding pair of the input objects.
///
template<typename TR,
typename TP1,
typename UR,
typename UP1>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1)>,
vtkm::internal::FunctionInterface<UR(UP1)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1)> &first,
const vtkm::internal::FunctionInterface<UR(UP1)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1)>,
vtkm::internal::FunctionInterface<UR(UP1)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename UR,
typename UP1,
typename UP2>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename UR,
typename UP1,
typename UP2,
typename UP3>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
result.template SetParameter<6>(
vtkm::make_Pair(first.template GetParameter<6>(),
second.template GetParameter<6>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
result.template SetParameter<6>(
vtkm::make_Pair(first.template GetParameter<6>(),
second.template GetParameter<6>()));
result.template SetParameter<7>(
vtkm::make_Pair(first.template GetParameter<7>(),
second.template GetParameter<7>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
result.template SetParameter<6>(
vtkm::make_Pair(first.template GetParameter<6>(),
second.template GetParameter<6>()));
result.template SetParameter<7>(
vtkm::make_Pair(first.template GetParameter<7>(),
second.template GetParameter<7>()));
result.template SetParameter<8>(
vtkm::make_Pair(first.template GetParameter<8>(),
second.template GetParameter<8>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename TP9,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8,
typename UP9>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
result.template SetParameter<6>(
vtkm::make_Pair(first.template GetParameter<6>(),
second.template GetParameter<6>()));
result.template SetParameter<7>(
vtkm::make_Pair(first.template GetParameter<7>(),
second.template GetParameter<7>()));
result.template SetParameter<8>(
vtkm::make_Pair(first.template GetParameter<8>(),
second.template GetParameter<8>()));
result.template SetParameter<9>(
vtkm::make_Pair(first.template GetParameter<9>(),
second.template GetParameter<9>()));
return result;
}
template<typename TR,
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8,
typename TP9,
typename TP10,
typename UR,
typename UP1,
typename UP2,
typename UP3,
typename UP4,
typename UP5,
typename UP6,
typename UP7,
typename UP8,
typename UP9,
typename UP10>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9,TP10)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9,UP10)> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9,TP10)> &first,
const vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9,UP10)> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<TR(TP1,TP2,TP3,TP4,TP5,TP6,TP7,TP8,TP9,TP10)>,
vtkm::internal::FunctionInterface<UR(UP1,UP2,UP3,UP4,UP5,UP6,UP7,UP8,UP9,UP10)> >::type result;
result.template SetParameter<1>(
vtkm::make_Pair(first.template GetParameter<1>(),
second.template GetParameter<1>()));
result.template SetParameter<2>(
vtkm::make_Pair(first.template GetParameter<2>(),
second.template GetParameter<2>()));
result.template SetParameter<3>(
vtkm::make_Pair(first.template GetParameter<3>(),
second.template GetParameter<3>()));
result.template SetParameter<4>(
vtkm::make_Pair(first.template GetParameter<4>(),
second.template GetParameter<4>()));
result.template SetParameter<5>(
vtkm::make_Pair(first.template GetParameter<5>(),
second.template GetParameter<5>()));
result.template SetParameter<6>(
vtkm::make_Pair(first.template GetParameter<6>(),
second.template GetParameter<6>()));
result.template SetParameter<7>(
vtkm::make_Pair(first.template GetParameter<7>(),
second.template GetParameter<7>()));
result.template SetParameter<8>(
vtkm::make_Pair(first.template GetParameter<8>(),
second.template GetParameter<8>()));
result.template SetParameter<9>(
vtkm::make_Pair(first.template GetParameter<9>(),
second.template GetParameter<9>()));
result.template SetParameter<10>(
vtkm::make_Pair(first.template GetParameter<10>(),
second.template GetParameter<10>()));
return result;
}
}
} // namespace vtkm::internal

@ -69,8 +69,8 @@ def template_params(num_params, start=0, name=''):
result += ',\n typename %s' % ptype(param, name)
return result
def signature(num_params, return_type=ptype(0), name=''):
result = '%s(' % return_type
def signature(num_params, name=''):
result = '%s(' % ptype(0, name)
if num_params > 0:
result += ptype(1, name)
for param in xrange(2, num_params+1):
@ -136,6 +136,53 @@ $endfor\
$endfor\
$for(num_params in xrange(0, max_parameters+1))\
template<$template_params(num_params, name='T'),
$template_params(num_params, name='U')>
struct FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >
{
typedef vtkm::internal::FunctionInterface<
typename detail::FunctionInterfaceZipReturn<$ptype(0,name='T'),$ptype(0,name='U')>::type (
$for(param_index in xrange(1, num_params+1))\
vtkm::Pair<$ptype(param_index,name='T'), $ptype(param_index,name='U')>$comma_if(num_params-param_index)
$endfor\
)> type;
};
$endfor\
/// Creates a "zipped" version of two \c FunctionInterface objects. Each
/// parameter in the returned object is a \c vtkm::Pair that is a combination
/// of the corresponding pair of the input objects.
///
$for(num_params in xrange(1, max_parameters+1))\
template<$template_params(num_params, name='T'),
$template_params(num_params, name='U')>
VTKM_EXEC_CONT_EXPORT
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >::type
make_FunctionInterfaceZip(
const vtkm::internal::FunctionInterface<$signature(num_params, name='T')> &first,
const vtkm::internal::FunctionInterface<$signature(num_params, name='U')> &second)
{
typename vtkm::internal::FunctionInterfaceZipType<
vtkm::internal::FunctionInterface<$signature(num_params, name='T')>,
vtkm::internal::FunctionInterface<$signature(num_params, name='U')> >::type result;
$for(param_index in xrange(1, num_params+1))\
result.template SetParameter<$(param_index)>(
vtkm::make_Pair(first.template GetParameter<$(param_index)>(),
second.template GetParameter<$(param_index)>()));
$endfor\
return result;
}
$endfor\
}
} // namespace vtkm::internal

@ -248,6 +248,23 @@ struct ForEachFunctor
void operator()(std::string &x) const { x.append("*2"); }
};
struct ZipFunctor
{
void operator()(const vtkm::Pair<Type1,Type3> &a1,
const vtkm::Pair<Type2,Type4> &a2,
const vtkm::Pair<Type3,Type5> &a3) const
{
std::cout << "In functor for zipped functions." << std::endl;
VTKM_TEST_ASSERT(a1.first == Arg1, "Bad arg.");
VTKM_TEST_ASSERT(a1.second == Arg3, "Bad arg.");
VTKM_TEST_ASSERT(a2.first == Arg2, "Bad arg.");
VTKM_TEST_ASSERT(a2.second == Arg4, "Bad arg.");
VTKM_TEST_ASSERT(a3.first == Arg3, "Bad arg.");
VTKM_TEST_ASSERT(a3.second == Arg5, "Bad arg.");
}
};
void TryFunctionInterface5(
vtkm::internal::FunctionInterface<void(Type1,Type2,Type3,Type4,Type5)> funcInterface)
{
@ -447,6 +464,16 @@ void TestForEach()
VTKM_TEST_ASSERT(funcInterface.GetParameter<5>() == 4*Arg5, "Arg 5 incorrect.");
}
void TestZip()
{
std::cout << "Testing zipping function interfaces." << std::endl;
vtkm::internal::make_FunctionInterfaceZip(
vtkm::internal::make_FunctionInterface<void>(Arg1, Arg2, Arg3),
vtkm::internal::make_FunctionInterface<void>(Arg3, Arg4, Arg5)).
InvokeCont(ZipFunctor());
}
void TestInvokeTime()
{
std::cout << "Checking time to call lots of args lots of times." << std::endl;
@ -525,6 +552,7 @@ void TestFunctionInterface()
TestStaticTransform();
TestDynamicTransform();
TestForEach();
TestZip();
TestInvokeTime();
}

@ -29,6 +29,7 @@ VTKM_declare_headers(${headers})
set(unit_tests
UnitTestExtent.cxx
UnitTestListTag.cxx
UnitTestPair.cxx
UnitTestTesting.cxx
UnitTestTypeListTag.cxx
UnitTestTypes.cxx

@ -0,0 +1,171 @@
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. 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.
//============================================================================
#include <vtkm/Pair.h>
#include <vtkm/Types.h>
#include <vtkm/VecTraits.h>
#include <vtkm/testing/Testing.h>
namespace {
//general pair test
template <typename T, typename U>
void PairTest( )
{
//test that all the constructors work properly
{
vtkm::Pair<T,U> no_params_pair;
no_params_pair.first = TestValue(12, T());
no_params_pair.second = TestValue(34, U());
vtkm::Pair<T,U> copy_constructor_pair(no_params_pair);
vtkm::Pair<T,U> assignment_pair = no_params_pair;
VTKM_TEST_ASSERT( (no_params_pair == copy_constructor_pair),
"copy constructor doesn't match default constructor");
VTKM_TEST_ASSERT( !(no_params_pair != copy_constructor_pair),
"operator != is working properly");
VTKM_TEST_ASSERT( (no_params_pair == assignment_pair),
"assignment constructor doesn't match default constructor");
VTKM_TEST_ASSERT( !(no_params_pair != assignment_pair),
"operator != is working properly");
}
//now lets give each item in the pair some values and do some in depth
//comparisons
T a = TestValue(56, T());
U b = TestValue(78, U());
//test the constructors now with real values
{
vtkm::Pair<T,U> pair_ab(a,b);
vtkm::Pair<T,U> copy_constructor_pair(pair_ab);
vtkm::Pair<T,U> assignment_pair = pair_ab;
vtkm::Pair<T,U> make_p = vtkm::make_Pair(a,b);
VTKM_TEST_ASSERT( !(pair_ab != pair_ab),
"operator != isn't working properly for vtkm::Pair" );
VTKM_TEST_ASSERT( (pair_ab == pair_ab),
"operator == isn't working properly for vtkm::Pair" );
VTKM_TEST_ASSERT( (pair_ab == copy_constructor_pair),
"copy constructor doesn't match pair constructor");
VTKM_TEST_ASSERT( (pair_ab == assignment_pair),
"assignment constructor doesn't match pair constructor");
VTKM_TEST_ASSERT(copy_constructor_pair.first == a,
"first field not set right");
VTKM_TEST_ASSERT(assignment_pair.second == b,
"second field not set right");
VTKM_TEST_ASSERT( (pair_ab == make_p),
"make_pair function doesn't match pair constructor");
}
//test the ordering operators <, >, <=, >=
{
//in all cases pair_ab2 is > pair_ab. these verify that if the second
//argument of the pair is different we respond properly
U b2(b);
vtkm::VecTraits<U>::SetComponent(b2,0,
vtkm::VecTraits<U>::GetComponent(b2,0)+1);
vtkm::Pair<T,U> pair_ab2(a,b2);
vtkm::Pair<T,U> pair_ab(a,b);
VTKM_TEST_ASSERT( (pair_ab2 >= pair_ab), "operator >= failed" );
VTKM_TEST_ASSERT( (pair_ab2 >= pair_ab2), "operator >= failed" );
VTKM_TEST_ASSERT( (pair_ab2 > pair_ab), "operator > failed" );
VTKM_TEST_ASSERT( !(pair_ab2 > pair_ab2), "operator > failed" );
VTKM_TEST_ASSERT( !(pair_ab2 < pair_ab), "operator < failed" );
VTKM_TEST_ASSERT( !(pair_ab2 < pair_ab2), "operator < failed" );
VTKM_TEST_ASSERT( !(pair_ab2 <= pair_ab), "operator <= failed" );
VTKM_TEST_ASSERT( (pair_ab2 <= pair_ab2), "operator <= failed" );
VTKM_TEST_ASSERT( !(pair_ab2 == pair_ab), "operator == failed" );
VTKM_TEST_ASSERT( (pair_ab2 != pair_ab), "operator != failed" );
T a2(a);
vtkm::VecTraits<T>::SetComponent(a2,0,
vtkm::VecTraits<T>::GetComponent(a2,0)+1);
vtkm::Pair<T,U> pair_a2b(a2,b);
//this way can verify that if the first argument of the pair is different
//we respond properly
VTKM_TEST_ASSERT( (pair_a2b >= pair_ab), "operator >= failed" );
VTKM_TEST_ASSERT( (pair_a2b >= pair_a2b), "operator >= failed" );
VTKM_TEST_ASSERT( (pair_a2b > pair_ab), "operator > failed" );
VTKM_TEST_ASSERT( !(pair_a2b > pair_a2b), "operator > failed" );
VTKM_TEST_ASSERT( !(pair_a2b < pair_ab), "operator < failed" );
VTKM_TEST_ASSERT( !(pair_a2b < pair_a2b), "operator < failed" );
VTKM_TEST_ASSERT( !(pair_a2b <= pair_ab), "operator <= failed" );
VTKM_TEST_ASSERT( (pair_a2b <= pair_a2b), "operator <= failed" );
VTKM_TEST_ASSERT( !(pair_a2b == pair_ab), "operator == failed" );
VTKM_TEST_ASSERT( (pair_a2b != pair_ab), "operator != failed" );
}
}
template< typename FirstType >
struct DecideSecondType
{
template <typename SecondType> void operator()(const SecondType&) const
{
PairTest<FirstType,SecondType>();
}
};
struct DecideFirstType
{
template <typename T> void operator()(const T&) const
{
//T is our first type for vtkm::Pair, now to figure out the second type
vtkm::testing::Testing::TryTypes(DecideSecondType<T>(),
vtkm::TypeListTagField());
}
};
void TestPair()
{
//we want to test each combination of standard dax types in a
//vtkm::Pair, so to do that we dispatch twice on TryTypes. We could
//dispatch on all types, but that gets excessively large and takes a
//long time to compile (although it runs fast). Instead, just select
//a subset of non-trivial combinations.
vtkm::testing::Testing::TryTypes(DecideFirstType(),
vtkm::TypeListTagCommon());
}
} // anonymous namespace
int UnitTestPair(int, char *[])
{
return vtkm::testing::Testing::Run(TestPair);
}