alibPow
General powers for scalar or array arguments, element-wise. The PV-WAVE API for this routine is the
Exponentiation Operator ^.
Prototypes
void alibPowf( wvlong m, wvlong n, float *p, float *q, float *r )
void alibPowd( wvlong m, wvlong n, double *p, double *q, double *r )
void alibPowc( wvlong m, wvlong n, COMPLEX *p, COMPLEX *q, COMPLEX *r )
void alibPowz( 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 argument p to the power of argument q, element-wise. 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 */
float f0=0.25, f1[4]={0.5,1.5,2.5,3.5}, f2[4]={0.5,-0.5,1.5,-1.5};
/* make an output array */
float f[4];
printf( "\n\n show scalar f0 and 4-element vectors f1 and f2" );
alibinit( NULL, NULL, NULL, NULL );
alibPrintArrayf( 1, 1, 1, 1, &f0, NULL );
alibPrintArrayf( 1, 1, 1, 4, f1, NULL );
alibPrintArrayf( 1, 1, 1, 4, f2, NULL );
printf( "\n\n show f0 to the power f1, element-wise" );
alibPowf( 0, 4, &f0, f1, f );
alibPrintArrayf( 1, 1, 1, 4, f, "%12.4e" );
printf( "\n\n show f1 to the power f0, element-wise" );
alibPowf( 4, 0, f1, &f0, f );
alibPrintArrayf( 1, 1, 1, 4, f, NULL );
printf( "\n\n show f1 to the power f2, element-wise" );
alibPowf( 4, 4, f1, f2, f );
alibPrintArrayf( 1, 1, 1, 4, f, NULL );
printf( "\n\n repeat the operation in-place; print result as a matrix" );
alibPowf( 4, 4, f1, f2, f1 );
alibPrintArrayf( 1, 1, 2, 2, f1, NULL );
}
Output:
show scalar f0 and 4-element vectors f1 and f2
2.500e-01
5.000e-01 1.500e+00 2.500e+00 3.500e+00
5.000e-01 -5.000e-01 1.500e+00 -1.500e+00
show f0 to the power f1, element-wise
5.0000e-01 1.2500e-01 3.1250e-02 7.8125e-03
show f1 to the power f0, element-wise
8.409e-01 1.107e+00 1.257e+00 1.368e+00
show f1 to the power f2, element-wise
7.071e-01 8.165e-01 3.953e+00 1.527e-01
repeat the operation in-place; print result as a matrix
7.071e-01 8.165e-01
3.953e+00 1.527e-01
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.