gemm
The gemm operator performs a matrix calculation of the form αAB +βC, with three matrices and two real constants you supply.
Synopsis
gemm(A_matrix, B_matrix, C_matrix [, transa:Â BOOLEAN]Â [, transb:Â BOOLEAN]Â [, alpha: DOUBLE]Â [, beta:Â DOUBLE] );
Library
The gemm operator resides in the Dense Linear Algebra library. Run the following query to load this library:
AFL% load_library('dense_linear_algebra');
Summary
Given matrices A, B, and C and the constants a and b, the gemm() operator can perform any of the following calculations:Â
- αAB + βC
- αATB + βC
- αABT + βC
- αATBT + βC
where T is the transpose of a matrix.
Restrictions apply. The matrices must be compatible for matrix multiplication and addition. For example, for the calculation αAB + βC, if A has dimensions m × n, then B must have dimensions n × p and C must have dimensions m × p. That is, the number of columns of A must equal the number of rows of B. Furthermore, C has the same number of columns as A and the same number of rows as B. The result has the same dimensions as C.
There are four optional named parameters:
- If transa: is set, perform the multiplication with the transpose of A (instead of A). Example syntax: transa: 1
- If transb: is set, perform the multiplication with the transpose of B (instead of B). Example syntax: transb: true
- If alpha: is set, multiply the matrix product by alpha before performing the addition. Example syntax: alpha: 3.1415926
- If beta: is set, multiply matrix C by beta before performing the addition. Example syntax: beta: 434.998
For more information, see:
Limitations
- The first attribute of all three arrays must be of type double. All other attributes are ignored.
- The chunks of the input matrices must be square, and require a chunk interval between 32 and 1024.
- Each dimension of each matrix requires the following characteristics:
- The starting index must be zero.
- The ending index cannot be '*'.
- Currently, the chunk overlap must be zero.
Example
To create three matrices and calculate the gemm, do the following:
Load the dense_linear_algebra library.
AFL% load_library('dense_linear_algebra');Â
Â
Create matrices A, B, and C.
AFL% CREATE ARRAY A <val:double>[i=0:1; j=0:1]; Â
AFL% store(build (A, i*2 + j + 1), A);Â
The output is:[ [(1),(2)], [(3),(4)] ]
AFL% store(build(<val:double>[i=0:1; j=0:1],iif(i=j,1,0)),B);Â
The output is:[ [(1),(0)], [(0),(1)] ]Â
AFL% CREATE ARRAY C <val:double>[i=0:1; j=0:1]; Â
AFL% store(build (C, 1), C); Â
The output is:[ [(1),(1)], [(1),(1)] ] Â
Perform the gemm calculation.
AFL% gemm(A,B,C); Â
Â
The output is:[ [(2),(3)], [(4),(5)] ] Â