matmul
- arrayfire.matmul(lhs: Array, rhs: Array, /, lhs_opts: MatProp = MatProp.NONE, rhs_opts: MatProp = MatProp.NONE) Array
Performs generalized matrix multiplication between two arrays with optional transposition or hermitian transposition operations on the input matrices.
Parameters
- lhsaf.Array
A 2-dimensional, real or complex ArrayFire array representing the left-hand side matrix.
- rhsaf.Array
A 2-dimensional, real or complex ArrayFire array representing the right-hand side matrix.
- lhs_optsaf.MATPROP, optional
Operation to perform on the lhs matrix before multiplication. Defaults to af.MATPROP.NONE. Options include: - af.MATPROP.NONE: No operation. - af.MATPROP.TRANS: Transpose lhs. - af.MATPROP.CTRANS: Hermitian transpose (conjugate transpose) lhs.
- rhs_optsaf.MATPROP, optional
Operation to perform on the rhs matrix before multiplication. Defaults to af.MATPROP.NONE. Options include: - af.MATPROP.NONE: No operation. - af.MATPROP.TRANS: Transpose rhs. - af.MATPROP.CTRANS: Hermitian transpose (conjugate transpose) rhs.
Returns
- outaf.Array
The result of the matrix multiplication. The output is a 2-dimensional ArrayFire array.
Notes
The data types of lhs and rhs must be the same.
Batch operations (multiplying multiple pairs of matrices at once) are not supported in this implementation.
Examples
Basic matrix multiplication:
A = af.randu(5, 4, dtype=af.Dtype.f32) B = af.randu(4, 6, dtype=af.Dtype.f32) C = matmul(A, B)
Matrix multiplication with the left-hand side transposed:
C = matmul(A, B, lhs_opts=af.MATPROP.TRANS)
Matrix multiplication with both matrices transposed:
C = matmul(A, B, lhs_opts=af.MATPROP.TRANS, rhs_opts=af.MATPROP.TRANS)