alibCartProd
Returns the Cartesian product of some arrays, e.g., the coordinate grid defined by a set of coordinate vectors. The PV-WAVE API for this routine is the
CPROD Function.
Prototypes
void alibCartProdb( wvlong m, wvlong *n, UCHAR **p, UCHAR *q )
void alibCartProds( wvlong m, wvlong *n, short **p, short *q )
void alibCartProdi( wvlong m, wvlong *n, int **p, int *q )
void alibCartProdl( wvlong m, wvlong *n, wvlong **p, wvlong *q )
void alibCartProdf( wvlong m, wvlong *n, float **p, float *q )
void alibCartProdd( wvlong m, wvlong *n, double **p, double *q )
void alibCartProdc( wvlong m, wvlong *n, COMPLEX **p, COMPLEX *q )
void alibCartProdz( wvlong m, wvlong *n, DCOMPLEX **p, DCOMPLEX *q )
Parameters
m — (Input) The number of source arrays.
*n — (Input) The m-element array specifying the number of elements in each source array.
**p — (Input) The m-element array of pointers to the source arrays. The number of elements in array p[i] is n[i].
*q — (Input/Output) The destination array. On return, array q contains the Cartesian product of the source arrays and is viewed as a (m,n[0]*...*n[m-1]) matrix of k points in m-dimensional space representing the coordinate grid defined by the m vectors p. q[k*i+j] is the ith coordinate of the jth grid point.
Example
The following example is a four-dimensional example.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
/* make up four coordinate vectors to use for a
/* four-dimensional example */
wvlong j, k, n[4]={2,2,3,4};
UCHAR *b, b0[2], b1[2], b2[3], b3[4], *bi[4]={b0,b1,b2,b3};
alibinit( NULL, NULL, NULL, NULL );
alibIndexb( 2, 0, 1, b0 );
alibIndexb( 2, 0, 1, b1 );
alibIndexb( 3, 0, 1, b2 );
alibIndexb( 4, 0, 1, b3 );
/* make array to hold grid of points defined by the coordinate
/* vectors */
b = (UCHAR*)malloc(4*2*2*3*4*sizeof(UCHAR));
printf( "\n\n print each of the four coordinate vectors" );
alibPrintArrayb( 1, 1, 1, 2, b0, NULL );
alibPrintArrayb( 1, 1, 1, 2, b1, NULL );
alibPrintArrayb( 1, 1, 1, 3, b2, NULL );
alibPrintArrayb( 1, 1, 1, 4, b3, NULL );
printf( "\n\n show the four-dimensional grid defined by the coordinate vectors" );
alibCartProdb( 4, n, bi, b );
printf( "\n\n" );
for ( k=0; k<48; k++ ) {
printf( "\n" );
for ( j=0; j<4; j++ ) printf( "%4d", b[48*j+k] );
}
}
Output:
print each of the four coordinate vectors
0 1
0 1
0 1 2
0 1 2 3
show the four-dimensional grid defined by the coordinate vectors
0 0 0 0
0 0 0 1
0 0 0 2
0 0 0 3
0 0 1 0
0 0 1 1
0 0 1 2
0 0 1 3
0 0 2 0
0 0 2 1
0 0 2 2
0 0 2 3
0 1 0 0
0 1 0 1
0 1 0 2
0 1 0 3
0 1 1 0
0 1 1 1
0 1 1 2
0 1 1 3
0 1 2 0
0 1 2 1
0 1 2 2
0 1 2 3
1 0 0 0
1 0 0 1
1 0 0 2
1 0 0 3
1 0 1 0
1 0 1 1
1 0 1 2
1 0 1 3
1 0 2 0
1 0 2 1
1 0 2 2
1 0 2 3
1 1 0 0
1 1 0 1
1 1 0 2
1 1 0 3
1 1 1 0
1 1 1 1
1 1 1 2
1 1 1 3
1 1 2 0
1 1 2 1
1 1 2 2
1 1 2 3
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.