RWalib C Array Library User Guide > Array Indexing > alibGetSubset
  

alibGetSubset
Retrieves a general subarray of an array. Unlike alibGetRange the subarray need not be contiguous within the source array, so if alibGetSubset is used to retrieve some slices, they need not be adjacent to one another. Contiguous subarrays are more efficiently retrieved by alibGetRange. The PV-WAVE API for this routine is array indexing with at least one index array and at least one scalar or range operator.
Prototypes
void alibGetSubsetb( wvlong n, wvlong *d, wvlong *b, wvlong **e, UCHAR *p, UCHAR *q )
void alibGetSubsets( wvlong n, wvlong *d, wvlong *b, wvlong **e, short *p, short *q )
void alibGetSubseti( wvlong n, wvlong *d, wvlong *b, wvlong **e, int *p, int *q )
void alibGetSubsetl( wvlong n, wvlong *d, wvlong *b, wvlong **e, wvlong *p, wvlong *q )
void alibGetSubsetf( wvlong n, wvlong *d, wvlong *b, wvlong **e, float *p, float *q )
void alibGetSubsetd( wvlong n, wvlong *d, wvlong *b, wvlong **e, double *p, double *q )
void alibGetSubsetc( wvlong n, wvlong *d, wvlong *b, wvlong **e, COMPLEX *p, COMPLEX *q )
void alibGetSubsetz( wvlong n, wvlong *d, wvlong *b, wvlong **e, DCOMPLEX *p, DCOMPLEX *q )
Parameters
n — (Input) The number of dimensions in the source array.
*d — (Input) The n-element array of dimensions in the source array.
*b — (Input) The n-element array of dimensions in the destination array. Some could be 1, effectively yielding an array with less than n dimensions.
**e — (Input) The n-element array of pointers to the index arrays defining the subarray to be retrieved from the source array. Some could be single element index arrays, effectively yielding a grid with less than n dimensions. The number of elements in array e[i] is b[i].
*p — (Input) The source array.
*q — (Input/Output) The destination array. On return, array q is a copy of the grid of data within array p defined by index arrays e.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   wvlong dsrc[4] = {2,3,4,5};
   wvlong ddst[4] = {2,2,2,3};
   wvlong ind0[2] = {0,1};
   wvlong ind1[3] = {0,2,4};
   wvlong *indx[4] = {ind0,ind1,ind1,ind1};
   UCHAR    *b, *b0;
   b0 = (UCHAR*)malloc(120*sizeof(UCHAR));
   b  = (UCHAR*)malloc(24*sizeof(UCHAR));
   alibinit( NULL, NULL, NULL, NULL );
   /* first fabricate some test data */
   alibIndexb( 120, 0, 1, b0 );
   printf( "\n\n print 1d-array, retrieve and print its even-indexed data" );
   alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   alibGetSubsetb( 1, &dsrc[3], &ddst[3], &indx[3], b0, b );
   alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n print 2d-array, retrieve and print its even-indexed data" );
   alibPrintArrayb( 1, 1, 4, 5, b0, NULL );
   alibGetSubsetb( 2, &dsrc[2], &ddst[2], &indx[2], b0, b );
   alibPrintArrayb( 1, 1, 2, 3, b, NULL );
   printf( "\n\n print 3d-array, retrieve and print its even-indexed data" );
   alibPrintArrayb( 1, 3, 4, 5, b0, NULL );
   alibGetSubsetb( 3, &dsrc[1], &ddst[1], &indx[1], b0, b );
   alibPrintArrayb( 1, 2, 2, 3, b, NULL );
   printf( "\n\n print 4d-array with leading dimension of 2, retrieve \n" );
   printf( " and print even-indexed data from each slice of that dimension");
   alibPrintArrayb( 2, 3, 4, 5, b0, NULL );
   alibGetSubsetb( 4, dsrc, ddst, indx, b0, b );
   alibPrintArrayb( 2, 2, 2, 3, b, NULL );
}
 
Output:
 
 print 1d-array, retrieve and print its even-indexed data
 
   0   1   2   3   4
 
   0   2   4
 
 print 2d-array, retrieve and print its even-indexed data
 
   0   1   2   3   4
   5   6   7   8   9
  10  11  12  13  14
  15  16  17  18  19
 
   0   2   4
  10  12  14
 
 print 3d-array, retrieve and print its even-indexed data
 
   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  48  49
  50  51  52  53  54
  55  56  57  58  59
 
   0   2   4
  10  12  14
 
  40  42  44
  50  52  54
 
 
 print 4d-array with leading dimension of 2, retrieve 
 and print even-indexed data from each slice of that dimension
 
   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  48  49
  50  51  52  53  54
  55  56  57  58  59
 
  60  61  62  63  64
  65  66  67  68  69
  70  71  72  73  74
  75  76  77  78  79
 
  80  81  82  83  84
  85  86  87  88  89
  90  91  92  93  94
  95  96  97  98  99
 
 100 101 102 103 104
 105 106 107 108 109
 110 111 112 113 114
 115 116 117 118 119
 
   0   2   4
  10  12  14
 
  40  42  44
  50  52  54
 
  60  62  64
  70  72  74
 
 100 102 104
 110 112 114

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.