RWalib C Array Library User Guide > Linear Algebra > alibMatMul
  

alibMatMul
Multiplies matrices. The PV-WAVE API for this routine is the Matrix Multiplication Operator #.
Prototypes
void alibMatMulf( wvlong m, wvlong h, wvlong n, float *p, float *q, float *r )
void alibMatMuld( wvlong m, wvlong h, wvlong n, double *p, double *q, double *r )
void alibMatMulc( wvlong m, wvlong h, wvlong n, COMPLEX *p, COMPLEX *q, COMPLEX *r )
void alibMatMulz( wvlong m, wvlong h, wvlong n, DCOMPLEX *p, DCOMPLEX *q, DCOMPLEX *r )
Parameters
m — (Input) The first dimension of the first matrix operand.
h — (Input) The second dimension of the first matrix operand.
n — (Input) The second dimension of the second matrix operand.
*p — (Input) The (m,h) matrix operand.
*q — (Input) The (h,n) matrix operand.
*r — (Input/Output) The destination array. On return, array r contains the (m,n) matrix which results from multiplying matrices p and q.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* input and output arrays for the examples */
   float f[80], f0[80], f1[80];
   /* make up some data for the input arrays */
   alibinit( NULL, NULL, NULL, NULL );
   alibIndexf( 80, 2, 1, f0 );
   alibIndexf( 80, 3, 1, f1 );
   printf( "\n\n show 4-element vectors f0 and f1" );
      alibPrintArrayf( 1, 1, 1, 4, f0, NULL );
      alibPrintArrayf( 1, 1, 1, 4, f1, NULL );
   printf( "\n\n show the inner product of vectors f0 and f1" );
      alibMatMulf( 1, 4, 1, f0, f1, f );
      alibPrintArrayf( 1, 1, 1, 1, f, NULL );
   printf( "\n\n show 4-element vector f0 and 3-element vector f1" );
      alibPrintArrayf( 1, 1, 1, 4, f0, NULL );
      alibPrintArrayf( 1, 1, 1, 3, f1, NULL );
   printf( "\n\n show the outer product of vectors f0 and f1" );
      alibMatMulf( 4, 1, 3, f0, f1, f );
      alibPrintArrayf( 1, 1, 4, 3, f, NULL );
   printf( "\n\n show (4,3) matrix f0 and 3-element vector f1" );
      alibPrintArrayf( 1, 1, 4, 3, f0, NULL );
      alibPrintArrayf( 1, 1, 3, 1, f1, NULL );
   printf( "\n\n show the result of matrix f0 times vector f1" );
      alibMatMulf( 4, 3, 1, f0, f1, f );
      alibPrintArrayf( 1, 1, 4, 1, f, NULL );
   printf( "\n\n show (1,4) vector f0 and (4,4) matrix f1" );
      alibPrintArrayf( 1, 1, 1, 4, f0, NULL );
      alibPrintArrayf( 1, 1, 4, 4, f1, NULL );
   printf( "\n\n show the result of covector f0 times matrix f1" );
      alibMatMulf( 1, 4, 4, f0, f1, f );
      alibPrintArrayf( 1, 1, 1, 4, f, NULL );
   printf( "\n\n show (4,3) matrix f0 and (3,2) matrix f1" );
      alibPrintArrayf( 1, 1, 4, 3, f0, NULL );
      alibPrintArrayf( 1, 1, 3, 2, f1, NULL );
   printf( "\n\n show the result of matrix f0 times matrix f1" );
      alibMatMulf( 4, 3, 2, f0, f1, f );
      alibPrintArrayf( 1, 1, 4, 2, f, NULL );
}
 
Output:
 
 show 4-element vectors f0 and f1
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
   3.000e+00   4.000e+00   5.000e+00   6.000e+00
 
 show the inner product of vectors f0 and f1
 
   6.800e+01
 
 show 4-element vector f0 and 3-element vector f1
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
   3.000e+00   4.000e+00   5.000e+00
 
 show the outer product of vectors f0 and f1
 
   6.000e+00   8.000e+00   1.000e+01
   9.000e+00   1.200e+01   1.500e+01
   1.200e+01   1.600e+01   2.000e+01
   1.500e+01   2.000e+01   2.500e+01
 
 show (4,3) matrix f0 and 3-element vector f1
 
   2.000e+00   3.000e+00   4.000e+00
   5.000e+00   6.000e+00   7.000e+00
   8.000e+00   9.000e+00   1.000e+01
   1.100e+01   1.200e+01   1.300e+01
 
   3.000e+00
   4.000e+00
   5.000e+00
 
 show the result of matrix f0 times vector f1
 
   3.800e+01
   7.400e+01
   1.100e+02
   1.460e+02
 
 show (1,4) vector f0 and (4,4) matrix f1
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
   3.000e+00   4.000e+00   5.000e+00   6.000e+00
   7.000e+00   8.000e+00   9.000e+00   1.000e+01
   1.100e+01   1.200e+01   1.300e+01   1.400e+01
   1.500e+01   1.600e+01   1.700e+01   1.800e+01
 
 show the result of covector f0 times matrix f1
 
   1.460e+02   1.600e+02   1.740e+02   1.880e+02
 
 show (4,3) matrix f0 and (3,2) matrix f1
 
   2.000e+00   3.000e+00   4.000e+00
   5.000e+00   6.000e+00   7.000e+00
   8.000e+00   9.000e+00   1.000e+01
   1.100e+01   1.200e+01   1.300e+01
 
   3.000e+00   4.000e+00
   5.000e+00   6.000e+00
   7.000e+00   8.000e+00
 
 show the result of matrix f0 times matrix f1
 
   4.900e+01   5.800e+01
   9.400e+01   1.120e+02
   1.390e+02   1.660e+02
   1.840e+02   2.200e+02

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.