@@ -13,8 +13,19 @@ const expectError = testing.expectError;
1313const max_items_per_row = 6 ; // Number of elements to show per row
1414const max_rows = 8 ; // Maximum number of rows to show before truncating
1515
16- // SIMD Tuning parameters
16+ /// SIMD Tuning parameters
17+ /// Tile size for SIMD matrix multiplication.
18+ /// The tile size is used to partition the input matrices into smaller submatrices
19+ /// that can be loaded into the cache and processed efficiently.
20+ /// The tile size should be chosen based on the cache size and the size of the
21+ /// input matrices to maximize cache utilization and minimize cache misses.
22+ /// Default value is 64.
1723pub const Tile : usize = 64 ; // Tile size
24+ /// Vector size for SIMD operations.
25+ /// The vector size is used to load and process multiple elements in parallel
26+ /// using SIMD instructions. The vector size should be chosen based on the
27+ /// target SIMD architecture to maximize performance.
28+ /// Default value is 32.
1829pub const Vec : usize = 32 ; // Vector size
1930
2031//--------------------------------- Transformation Operations ---------------------------------
@@ -1876,6 +1887,23 @@ fn softmax(comptime T: type, tensor: *Tensor(T), dim: usize) !void {
18761887 }
18771888}
18781889
1890+ /// Applies the Gaussian Error Linear Unit (GELU) activation function to the input.
1891+ ///
1892+ /// The GELU activation function is defined as:
1893+ /// GELU(x) = 0.5 * x * (1 + tanh(sqrt(2 / π) * (x + 0.044715 * x^3)))
1894+ ///
1895+ /// This function is used in neural networks to introduce non-linearity.
1896+ /// It is known for its smooth and differentiable properties, which can help
1897+ /// with the training of deep learning models.
1898+ ///
1899+ /// Parameters:
1900+ /// - `x`: The input value to the GELU function.
1901+ ///
1902+ /// Returns:
1903+ /// - The output value after applying the GELU function to the input.
1904+ ///
1905+ /// Note:
1906+ /// - If the array is empty, the behavior of this function is undefined.
18791907pub fn gelu (comptime T : type , tensor : * Tensor (T )) ! void {
18801908 if (@typeInfo (T ) != .Float ) {
18811909 @compileError ("GELU operation requires floating-point tensor" );
@@ -1893,6 +1921,19 @@ pub fn gelu(comptime T: type, tensor: *Tensor(T)) !void {
18931921 }
18941922}
18951923
1924+ /// Returns the index of the maximum value in the given array.
1925+ ///
1926+ /// This function iterates through the provided array and compares each element
1927+ /// to find the maximum value. It then returns the index of this maximum value.
1928+ ///
1929+ /// Parameters:
1930+ /// - `array`: The array of values to search through.
1931+ ///
1932+ /// Returns:
1933+ /// - `usize`: The index of the maximum value in the array.
1934+ ///
1935+ /// Note:
1936+ /// - If the array is empty, the behavior of this function is undefined.
18961937pub fn argmax (comptime T : type , input : Tensor (T )) ! usize {
18971938 if (input .data .len == 0 or input .shape .len == 0 ) {
18981939 return error .EmptyTensor ;
0 commit comments