@ -210,8 +210,8 @@ struct HardShrinkFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
auto temp1 = ( x < ( threshold * - 1 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x > threshold) . template cast < T > ( ) . eval ( ) ;
auto temp1 = ( x < static_cast < T > ( threshold * - 1 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x > static_cast< T > ( threshold) ) . template cast < T > ( ) . eval ( ) ;
y . device ( d ) = x * ( temp1 + temp2 ) ;
}
} ;
@ -226,8 +226,8 @@ struct HardShrinkGradFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
auto temp1 = ( x < ( threshold * - 1 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x > threshold) . template cast < T > ( ) . eval ( ) ;
auto temp1 = ( x < static_cast < T > ( threshold * - 1 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x > static_cast< T > ( threshold) ) . template cast < T > ( ) . eval ( ) ;
dx . device ( d ) = dy * ( temp1 + temp2 ) . template cast < T > ( ) ;
}
} ;
@ -243,9 +243,10 @@ struct SoftShrinkFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
auto temp1 = ( x > lambda ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x < - lambda ) . template cast < T > ( ) . eval ( ) ;
y . device ( d ) = temp1 * ( x - lambda ) + temp2 * ( x + lambda ) ;
auto lambdaT = static_cast < T > ( lambda ) ;
auto temp1 = ( x > lambdaT ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x < - lambdaT ) . template cast < T > ( ) . eval ( ) ;
y . device ( d ) = temp1 * ( x - lambdaT ) + temp2 * ( x + lambdaT ) ;
}
} ;
@ -257,8 +258,9 @@ struct SoftShrinkGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
auto temp1 = ( x > lambda ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x < - lambda ) . template cast < T > ( ) . eval ( ) ;
auto lambdaT = static_cast < T > ( lambda ) ;
auto temp1 = ( x > lambdaT ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x < - lambdaT ) . template cast < T > ( ) . eval ( ) ;
dx . device ( d ) = dy * ( temp1 + temp2 ) . template cast < T > ( ) ;
}
} ;
@ -362,7 +364,8 @@ struct BReluFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = x . cwiseMax ( t_min ) . cwiseMin ( t_max ) ;
y . device ( d ) =
x . cwiseMax ( static_cast < T > ( t_min ) ) . cwiseMin ( static_cast < T > ( t_max ) ) ;
}
} ;
@ -375,7 +378,9 @@ struct BReluGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
dx . device ( d ) = dy * ( ( x > t_min ) * ( x < t_max ) ) . template cast < T > ( ) ;
dx . device ( d ) = dy *
( ( x > static_cast < T > ( t_min ) ) * ( x < static_cast < T > ( t_max ) ) )
. template cast < T > ( ) ;
}
} ;
@ -390,7 +395,8 @@ struct Relu6Functor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = x . cwiseMax ( static_cast < T > ( 0 ) ) . cwiseMin ( threshold ) ;
y . device ( d ) =
x . cwiseMax ( static_cast < T > ( 0 ) ) . cwiseMin ( static_cast < T > ( threshold ) ) ;
}
} ;
@ -402,8 +408,9 @@ struct Relu6GradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
dx . device ( d ) =
dy * ( ( x > static_cast < T > ( 0 ) ) * ( x < threshold ) ) . template cast < T > ( ) ;
dx . device ( d ) = dy *
( ( x > static_cast < T > ( 0 ) ) * ( x < static_cast < T > ( threshold ) ) )
. template cast < T > ( ) ;
}
} ;
@ -463,7 +470,8 @@ struct SoftReluFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
auto temp = x . cwiseMax ( - threshold ) . cwiseMin ( threshold ) ;
auto tmp = static_cast < T > ( threshold ) ;
auto temp = x . cwiseMax ( - tmp ) . cwiseMin ( tmp ) ;
y . device ( d ) = ( static_cast < T > ( 1 ) + temp . exp ( ) ) . log ( ) ;
}
} ;
@ -476,7 +484,8 @@ struct SoftReluGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
auto temp = ( ( x > - threshold ) * ( x < threshold ) ) . template cast < T > ( ) . eval ( ) ;
auto tmp = static_cast < T > ( threshold ) ;
auto temp = ( ( x > - tmp ) * ( x < tmp ) ) . template cast < T > ( ) . eval ( ) ;
dx . device ( d ) = dy * ( static_cast < T > ( 1 ) - ( - y ) . exp ( ) ) * temp ;
}
} ;
@ -490,7 +499,7 @@ struct LeakyReluFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = x . cwiseMax ( alpha * x ) ;
y . device ( d ) = x . cwiseMax ( static_cast< T > ( alpha) * x ) ;
}
} ;
@ -502,7 +511,8 @@ struct LeakyReluGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
auto temp1 = alpha * ( x < static_cast < T > ( 0 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp1 = static_cast < T > ( alpha ) *
( x < static_cast < T > ( 0 ) ) . template cast < T > ( ) . eval ( ) ;
auto temp2 = ( x > = static_cast < T > ( 0 ) ) . template cast < T > ( ) . eval ( ) ;
dx . device ( d ) = dy * ( temp1 + temp2 ) . template cast < T > ( ) ;
}
@ -517,9 +527,9 @@ struct ELUFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) =
x . cwis eMa x( static_cast < T > ( 0) ) +
( alpha * ( x . exp ( ) - static_cast < T > ( 1 ) ) ) . cwiseMin ( static_cast < T > ( 0 ) ) ;
y . device ( d ) = x . cwiseMax ( static_cast < T > ( 0 ) ) +
( static_cast < T > ( alpha ) * ( x . exp ( ) - static_cast < T > ( 1) ) )
. cwiseMin ( static_cast < T > ( 0 ) ) ;
}
} ;
@ -531,9 +541,9 @@ struct ELUGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
dx . device ( d ) =
dy * ( x > static_cast < T > ( 0 ) ) . template cast < T > ( ) +
dy * ( y + alpha ) * ( x < static_cast < T > ( 0 ) ) . template cast < T > ( ) ;
dx . device ( d ) = dy * ( x > static_cast < T > ( 0 ) ) . template cast < T > ( ) +
dy * ( y + static_cast < T > ( alpha ) ) *
( x < static_cast < T > ( 0 ) ) . template cast < T > ( ) ;
}
} ;
@ -545,7 +555,7 @@ struct PowFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = x . pow ( factor) ;
y . device ( d ) = x . pow ( static_cast< T > ( factor) ) ;
}
} ;
@ -557,7 +567,8 @@ struct PowGradFunctor : public BaseActivationFunctor<T> {
}
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
dx . device ( d ) = dy * factor * x . pow ( factor - static_cast < T > ( 1 ) ) ;
dx . device ( d ) = dy * static_cast < T > ( factor ) *
x . pow ( static_cast < T > ( factor - static_cast < T > ( 1 ) ) ) ;
}
} ;
@ -571,7 +582,8 @@ struct STanhFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = scale_b * ( scale_a * x ) . tanh ( ) ;
y . device ( d ) =
static_cast < T > ( scale_b ) * ( static_cast < T > ( scale_a ) * x ) . tanh ( ) ;
}
} ;
@ -585,8 +597,10 @@ struct STanhGradFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
auto temp = ( scale_a * x ) . tanh ( ) * ( scale_a * x ) . tanh ( ) ;
dx . device ( d ) = dy * scale_a * scale_b * ( static_cast < T > ( 1 ) - temp ) ;
auto a = static_cast < T > ( scale_a ) ;
auto b = static_cast < T > ( scale_b ) ;
auto temp = ( a * x ) . tanh ( ) * ( a * x ) . tanh ( ) ;
dx . device ( d ) = dy * a * b * ( static_cast < T > ( 1 ) - temp ) ;
}
} ;
@ -599,7 +613,8 @@ struct ThresholdedReluFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y >
void operator ( ) ( Device d , X x , Y y ) const {
y . device ( d ) = ( x > static_cast < T > ( threshold ) ) . template cast < T > ( ) * x ;
auto th = static_cast < T > ( threshold ) ;
y . device ( d ) = ( x > th ) . template cast < T > ( ) * x ;
}
} ;
@ -612,7 +627,8 @@ struct ThresholdedReluGradFunctor : public BaseActivationFunctor<T> {
template < typename Device , typename X , typename Y , typename dY , typename dX >
void operator ( ) ( Device d , X x , Y y , dY dy , dX dx ) const {
dx . device ( d ) = dy * ( x > static_cast < T > ( threshold ) ) . template cast < T > ( ) ;
auto th = static_cast < T > ( threshold ) ;
dx . device ( d ) = dy * ( x > th ) . template cast < T > ( ) ;
}
} ;