Program Listing for File functional.h¶
↰ Return to documentation for file (thrust/functional.h
)
/*
* Copyright 2008-2013 NVIDIA Corporation
* Modifications Copyright© 2019 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <thrust/detail/config.h>
#include <functional>
#include <thrust/detail/functional/placeholder.h>
namespace thrust
{
template<typename Operation> struct unary_traits;
template<typename Operation> struct binary_traits;
template<typename Argument,
typename Result>
struct unary_function
{
typedef Argument argument_type;
typedef Result result_type;
}; // end unary_function
template<typename Argument1,
typename Argument2,
typename Result>
struct binary_function
{
typedef Argument1 first_argument_type;
typedef Argument2 second_argument_type;
typedef Result result_type;
}; // end binary_function
template<typename T>
struct plus
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs + rhs;}
}; // end plus
template<typename T>
struct minus
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs - rhs;}
}; // end minus
template<typename T>
struct multiplies
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs * rhs;}
}; // end multiplies
template<typename T>
struct divides
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs / rhs;}
}; // end divides
template<typename T>
struct modulus
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs % rhs;}
}; // end modulus
template<typename T>
struct negate
{
typedef T argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &x) const {return -x;}
}; // end negate
template<typename T>
struct equal_to
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs == rhs;}
}; // end equal_to
template<typename T>
struct not_equal_to
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs != rhs;}
}; // end not_equal_to
template<typename T>
struct greater
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs > rhs;}
}; // end greater
template<typename T>
struct less
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs < rhs;}
}; // end less
template<typename T>
struct greater_equal
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs >= rhs;}
}; // end greater_equal
template<typename T>
struct less_equal
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs <= rhs;}
}; // end less_equal
template<typename T>
struct logical_and
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs && rhs;}
}; // end logical_and
template<typename T>
struct logical_or
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &lhs, const T &rhs) const {return lhs || rhs;}
}; // end logical_or
template<typename T>
struct logical_not
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
__host__ __device__ bool operator()(const T &x) const {return !x;}
}; // end logical_not
template<typename T>
struct bit_and
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs & rhs;}
}; // end bit_and
template<typename T>
struct bit_or
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs | rhs;}
}; // end bit_or
template<typename T>
struct bit_xor
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs ^ rhs;}
}; // end bit_xor
template<typename T>
struct identity
{
typedef T argument_type;
typedef T result_type;
__host__ __device__ const T &operator()(const T &x) const {return x;}
}; // end identity
template<typename T>
struct maximum
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs < rhs ? rhs : lhs;}
}; // end maximum
template<typename T>
struct minimum
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef T result_type;
__host__ __device__ T operator()(const T &lhs, const T &rhs) const {return lhs < rhs ? lhs : rhs;}
}; // end minimum
template<typename T1, typename T2>
struct project1st
{
typedef T1 first_argument_type;
typedef T2 second_argument_type;
typedef T1 result_type;
__host__ __device__ const T1 &operator()(const T1 &lhs, const T2 & /*rhs*/) const {return lhs;}
}; // end project1st
template<typename T1, typename T2>
struct project2nd
{
typedef T1 first_argument_type;
typedef T2 second_argument_type;
typedef T2 result_type;
__host__ __device__ const T2 &operator()(const T1 &/*lhs*/, const T2 &rhs) const {return rhs;}
}; // end project2nd
// odds and ends
template<typename Predicate>
struct unary_negate
: public thrust::unary_function<typename Predicate::argument_type, bool>
{
__host__ __device__
explicit unary_negate(Predicate p) : pred(p){}
__host__ __device__
bool operator()(const typename Predicate::argument_type& x) { return !pred(x); }
Predicate pred;
}; // end unary_negate
template<typename Predicate>
__host__ __device__
unary_negate<Predicate> not1(const Predicate &pred);
template<typename Predicate>
struct binary_negate
: public thrust::binary_function<typename Predicate::first_argument_type,
typename Predicate::second_argument_type,
bool>
{
__host__ __device__
explicit binary_negate(Predicate p) : pred(p){}
__host__ __device__
bool operator()(const typename Predicate::first_argument_type& x, const typename Predicate::second_argument_type& y)
{
return !pred(x,y);
}
Predicate pred;
}; // end binary_negate
template<typename BinaryPredicate>
__host__ __device__
binary_negate<BinaryPredicate> not2(const BinaryPredicate &pred);
namespace placeholders
{
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<0>::type _1;
#else
static const thrust::detail::functional::placeholder<0>::type _1;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<1>::type _2;
#else
static const thrust::detail::functional::placeholder<1>::type _2;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<2>::type _3;
#else
static const thrust::detail::functional::placeholder<2>::type _3;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<3>::type _4;
#else
static const thrust::detail::functional::placeholder<3>::type _4;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<4>::type _5;
#else
static const thrust::detail::functional::placeholder<4>::type _5;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<5>::type _6;
#else
static const thrust::detail::functional::placeholder<5>::type _6;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<6>::type _7;
#else
static const thrust::detail::functional::placeholder<6>::type _7;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<7>::type _8;
#else
static const thrust::detail::functional::placeholder<7>::type _8;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<8>::type _9;
#else
static const thrust::detail::functional::placeholder<8>::type _9;
#endif
#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
static const __device__ thrust::detail::functional::placeholder<9>::type _10;
#else
static const thrust::detail::functional::placeholder<9>::type _10;
#endif
} // end placeholders
} // end thrust
#include <thrust/detail/functional.inl>
#include <thrust/detail/functional/operators.h>