RWalib C Array Library User Guide > Arithmetic Operations > alibMult
  

alibMult
Multiplies scalar or array arguments, element-wise. The PV-WAVE API for this routine is the Multiplication Operator *.
Prototypes
void alibMultb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibMults( wvlong m, wvlong n, short *p, short *q, short *r )
void alibMulti( wvlong m, wvlong n, int *p, int *q, int *r )
void alibMultl( wvlong m, wvlong n, wvlong *p, wvlong *q, wvlong *r )
void alibMultf( wvlong m, wvlong n, float *p, float *q, float *r )
void alibMultd( wvlong m, wvlong n, double *p, double *q, double *r )
void alibMultc( wvlong m, wvlong n, COMPLEX *p, COMPLEX *q, COMPLEX *r )
void alibMultz( wvlong m, wvlong n, DCOMPLEX *p, DCOMPLEX *q, DCOMPLEX *r )
Parameters
m — (Input) The number of elements in the first array operand. A value of 0 indicates that the first operand is a scalar.
n — (Input) The number of elements in the second array operand. A value of 0 indicates that the second operand is a scalar. If both operands are arrays then n must equal m.
*p — (Input) The pointer to the first operand.
*q — (Input) The pointer to the second operand.
*r — (Input/Output) The destination array. On return, array r contains the element-wise product of the two operands. The operation can be done in-place, i.e., r can equal p or q.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
  /* make up some input data for the examples */
    short    s0[6]={2,3,4,5,6,7}, s1[6]={7,2,6,3,5,3}, s2=5;
  /* make an output array */
    short    s[6];
  printf( "\n\n show 6-element vector s0 and scalar s2" );
    alibinit( NULL, NULL, NULL, NULL );
    alibPrintArrays( 1, 1, 1, 6, s0, NULL );
    alibPrintArrays( 1, 1, 1, 1, &s2, NULL );
  printf( "\n\n show the result of s0 * s2, element-wise" );
    alibMults( 6, 0, s0, &s2, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n show the result of s2 * s0, element-wise" );
    alibMults( 0, 6, &s2, s0, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n show a second 6-element vector s1" );
    alibPrintArrays( 1, 1, 1, 6, s1, NULL );
  printf( "\n\n show the result of s0 * s1, element-wise" );
    alibMults( 6, 6, s0, s1, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n now do the same operation, but in-place in s0, \n" );
  printf( " and show the result as a (2,3) matrix" );
    alibMults( 6, 6, s0, s1, s0 );
    alibPrintArrays( 1, 1, 2, 3, s0, NULL );
}
 
Output:
 
 show 6-element vector s0 and scalar s2
 
       2       3       4       5       6       7
 
       5
 
 show the result of s0 * s2, element-wise
 
      10      15      20      25      30      35
 
 show the result of s2 * s0, element-wise
 
      10      15      20      25      30      35
 
 show a second 6-element vector s1
 
       7       2       6       3       5       3
 
 show the result of s0 * s1, element-wise
 
      14       6      24      15      30      21
 
 now do the same operation, but in-place in s0, 
 and show the result as a (2,3) matrix
 
      14       6      24
      15      30      21

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.