alibSubt
Subtracts scalar or array arguments, element-wise. The PV-WAVE API for this routine is the
Subtraction Operator -.
Prototypes
void alibSubtb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibSubts( wvlong m, wvlong n, short *p, short *q, short *r )
void alibSubti( wvlong m, wvlong n, int *p, int *q, int *r )
void alibSubtl( wvlong m, wvlong n, wvlong *p, wvlong *q, wvlong *r )
void alibSubtf( wvlong m, wvlong n, float *p, float *q, float *r )
void alibSubtd( wvlong m, wvlong n, double *p, double *q, double *r )
void alibSubtc( wvlong m, wvlong n, COMPLEX *p, COMPLEX *q, COMPLEX *r )
void alibSubtz( 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 difference 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" );
alibSubts( 6, 0, s0, &s2, s );
alibPrintArrays( 1, 1, 1, 6, s, NULL );
printf( "\n\n show the result of s2 - s0, element-wise" );
alibSubts( 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" );
alibSubts( 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" );
alibSubts( 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
-3 -2 -1 0 1 2
show the result of s2 - s0, element-wise
3 2 1 0 -1 -2
show a second 6-element vector s1
7 2 6 3 5 3
show the result of s0 - s1, element-wise
-5 1 -2 2 1 4
now do the same operation, but in-place in s0,
and show the result as a (2,3) matrix
-5 1 -2
2 1 4
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.