alibMinMaxDim
Locates the extrema along one dimension of an array, e.g., along each column or row of a matrix or along some set of 'columns' in a multidimensional array. The PV-WAVE API for this routine is the
MIN Function or
MAX Function with
Dimension keyword.
Prototypes
void alibMinMaxDimb( wvlong m, wvlong n, wvlong *d, UCHAR *p, wvlong *i, wvlong *j, UCHAR *q, UCHAR *r )
void alibMinMaxDims( wvlong m, wvlong n, wvlong *d, short *p, wvlong *i, wvlong *j, short *q, short *r )
void alibMinMaxDimi( wvlong m, wvlong n, wvlong *d, int *p, wvlong *i, wvlong *j, int *q, int *r )
void alibMinMaxDiml( wvlong m, wvlong n, wvlong *d, wvlong *p, wvlong *i, wvlong *j, wvlong *q, wvlong *r )
void alibMinMaxDimf( wvlong m, wvlong n, wvlong *d, float *p, wvlong *i, wvlong *j, float *q, float *r )
void alibMinMaxDimd( wvlong m, wvlong n, wvlong *d, double *p, wvlong *i, wvlong *j, double *q, double *r )
Parameters
m — (Input) The dimension (>=0) along which the extrema are to be located.In a matrix for example, 0 and 1 correspond to columns and rows, respectively.
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.
*i — (Input/Output) The array of one-dimensional indices into array p, where each index locates the first occurrence of the minimum value in a row along dimension m. If array i is not of interest, input i as NULL, otherwise the number of elements in the array must equal the number of 'rows' along dimension m.
*j — (Input/Output) The array of one-dimensional indices into array p, where each index locates the first occurrence of the maximum value in a row along dimension m. If array j is not of interest, input j as NULL, otherwise the number of elements in the array must equal the number of 'rows' along dimension m.
*q — (Input/Output) The array containing the minimum value in each 'row' along dimension m. If array q is not of interest, input q as NULL, otherwise the number of elements in the array must equal the number of 'rows' along dimension m.
*r — (Input/Output) The array containing the maximum value in each 'row' along dimension m. If array r is not of interest, input r as NULL, otherwise the number of elements in the array must equal the number of 'rows' along dimension m.
Arrays i, j, q, and r are usually interpreted as (n–1)-dimensional with dimensions d[0],...,d[m–1],1,d[m+1],...,d[n–1].
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
/* arrays of dimensions to use for 2d and 3d examples */
wvlong d2[2]={5,4}, d3[3]={3,3,3};
/* source data for all examples */
UCHAR b[27]={1,1,1,3,3,0,3,3,2,0,0,0,2,2,1,3,1,2,1,0,2,3,2,2,3,1,0};
/* output arrays to use for all examples */
wvlong bi[9], bj[9];
UCHAR b0[9], b1[9];
printf( "\n\n show (5,4) matrix b" );
alibinit( NULL, NULL, NULL, NULL );
alibPrintArrayb( 1, 1, 5, 4, b, NULL );
printf( "\n\n show min and max values along each column of matrix b \n" );
printf( " and show the indices where they first occur in their column" );
alibMinMaxDimb( 0, 2, d2, b, bi, bj, b0, b1 );
alibPrintArrayb( 1, 1, 1, 4, b0, NULL );
alibPrintArrayb( 1, 1, 1, 4, b1, NULL );
alibPrintArrayl( 1, 1, 1, 4, bi, "%8lld" );
alibPrintArrayl( 1, 1, 1, 4, bj, "%8lld" );
printf( "\n\n show min and max values along each row of matrix b \n" );
printf( " and show the indices where they first occur in their row" );
alibMinMaxDimb( 1, 2, d2, b, bi, bj, b0, b1 );
alibPrintArrayb( 1, 1, 5, 1, b0, NULL );
alibPrintArrayb( 1, 1, 5, 1, b1, NULL );
alibPrintArrayl( 1, 1, 5, 1, bi, "%8lld" );
alibPrintArrayl( 1, 1, 5, 1, bj, "%8lld" );
printf( "\n\n show (3,3,3) array b" );
alibPrintArrayb( 1, 3, 3, 3, b, NULL );
printf( "\n\n show min and max values along leading dimension of b \n" );
printf( " and show the indices where they first occur in their 'column'");
alibMinMaxDimb( 0, 3, d3, b, bi, bj, b0, b1 );
alibPrintArrayb( 1, 1, 3, 3, b0, NULL );
alibPrintArrayb( 1, 1, 3, 3, b1, NULL );
alibPrintArrayl( 1, 1, 3, 3, bi, "%8lld" );
alibPrintArrayl( 1, 1, 3, 3, bj, "%8lld" );
printf( "\n\n show min and max values along middle dimension of b \n" );
printf( " and show the indices where they first occur in their column");
alibMinMaxDimb( 1, 3, d3, b, bi, bj, b0, b1 );
alibPrintArrayb( 1, 3, 1, 3, b0, NULL );
alibPrintArrayb( 1, 3, 1, 3, b1, NULL );
alibPrintArrayl( 1, 3, 1, 3, bi, "%8lld" );
alibPrintArrayl( 1, 3, 1, 3, bj, "%8lld" );
printf( "\n\n show min and max values along trailing dimension of b \n" );
printf( " and show the indices where they first occur in their row");
alibMinMaxDimb( 2, 3, d3, b, bi, bj, b0, b1 );
alibPrintArrayb( 1, 3, 3, 1, b0, NULL );
alibPrintArrayb( 1, 3, 3, 1, b1, NULL );
alibPrintArrayl( 1, 3, 3, 1, bi, "%8lld" );
alibPrintArrayl( 1, 3, 3, 1, bj, "%8lld" );
}
Output:
show (5,4) matrix b
1 1 1 3
3 0 3 3
2 0 0 0
2 2 1 3
1 2 1 0
show min and max values along each column of matrix b
and show the indices where they first occur in their column
1 0 0 0
3 2 3 3
0 5 10 11
4 13 6 3
show min and max values along each row of matrix b
and show the indices where they first occur in their row
1
0
0
1
0
3
3
2
3
2
0
5
9
14
19
3
4
8
15
17
show (3,3,3) array b
1 1 1
3 3 0
3 3 2
0 0 0
2 2 1
3 1 2
1 0 2
3 2 2
3 1 0
show min and max values along leading dimension of b
and show the indices where they first occur in their 'column'
0 0 0
2 2 0
3 1 0
1 1 2
3 3 2
3 3 2
9 10 11
12 13 5
6 16 26
0 1 20
3 4 23
6 7 8
show min and max values along middle dimension of b
and show the indices where they first occur in their column
1 1 0
0 0 0
1 0 0
3 3 2
3 2 2
3 2 2
0 1 5
9 10 11
18 19 26
3 4 8
15 13 17
21 22 20
show min and max values along trailing dimension of b
and show the indices where they first occur in their row
1
0
2
0
1
1
0
2
0
1
3
3
0
2
3
2
3
3
0
5
8
9
14
16
19
22
26
0
3
6
9
12
15
20
21
24
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.