# [−][src]Function arrayfire::gemm

pub fn gemm<T>(

output: &mut Array<T>,

optlhs: MatProp,

optrhs: MatProp,

alpha: Vec<T>,

lhs: &Array<T>,

rhs: &Array<T>,

beta: Vec<T>

) where

T: HasAfEnum + FloatingPoint,

BLAS general matrix multiply (GEMM) of two Array objects

This provides a general interface to the BLAS level 3 general matrix multiply (GEMM), which is generally defined as:

\begin{equation} C = \alpha * opA(A)opB(B) + \beta * C \end{equation}

where $\alpha$ (**alpha**) and $\beta$ (**beta**) are both scalars; $A$ and $B$ are the matrix
multiply operands; and $opA$ and $opB$ are noop
(if optLhs is MatProp::NONE) or transpose
(if optLhs is MatProp::TRANS) operations on $A$ or $B$ before the
actual GEMM operation. Batched GEMM is supported if at least either $A$ or $B$ have more than
two dimensions (see af::matmul
for more details on broadcasting). However, only one **alpha** and one **beta** can be used
for all of the batched matrix operands.

The `output`

Array can be used both as an input and output. An allocation will be performed
if you pass an empty Array (i.e. `let c: Array<f32> = (0 as i64).into();`

). If a valid Array
is passed as $C$, the operation will be performed on that Array itself. The C Array must be
the correct type and shape; otherwise, an error will be thrown.

Note: Passing an Array that has not been initialized to the C array will cause undefined behavior.

# Examples

Given below is an example of using gemm API with existing Arrays

use arrayfire::{Array, Dim4, print, randu, gemm}; let dims = Dim4::new(&[5, 5, 1, 1]); let alpha = vec![1.0 as f32]; let beta = vec![2.0 as f32]; let lhs = randu::<f32>(dims); let rhs = randu::<f32>(dims); let mut result = Array::new_empty(dims); gemm(&mut result, arrayfire::MatProp::NONE, arrayfire::MatProp::NONE, alpha, &lhs, &rhs, beta);

If you don't have an existing Array, you can also use gemm in the following fashion. However, if there is no existing Array that you need to fill and your use case doesn't deal with alpha and beta from gemm equation, it is recommended to use matmul for more terse code.

use arrayfire::{Array, Dim4, af_array, print, randu, gemm}; let dims = Dim4::new(&[5, 5, 1, 1]); let alpha = vec![1.0 as f32]; let beta = vec![2.0 as f32]; let lhs = randu::<f32>(dims); let rhs = randu::<f32>(dims); let mut result: Array::<f32> = (std::ptr::null_mut() as af_array).into(); gemm(&mut result, arrayfire::MatProp::NONE, arrayfire::MatProp::NONE, alpha, &lhs, &rhs, beta);

# Parameters

`optlhs`

- Transpose left hand side before the function is performed, uses one of the values of MatProp`optrhs`

- Transpose right hand side before the function is performed, uses one of the values of MatProp`alpha`

is alpha value;`lhs`

is the Array on left hand side`rhs`

is the Array on right hand side`beta`

is beta value;

# Return Values

Array, result of gemm operation