#pragma once #include #include #include #include namespace thrust { namespace detail { namespace functional { template struct unary_exp : public thrust::unary_function { __host__ __device__ T operator()(const T &x) const { float x2 = x; float clip = 16; if(x2 > clip) x2 = clip; if(x2 < -clip) x2 = -clip; return expf(x2); } }; template __host__ __device__ actor, actor>> Exp(const actor &_1) { return compose(unary_operator(), _1); } template struct unary_log : public thrust::unary_function { __host__ __device__ T operator()(const T &x) const { float x2 = x; if(x2 < 10e-10) x2 = 10e-10; return logf(x2); } }; template __host__ __device__ actor, actor>> Log(const actor &_1) { return compose(unary_operator(), _1); } template struct unary_sigma : public thrust::unary_function { __host__ __device__ T operator()(const T &x) const { float x2 = x; float clip = 16; if(x2 > clip) x2 = clip; if(x2 < -clip) x2 = -clip; return 1.0 / (1.0 + expf(-x2)); } }; template __host__ __device__ actor, actor>> Sigma(const actor &_1) { return compose(unary_operator(), _1); } template struct unary_tanh : public thrust::unary_function { __host__ __device__ T operator()(const T &x) const { return tanhf(x); } }; template __host__ __device__ actor, actor>> Tanh(const actor &_1) { return compose(unary_operator(), _1); } template __host__ __device__ actor, actor, actor>> Max(const actor &_1, const actor &_2) { return compose(binary_operator(), make_actor(_1), make_actor(_2)); } } } }