Conditional SIMD Operations
Context
- Mojo Reference: SIMD select method
- Mojo Version: 24.2.0
Demo: Vectorized Relu Function
This demo illustrates a practical application of conditional SIMD operations to implement the Relu activation function in a vectorized manner. The Relu function is defined as returning 0 for all input values less than 0 and the input value itself for those greater than 0.
|
|
Output:
relu(-3.0) = 0.0
relu(-2.0) = 0.0
relu(-1.0) = 0.0
relu(0.0) = 0.0
relu(1.0) = 1.0
relu(2.0) = 2.0
relu(3.0) = 3.0
Remarks
Special thanks to @sora from the Modular Discord community for elucidating this technique.