RWalib C Array Library User Guide > Arithmetic Operations > alibAdd
  

alibAdd
Adds scalar or array arguments, element-wise. The PV-WAVE API for this routine is the Addition Operator +.
Prototypes
void alibAddb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibAdds( wvlong m, wvlong n, short *p, short *q, short *r )
void alibAddi( wvlong m, wvlong n, int *p, int *q, int *r )
void alibAddl( wvlong m, wvlong n, wvlong *p, wvlong *q, wvlong *r )
void alibAddf( wvlong m, wvlong n, float *p, float *q, float *r )
void alibAddd( wvlong m, wvlong n, double *p, double *q, double *r )
void alibAddc( wvlong m, wvlong n, COMPLEX *p, COMPLEX *q, COMPLEX *r )
void alibAddz( 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 sum 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" );
    alibAdds( 6, 0, s0, &s2, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n show the result of s2 + s0, element-wise" );
    alibAdds( 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" );
    alibAdds( 6, 6, s0, s1, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n now do the same operation, but in-place in s1, \n" );
  printf( " and show the result as a (2,3) matrix" );
    alibAdds( 6, 6, s0, s1, s1 );
    alibPrintArrays( 1, 1, 2, 3, s1, 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
 
       7       8       9      10      11      12
 
 show the result of s2 + s0, element-wise
 
       7       8       9      10      11      12
 
 show a second 6-element vector s1
 
       7       2       6       3       5       3
 
 show the result of s0 + s1, element-wise
 
       9       5      10       8      11      10
 
 now do the same operation, but in-place in s1, 
 and show the result as a (2,3) matrix
 
       9       5      10
       8      11      10

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