RWalib C Array Library User Guide > Array Indexing > alibPutSubset
  

alibPutSubset
Replaces a general subarray with an array. Unlike alibPutRange the subarray need not be contiguous within the source array, so if alibPutSubset is used to replace some slices, they need not be adjacent to one another. Contiguous subarrays are more efficiently replaced by alibPutRange. 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 alibPutSubsetb( wvlong n, wvlong *d, wvlong *b, wvlong **e, UCHAR *p, UCHAR *q )
void alibPutSubsets( wvlong n, wvlong *d, wvlong *b, wvlong **e, short *p, short *q )
void alibPutSubseti( wvlong n, wvlong *d, wvlong *b, wvlong **e, int *p, int *q )
void alibPutSubsetl( wvlong n, wvlong *d, wvlong *b, wvlong **e, wvlong *p, wvlong *q )
void alibPutSubsetf( wvlong n, wvlong *d, wvlong *b, wvlong **e, float *p, float *q )
void alibPutSubsetd( wvlong n, wvlong *d, wvlong *b, wvlong **e, double *p, double *q )
void alibPutSubsetc( wvlong n, wvlong *d, wvlong *b, wvlong **e, COMPLEX *p, COMPLEX *q )
void alibPutSubsetz( wvlong n, wvlong *d, wvlong *b, wvlong **e, DCOMPLEX *p, DCOMPLEX *q )
Parameters
n — (Input) The number of dimensions in the array containing the subarray to be replaced.
*d — (Input) The n-element array of dimensions in the array containing the subarray to be replaced.
*b — (Input) The n-element array of dimensions in the subarray. Some can be equal to 1, i.e., the subarray can have less than n dimensions.
**e — (Input) The n-element array of pointers to the index arrays defining the subarray to be replaced. Some can be 1-element arrays, i.e., the subarray can have less than n dimensions. Number of elements in array e[i] is b[i].
*p — (Input/Output) The array containing the subarray to be replaced. On output, the subarray has been replaced.
*q — (Input) The array which replaces the subarray in array p.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* array of dimensions to use for one-dimensional, two-dimensional, three-dimensional, and four-dimensional 
   examples */
   wvlong dims[4] = {2,3,4,5};
   /* lengths of index arrays to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional 
   examples */
   wvlong ddst[4] = {2,2,2,3};
   /* index arrays to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional examples */
   wvlong ind0[2] = {0,1};
   wvlong ind1[3] = {0,2,4};
   wvlong *indx[4] = {ind0,ind1,ind1,ind1};
   /* allocate arrays big enough for one-dimensional, two-dimensional, three-dimensional, and four-dimensional 
examples */
   UCHAR    *b, *b0;
   b0 = (UCHAR*)malloc(120*sizeof(UCHAR));
   b  = (UCHAR*)malloc(24*sizeof(UCHAR));
   /* initialize replacement data to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional    examples */
   alibinit( NULL, NULL, NULL, NULL );
   alibIndexb( 24, 120, 1, b );
   printf( "\n\n initialize and print one-dimensional array b0" );
      alibIndexb( 5, 0, 1, b0 );
      alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n print one-dimensional array b" );
      alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n replace even-indexed elements of b0 with b, print result" );
      alibPutSubsetb( 1, &dims[3], &ddst[3], &indx[3], b0, b );
      alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n initialize and print two-dimensional array b0" );
      alibIndexb( 20, 0, 1, b0 );
      alibPrintArrayb( 1, 1, 4, 5, b0, NULL );
   printf( "\n\n print two-dimensional array b" );
      alibPrintArrayb( 1, 1, 2, 3, b, NULL );
   printf( "\n\n replace even-indexed elements of b0 with b, print result" );
      alibPutSubsetb( 2, &dims[2], &ddst[2], &indx[2], b0, b );
      alibPrintArrayb( 1, 1, 4, 5, b0, NULL );
   printf( "\n\n initialize and print three-dimensional array b0" );
      alibIndexb( 60, 0, 1, b0 );
      alibPrintArrayb( 1, 3, 4, 5, b0, NULL );
   printf( "\n\n print three-dimensional array b" );
      alibPrintArrayb( 1, 2, 2, 3, b, NULL );
   printf( "\n\n replace even-indexed elements of b0 with b, print result" );
      alibPutSubsetb( 3, &dims[1], &ddst[1], &indx[1], b0, b );
      alibPrintArrayb( 1, 3, 4, 5, b0, NULL );
   printf( "\n\n initialize and print four-dimensional array b0" );
      alibIndexb( 120, 0, 1, b0 );
      alibPrintArrayb( 2, 3, 4, 5, b0, NULL );
   printf( "\n\n print four-dimensional array b" );
      alibPrintArrayb( 2, 2, 2, 3, b, NULL );
   printf( "\n\n in each slice of the leading dimension, \n" );
   printf( " replace even-indexed elements of b0 with b, print result" );
      alibPutSubsetb( 4, dims, ddst, indx, b0, b );
      alibPrintArrayb( 2, 3, 4, 5, b0, NULL );
}
 
Output:
 
 initialize and print one-dimensional array b0
 
   0   1   2   3   4
 
 print one-dimensional array b
 
 120 121 122
 
 replace even-indexed elements of b0 with b, print result
 
 120   1 121   3 122
 
 initialize and print two-dimensional array b0
 
   0   1   2   3   4
   5   6   7   8   9
  10  11  12  13  14
  15  16  17  18  19
 
 print two-dimensional array b
 
 120 121 122
 123 124 125
 
 replace even-indexed elements of b0 with b, print result
 
 120   1 121   3 122
   5   6   7   8   9
 123  11 124  13 125
  15  16  17  18  19
 
 initialize and print three-dimensional array b0
 
   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
 
 print three-dimensional array b
 
 120 121 122
 123 124 125
 
 126 127 128
 129 130 131
 
 replace even-indexed elements of b0 with b, print result
 
 120   1 121   3 122
   5   6   7   8   9
 123  11 124  13 125
  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
 
 126  41 127  43 128
  45  46  47  48  49
 129  51 130  53 131
  55  56  57  58  59
 
 initialize and print four-dimensional array b0
 
   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
 
 print four-dimensional array b
 
 120 121 122
 123 124 125
 
 126 127 128
 129 130 131
 
 132 133 134
 135 136 137
 
 138 139 140
 141 142 143
 
 in each slice of the leading dimension, 
 replace even-indexed elements of b0 with b, print result
 
 120   1 121   3 122
   5   6   7   8   9
 123  11 124  13 125
  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
 
 126  41 127  43 128
  45  46  47  48  49
 129  51 130  53 131
  55  56  57  58  59
 
 132  61 133  63 134
  65  66  67  68  69
 135  71 136  73 137
  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
 
 138 101 139 103 140
 105 106 107 108 109
 141 111 142 113 143
 115 116 117 118 119

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