alibSumDim
Sums the elements along one dimension of an array. The PV-WAVE API for this routine is the
TOTAL Function with
Dimension keyword.
Prototypes
void alibSumDimb( wvlong m, wvlong n, wvlong *d, UCHAR *p, float *q )
void alibSumDims( wvlong m, wvlong n, wvlong *d, short *p, float *q )
void alibSumDimi( wvlong m, wvlong n, wvlong *d, int *p, float *q )
void alibSumDiml( wvlong m, wvlong n, wvlong *d, wvlong *p, float *q )
void alibSumDimf( wvlong m, wvlong n, wvlong *d, float *p, float *q )
void alibSumDimd( wvlong m, wvlong n, wvlong *d, double *p, double *q )
void alibSumDimc( wvlong m, wvlong n, wvlong *d, COMPLEX *p, COMPLEX *q )
void alibSumDimz( wvlong m, wvlong n, wvlong *d, DCOMPLEX *p, DCOMPLEX *q )
Parameters
m — (Input) The dimension (>=0) along which elements are summed. In a matrix for example, set m=0 to sum each column or set m=1 to sum each row.
n — (Input) The number of dimensions in the source array.
*d — (Input) The n-element array of dimensions for the source array.
*p — (Input) The n-dimensional source array of dimensions d.
*q — (Input/Output) The destination array. On output, array q contains the sum of each 'column' along dimension m, and it is usually interpreted as (n–1)-dimensional with dimensions d[0], ..., d[m–1], 1, d[m+1], ..., d[n–1]. Computation is done in the data-type of array q.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
/* arrays of dimensions to use for all the examples */
wvlong dm[4]={4,3,2,2};
/* source data for all the examples */
UCHAR b0[48];
/* output array to use for all the examples */
float b[24];
/* initialize the source data */
alibinit( NULL, NULL, NULL, NULL );
alibIndexb( 48, 0, 1, b0 );
printf( "\n\n show a (4,3) matrix" );
alibPrintArrayb( 1, 1, 4, 3, b0, NULL );
printf( "\n\n sum over dimension 0, i.e. sum each column" );
alibSumDimb( 0, 2, dm, b0, b );
alibPrintArrayf( 1, 1, 1, 3, b, NULL );
printf( "\n\n sum over dimension 1, i.e. sum each row" );
alibSumDimb( 1, 2, dm, b0, b );
alibPrintArrayf( 1, 1, 4, 1, b, NULL );
printf( "\n\n show a (4,3,2) array" );
alibPrintArrayb( 1, 4, 3, 2, b0, NULL );
printf( "\n\n sum over dimension 0" );
alibSumDimb( 0, 3, dm, b0, b );
alibPrintArrayf( 1, 1, 3, 2, b, NULL );
printf( "\n\n sum over dimension 1" );
alibSumDimb( 1, 3, dm, b0, b );
alibPrintArrayf( 1, 4, 1, 2, b, NULL );
printf( "\n\n sum over dimension 2" );
alibSumDimb( 2, 3, dm, b0, b );
alibPrintArrayf( 1, 4, 3, 1, b, NULL );
printf( "\n\n show a (4,3,2,2) array" );
alibPrintArrayb( 4, 3, 2, 2, b0, NULL );
printf( "\n\n sum over dimension 0" );
alibSumDimb( 0, 4, dm, b0, b );
alibPrintArrayf( 1, 3, 2, 2, b, NULL );
}
Output:
show a (4,3) matrix
0 1 2
3 4 5
6 7 8
9 10 11
sum over dimension 0, i.e. sum each column
1.800e+01 2.200e+01 2.600e+01
sum over dimension 1, i.e. sum each row
3.000e+00
1.200e+01
2.100e+01
3.000e+01
show a (4,3,2) array
0 1
2 3
4 5
6 7
8 9
10 11
12 13
14 15
16 17
18 19
20 21
22 23
sum over dimension 0
3.600e+01 4.000e+01
4.400e+01 4.800e+01
5.200e+01 5.600e+01
sum over dimension 1
6.000e+00 9.000e+00
2.400e+01 2.700e+01
4.200e+01 4.500e+01
6.000e+01 6.300e+01
sum over dimension 2
1.000e+00
5.000e+00
9.000e+00
1.300e+01
1.700e+01
2.100e+01
2.500e+01
2.900e+01
3.300e+01
3.700e+01
4.100e+01
4.500e+01
show a (4,3,2,2) array
0 1
2 3
4 5
6 7
8 9
10 11
12 13
14 15
16 17
18 19
20 21
22 23
24 25
26 27
28 29
30 31
32 33
34 35
36 37
38 39
40 41
42 43
44 45
46 47
sum over dimension 0
7.200e+01 7.600e+01
8.000e+01 8.400e+01
8.800e+01 9.200e+01
9.600e+01 1.000e+02
1.040e+02 1.080e+02
1.120e+02 1.160e+02
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.