pub enum Activation {
Show 29 variants
Gelu,
GeluApprox,
Silu,
Relu,
Sigmoid,
Tanh,
Exp,
Log,
Sqrt,
Rsqrt,
Neg,
Abs,
Sin,
Cos,
Tan,
Atan,
Recip,
Round,
Floor,
Ceil,
Sign,
Softplus,
Elu,
Erf,
HardSwish,
HardSigmoid,
Mish,
Softsign,
LogSigmoid,
}Expand description
Unary element-wise activation functions.
Variants§
Gelu
GeluApprox
Silu
Relu
Sigmoid
Tanh
Exp
Log
Sqrt
Rsqrt
Neg
Abs
Sin
sin(x). Backward: dx = upstream · cos(x).
Cos
cos(x). Backward: dx = -upstream · sin(x).
Tan
tan(x). Backward: dx = upstream · sec²(x) = upstream · (1 + tan²(x)).
Atan
atan(x). Backward: dx = upstream · (1 / (1 + x²)).
Recip
Reciprocal 1 / x.
Round
Round to nearest integer (half-to-even), in f32.
Forward: x.round(). Backward: STE — treats as identity, so
the gradient passes through unchanged. Useful as a primitive
for composing custom quantization schemes (Mul-by-recip-scale
→ Round → Clamp → Mul-by-scale = a hand-rolled FakeQuantize
that the elementwise-region pass can fuse into a single kernel).
Floor
floor(x). Backward: 0 (piecewise-constant).
Ceil
ceil(x). Backward: 0.
Sign
sign(x) = -1/0/+1 (sign of zero is 0). Backward: 0.
Softplus
softplus(x) = ln(1 + eˣ). Backward: dx = u·sigmoid(x).
Elu
ELU (α=1): x if x>0 else eˣ-1. Backward: u·(1 if x>0 else eˣ).
Erf
erf(x) (Gauss error function). Backward: dx = u·(2/√π)·e^(-x²).
HardSwish
HardSwish x·clamp(x+3,0,6)/6. Backward: 0/1/(2x+3)/6 piecewise.
HardSigmoid
HardSigmoid clamp(x/6+0.5,0,1). Backward: 1/6 on |x|<3 else 0.
Mish
Mish x·tanh(softplus(x)).
Softsign
Softsign x/(1+|x|). Backward: 1/(1+|x|)².
LogSigmoid
LogSigmoid log(σ(x)) = min(x,0) − ln(1+e^(−|x|)). Backward: σ(−x).
Implementations§
Source§impl Activation
impl Activation
Sourcepub fn region_fusable(self) -> bool
pub fn region_fusable(self) -> bool
Activations that may be folded into a fused ElementwiseRegion /
TransformRegion chain. The newer scalar activations
(Floor/Ceil/Sign/Softplus/Elu) run only on the standalone
kernel path for now — the per-backend fused-region kernels don’t yet
carry their opcodes, and their default passthrough would silently
mis-evaluate them. Keeping them unfused is correct; a fused kernel is a
perf follow-up.
Source§impl Activation
impl Activation
Sourcepub const ALL: [Activation; 29]
pub const ALL: [Activation; 29]
Every Activation variant, for exhaustive test/parity fan-out.
Sourcepub const fn opcode_relu_first(self) -> u32
pub const fn opcode_relu_first(self) -> u32
“Relu-first” activation opcode: CUDA / wgpu / ROCm forward unary
kernels, and every backend’s activation-backward kernel
(activation_backward.{cu,comp,cl} + Metal). Relu=0 … Gelu=9 … Recip=17 … LogSigmoid=28.
Sourcepub const fn opcode_gelu_first(self) -> u32
pub const fn opcode_gelu_first(self) -> u32
“Gelu-first” activation opcode: Vulkan and oneAPI forward unary
kernels (act_id). Gelu=0, GeluApprox=1, Silu=2, Relu=3 … LogSigmoid=28. Note Round=16, Recip=17 (swapped vs enum order).
Trait Implementations§
Source§impl Clone for Activation
impl Clone for Activation
Source§fn clone(&self) -> Activation
fn clone(&self) -> Activation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Activation
Source§impl Debug for Activation
impl Debug for Activation
Source§impl<'de> Deserialize<'de> for Activation
impl<'de> Deserialize<'de> for Activation
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Activation, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Activation, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Activation
Source§impl Hash for Activation
impl Hash for Activation
Source§impl PartialEq for Activation
impl PartialEq for Activation
Source§impl Serialize for Activation
impl Serialize for Activation
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Activation
Auto Trait Implementations§
impl Freeze for Activation
impl RefUnwindSafe for Activation
impl Send for Activation
impl Sync for Activation
impl Unpin for Activation
impl UnsafeUnpin for Activation
impl UnwindSafe for Activation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more