Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
variadic tuple_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcorrigan committed Oct 12, 2020
1 parent 53a1d25 commit 22e6dd1
Showing 1 changed file with 6 additions and 341 deletions.
347 changes: 6 additions & 341 deletions thrust/detail/tuple_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,349 +28,23 @@ namespace detail
template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction,
unsigned int sz = thrust::tuple_size<Tuple>::value>
typename IndexSequence = thrust::make_index_sequence<thrust::tuple_size<Tuple>::value>>
struct tuple_transform_functor;


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,0>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &, UnaryFunction)
{
return thrust::null_type();
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &, UnaryFunction)
{
return thrust::null_type();
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,1>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,2>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,3>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,4>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,5>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,6>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,7>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,8>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,9>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)),
f(thrust::get<8>(t)));
}

static __host__ __device__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)),
f(thrust::get<8>(t)));
}
};


template<typename Tuple,
template<typename> class UnaryMetaFunction,
typename UnaryFunction>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,10>
typename UnaryFunction,
size_t... Is>
struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,thrust::index_sequence<Is...>>
{
static __host__
typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
do_it_on_the_host(const Tuple &t, UnaryFunction f)
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)),
f(thrust::get<8>(t)),
f(thrust::get<9>(t)));
return XfrmTuple(f(thrust::get<Is>(t))...);
}

static __host__ __device__
Expand All @@ -379,16 +53,7 @@ template<typename Tuple,
{
typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;

return XfrmTuple(f(thrust::get<0>(t)),
f(thrust::get<1>(t)),
f(thrust::get<2>(t)),
f(thrust::get<3>(t)),
f(thrust::get<4>(t)),
f(thrust::get<5>(t)),
f(thrust::get<6>(t)),
f(thrust::get<7>(t)),
f(thrust::get<8>(t)),
f(thrust::get<9>(t)));
return XfrmTuple(f(thrust::get<Is>(t))...);
}
};

Expand Down

0 comments on commit 22e6dd1

Please sign in to comment.