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:

  1. Load the dense_linear_algebra library.

    AFL% load_library('dense_linear_algebra'); 

     

  2. 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)]
    ]  
  3. Perform the gemm calculation.

    AFL% gemm(A,B,C);   

     
    The output is:

    [
    [(2),(3)],
    [(4),(5)]
    ] Â