Skip to content

Commit 7ecb268

Browse files
committed
Add updated doc for matmul
1 parent 979b25d commit 7ecb268

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/ops.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,31 @@ const ThreadContext = struct {
14311431
shared_counter: *ThreadLocalData,
14321432
};
14331433

1434+
/// Multiplies two matrices and returns the resulting matrix.
1435+
///
1436+
/// This function takes two 2D arrays (matrices) as input and performs matrix multiplication.
1437+
/// The number of columns in the first matrix must be equal to the number of rows in the second matrix.
1438+
///
1439+
/// # Parameters
1440+
/// - `matrix1`: The first matrix (2D array) to be multiplied.
1441+
/// - `matrix2`: The second matrix (2D array) to be multiplied.
1442+
///
1443+
/// # Returns
1444+
/// A new matrix (2D array) which is the result of multiplying `matrix1` by `matrix2`.
1445+
///
1446+
/// # Example
1447+
/// ```zig
1448+
/// const matrix1 = [[1, 2, 3], [4, 5, 6]];
1449+
/// const matrix2 = [[7, 8], [9, 10], [11, 12]];
1450+
/// const result = matmul(matrix1, matrix2);
1451+
/// // result is [[58, 64], [139, 154]]
1452+
/// ```
1453+
///
1454+
/// # Notes
1455+
/// - The function assumes that the input tensors are properly initialized and deinitialized.
1456+
/// - The function uses SIMD for f32 data type to optimize matrix multiplication
1457+
/// - The function uses a simple triple-loop matrix multiplication for other data types.
1458+
/// - SIMD support for f64 and f16 will be added in future versions.
14341459
pub fn matmul(comptime T: type, a: Tensor(T), b: Tensor(T), allocator: Allocator) !Tensor(T) {
14351460
if (a.shape.len != 2 or b.shape.len != 2) {
14361461
return error.InvalidDimensions;

0 commit comments

Comments
 (0)