next up previous index
Next: F010 Linear Equations Up: CERNLIB Previous: F003 Elementary Matrix

F004 Matrix Multiplication

Routine ID: F004
Author(s): Library: KERNLIB
Submitter: Submitted: 18.12.1979
Language: Fortran or Assembler or COMPASSRevised: 27.05.1987

These subprograms calculate the matrix product

Z=XY or Z=XY,

where Y denotes the conjugate of the complex matrix Y, or one of the matrix expressions

Z=XY+Z, &quad;Z=XY-Z, &quad;Z=-XY+Z, &quad;Z=-XY-Z.

Structure:

SUBROUTINE subprograms
User Entry Names:
RMMLA, RMMLS, RMMLT, RMNMA, RMNMS,
DMMLA, DMMLS, DMMLT, DMNMA, DMNMS,
CMMLA, CMMLS, CMMLT, CMNMA, CMNMS, CMMLTC

External References: LOCF (N100) (some Fortran versions only).

Usage:

For t=R (type REAL), t=D (type DOUBLE PRECISION), t=C (type COMPLEX):
CALL tMMLT (M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21,W)Z=XY

CALL tMMLA (M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21)Z=XY+Z

CALL tMMLS (M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21)Z=XY-Z

CALL tMNMA (M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21)Z=-XY+Z

CALL tMNMS (M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21)Z=-XY-Z

CALL CMMLTC(M,N,K,X11,X12,X21,Y11,Y12,Y21,Z11,Z12,Z21,W)Z=XY

M,N,K
( INTEGER) The mathematical dimensions of the matrices: X has M rows and N columns, Y has N rows and K columns, Z has M rows and K columns.
X11,X12,X21
(Type according to t) Array elements. They must contain the elements x11,x12,x21 of the matrix X.
Y11,Y12,Y21
(Type according to t) Array elements. They must contain the elements y11,y12,y21 of the matrix Y.
Z11,Z12,Z21
(Type according to t) Array elements. On exit, they will contain the elements z11,z12,z21 of the matrix Z.
W
(Type according to t) Working space array as specified below, required only if Z overlaps X or Y. Otherwise a dummy variable.
For M < 1 or N < 1 or K < 1 , all subroutines return control without action.

The matrices X, Y and Z need not to be stored according to the Fortran conventions: any equidistant spacing of their rows and columns is permitted. In particular, matrices may be stored row-wise. Each subroutine can work with the transpose of a matrix. To make this possible, each matrix is specified in the calling sequence by three arguments. For example, the called subroutine will operate on the matrix A=(aij) if the actual arguments which replace X11, X12, X21 in the calling sequence are a11,a12,a21 , and will operate on the transpose A'

of A if the actual arguments are a11,a21,a12 .

The only cases in which the result matrix Z is permitted to overlap X or Y are the following:
tMMLT:X=XY Y=Y'Y ,provided Wis an array of at least Kelements.
Y=XY X=XX' ,provided Wis an array of at least Melements.
CMMLTC:X=XY Y=Y'Y ,provided Wis an array of at least Kelements.
Y=XY X=XX' ,provided Wis an array of at least Melements.

Accuracy:

On computers with IBM 370 architecture, all routines that accumulate the inner product of type REAL or COMPLEX use double-precision arithmetic internally; the final result is then rounded to single precision.

Notes:

The product of a matrix and its transpose (or Hermitian conjugate) is recognized by tMMLT (or CMMLTC) and the computation is shortened accordingly.

Examples:

Assume that the two-dimensional arrays A, B, C, D, E, the one-dimensional array W, and the dummy variable V are declared by

    COMPLEX A(9,9),B(9,9),C(9,9),D(9,9),E(9,9),V,W(99)
and that a 4x5 matrix A, a 5x7 matrix B, and a 7x3 matrix C have been stored according to the Fortran conventions in arrays of corresponding name.
  1. To compute D=AB :
        CALL CMMLT (4,5,7,A,A(1,2),A(2,1),B,B(1,2),B(2,1),D,D(1,2),D(2,1),V).
    
    To pack the 4x7 product matrix AB row-wise into array W:
        CALL CMMLT (4,5,7,A,A(1,2),A(2,1),B,B(2,1),B(1,2),W,W(2),W(8),V).
    
    (Note that z11 goes into W(1), z12 into W(2), and z21 into W(8)).

    For the purpose of abbreviation we shall denote
    A,A(1,2),A(2,1) by a, A,A(2,1),A(1,2) by a',
    and similarly for arrays B, C, D, E. The first example above then becomes

        CALL CMMLT(4,5,7,a,b,d,V).
    
  2. To compute D=B'A'=(AB)' :
        CALL CMMLT(7,5,4,b',a',d,V)  or  CMMLT(4,5,7,a,b,d',V).
    
  3. To compute D=AA' and E=A'A :
        CALL CMMLT(4,5,4,a,a',d,V)
        CALL CMMLT(5,4,5,a',a,e,V).
    
  4. To replace A by AB or by AA' :
        CALL CMMLT(4,5,7,a,b,a,W)  or  CALL CMMLT(4,5,4,a,a',a,W).
    
    These two calls require a working vector W containing 7 or 4 complex elements, respectively.
  5. To compute D=AB and E=BC=(C'B')' :
        CALL CMMLTC(4,5,7,a,b,d,V)
        CALL CMMLTC(3,7,5,c',b',e',V).
    

F010



next up previous index
Next: F010 Linear Equations Up: CERNLIB Previous: F003 Elementary Matrix


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995