Class ActivationHelper
Provides centralized helper methods for applying activation functions with optimal performance. Uses Engine methods (GPU/SIMD) for known activation types, falls back to standard activation otherwise.
public static class ActivationHelper
- Inheritance
-
ActivationHelper
- Inherited Members
Remarks
This class consolidates activation type-checking logic in one place, following DRY (Don't Repeat Yourself) and SOLID principles. All layers should use these methods instead of duplicating if-else chains.
Methods
ApplyActivation<T>(IVectorActivationFunction<T>?, Tensor<T>, IEngine)
Applies a vector activation function to a tensor using Engine methods when possible.
public static Tensor<T> ApplyActivation<T>(IVectorActivationFunction<T>? activation, Tensor<T> input, IEngine engine)
Parameters
activationIVectorActivationFunction<T>The vector activation function to apply.
inputTensor<T>The input tensor to activate.
engineIEngineThe engine to use for optimized operations.
Returns
- Tensor<T>
The activated tensor, or input unchanged if activation is null.
Type Parameters
TThe numeric type (float, double, etc.).
ApplyActivation<T>(IVectorActivationFunction<T>?, Vector<T>, IEngine)
Applies a vector activation function to a vector using Engine methods when possible.
public static Vector<T> ApplyActivation<T>(IVectorActivationFunction<T>? activation, Vector<T> input, IEngine engine)
Parameters
activationIVectorActivationFunction<T>The vector activation function to apply.
inputVector<T>The input vector to activate.
engineIEngineThe engine to use for optimized operations.
Returns
- Vector<T>
The activated vector, or input unchanged if activation is null.
Type Parameters
TThe numeric type (float, double, etc.).