alibRepArray
Replicates an array along one or more dimensions. The API is aimed at four basic vector or matrix operations, but depending on parameter interpretation, these same basic memory manipulations can represent n-dimensional tiling or stretching in any direction. Common uses of this routine are:
Concatenates or interleave a vector with itself multiple times.
Tiles a matrix or
n-dimensional array with a vector along any one of its dimensions.
Vertically or horizontally concatenates a matrix with itself multiple times.
Tiles a three-dimensional or
n-dimensional array with a matrix along any pair of its dimensions.
Vertically or horizontally stretches a two-dimensional or three-dimensional array, e.g., an image.
Tiles an
n-dimensional array with an
m-dimensional array along any
m of its dimensions.
Stretches an
n-dimensional array in any direction.
The PV-WAVE API for this routine is the
REBIN Function with the
Sample keyword.
Prototypes
void alibRepArrayb( wvlong d, wvlong m, wvlong n, UCHAR *p, UCHAR *q )
void alibRepArrays( wvlong d, wvlong m, wvlong n, short *p, short *q )
void alibRepArrayi( wvlong d, wvlong m, wvlong n, int *p, int *q )
void alibRepArrayl( wvlong d, wvlong m, wvlong n, wvlong *p, wvlong *q )
void alibRepArrayf( wvlong d, wvlong m, wvlong n, float *p, float *q )
void alibRepArrayd( wvlong d, wvlong m, wvlong n, double *p, double *q )
void alibRepArrayc( wvlong d, wvlong m, wvlong n, COMPLEX *p, COMPLEX *q )
void alibRepArrayz( wvlong d, wvlong m, wvlong n, DCOMPLEX *p, DCOMPLEX *q )
Parameters
d — (Input) An integer specifying which one of the four basic types of memory manipulation are to be performed. The four cases are described below, where values m, n, p, and q are the same as in the prototypes.
d=0 aims the API at concatenation of a vector with itself multiple times, but depending on parameter interpretation, this memory manipulation can also represent the replication of an
n-dimensional array along leading dimensions up to and including its first nondegenerate dimension. Common examples for mode
d=0:
Concatenates
m-element vector
p with itself
n times and puts the result in
q.
Tiles (
n,
m) matrix
q with (1,
m) row-vector
p.
Tiles (
n0,
n1,
m) array
q with (1,1,
m) row-vector
p, where
n0*
n1=
n.
Tiles (
n*
m0,
m1) matrix
q with (
m0,
m1) matrix
p, where
m0*
m1=
m.
Tiles (n,
m0,
m1) array
q with (1,
m0,
m1) matrix
p, where
m0*
m1=
m.
Tiles (n*
m0,
m1,
m2) array
q with (
m0,
m1,
m2) array
p, where
m0*
m1*
m2=m.
Tiles (n,
m0,
m1,
m2) array
q with (1,
m0,
m1,
m2) array
p, where
m0*
m1*
m2=
m.
d=1 aims the API at interleaving a vector with itself multiple times, but depending on parameter interpretation, this memory manipulation can also represent the replication an
n-dimensional array along trailing degenerate dimensions, i.e., along trailing dimensions of length 1. Furthermore, replication along a trailing degenerate dimension can instead be interpreted as a stretch along the trailing nondegenerate dimension. Common examples for mode d=1:
Interleaves
m-element vector
p with itself
n times and puts the result in
q.
Tiles (
m,
n) matrix
q with (
m,1) column-vector
p.
Tiles (
m,
n0,
n1) array
q with (
m,1,1) column-vector
p, where
n0*
n1=
n.
Tiles (
m0,
m1,
n) array
q with (
m0,
m1,1) matrix
p, where
m0*
m1=
m.
Equivalently, stretches (
m0,
m1) matrix
p into (
m0,n*
m1) matrix
q.
Tiles (
m0,
m1,
m2,
n) array
q with (
m0,
m1,
m2,1) array
p, where
m0*
m1*
m2=
m.
Equivalently, stretches (
m0,
m1,
m2) array
p into (
m0,
m1,n*
m2) array
q.
d>1 aims the API at a composite of the previous two cases, i.e., at
d-fold concatenation of interleavings, but depending on the parameter interpretation, this memory manipulation can also represent replication of an
n-dimensional array along leading dimensions up to and including its first nondegenerate dimension and along trailing degenerate dimensions. Although mode
d>1 subsumes the previous two modes, the others are more efficient for the restricted cases. Common examples for mode
d>1:
d-fold concatenation of
n-fold interleaving of
m-element vector
p.
Tiles (
d,
m,
n) array
q with a (1,
m,1) vector
p.
Tiles (
d,
m0,
m1,
n) array q with (1,
m0,
m1,1) matrix
p, where
m0*
m1=
m.
d<0 aims the API at the |
d|-fold horizontal concatenation of a matrix with itself, but depending on parameter interpretation, this memory manipulation can also represent replication or stretch of an
n-dimensional array along any dimension. Replicating along a dimension is equivalent to stretching the prior dimension. Mode
d<0 subsumes the other modes, but these other modes are computationally more efficient for their own restricted cases, so mode
d<0 should be used only for replication along an intermediate or trailing nondegenerate dimension or for stretching along a non-trailing dimension. Common examples for mode
d<0:
Tiles (
m,|
d|
*n) matrix
q with (
m,n) matrix
p.
Equivalently, stretches (
m,n) matrix
p into (|
d|*
m,n) matrix
q.
Tiles (
m,|
d|,
n) array
q with (
m,1,
n) matrix
p.
Tiles (
m,|
d|*
n0,
n1) array
q with (
m,
n0,
n1) array
p, where
n0*
n1=
n.
Equivalently, stretches (
m,
n0,
n1) array
p into (|
d|*
m,
n0,
n1) array
q.
Tiles (
m0,
m1,|
d|*
n) array
q with (
m0,
m1,
n) array
p, where
m0*
m1=
m.
Equivalently, stretches (
m0,
m1,
n) array
p into (
m0,|
d|*
m1,
n) array
q.
m — (Input) For modes d=0, d=1, and d>1, m is the number of elements in the source array. For mode d<0, m is the product of all dimensions preceding the concatenation dimension, or the product of all dimensions preceding and including the stretch dimension. See examples above.
n — (Input) For modes d=0 and d=1, n is the number of elements in the destination array divided by m. For modes d>1 and d<0, n is the number of elements in the destination array divided by the product m*|d|. See examples above.
*p — (Input) The source array. For modes d=0, d=1, and d>1, array p has m elements. For mode d<0, array p has m*n elements.
*q — (Input/Output) Destination array. For modes d=0 and d=1, array q has m*n elements. For modes d>1 and d<0, array q has m*n*|d| elements.
Example
The following examples are for each mode associated with parameter d, covering all the common tiling and stretching operations listed above.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
/* make enough example input data to use for all the
/* examples */
UCHAR *b, b0[64];
alibinit( NULL, NULL, NULL, NULL );
alibIndexb( 64, 0, 1, b0 );
/* make an output array big enough for all the examples */
b = (UCHAR*)malloc(256*sizeof(UCHAR));
/**/
printf( "\n\n TILE ALONG LEADING DIMENSION: \n" );
/**/
printf( "\n\n show 3-element vector b0" );
alibPrintArrayb( 1, 1, 1, 3, b0, NULL );
printf( "\n\n concatenate 3-element vector b0 to itself 4 times" );
alibRepArrayb( 0, 3, 4, b0, b );
alibPrintArrayb( 1, 1, 1, 12, b, NULL );
printf( "\n\n this can also represent (4,3) tiling with (1,3) vector" );
alibPrintArrayb( 1, 1, 4, 3, b, NULL );
printf( "\n\n or it can represent (2,2,3) tiling with (1,1,3) vector" );
alibPrintArrayb( 1, 2, 2, 3, b, NULL );
printf( "\n\n show (2,3) matrix b0" );
alibPrintArrayb( 1, 1, 2, 3, b0, NULL );
printf( "\n\n vertically tile an (8,3) matrix with (2,3) matrix b0" );
alibRepArrayb( 0, 6, 4, b0, b );
alibPrintArrayb( 1, 1, 8, 3, b, NULL );
printf( "\n\n this also represents (4,2,3) tiling with (1,2,3) matrix" );
alibPrintArrayb( 1, 4, 2, 3, b, NULL );
printf( "\n\n show (2,3,4) array b0" );
alibPrintArrayb( 1, 2, 3, 4, b0, NULL );
printf( "\n\n tile a (6,3,4) array with (2,3,4) array b0" );
alibRepArrayb( 0, 24, 3, b0, b );
alibPrintArrayb( 1, 6, 3, 4, b, NULL );
printf( "\n\n also represents (3,2,3,4) tiling with (1,2,3,4) array" );
alibPrintArrayb( 3, 2, 3, 4, b, NULL );
/**/
printf( "\n\n TILE ALONG TRAILING DEGENERATE DIMENSION, \n" );
printf( " OR EQIVALENTLY, STRETCH ALONG TRAILING DIMENSION: \n" );
/**/
printf( "\n\n show 3-element vector b0" );
alibPrintArrayb( 1, 1, 1, 3, b0, NULL );
printf( "\n\n interleave 3-element vector b0 with itself 4 times" );
alibRepArrayb( 1, 3, 4, b0, b );
alibPrintArrayb( 1, 1, 1, 12, b, NULL );
printf( "\n\n this can also represent (3,4) tiling with (3,1) vector" );
alibPrintArrayb( 1, 1, 3, 4, b, NULL );
printf( "\n\n or it can represent (3,2,2) tiling with (3,1,1) vector" );
alibPrintArrayb( 1, 3, 2, 2, b, NULL );
printf( "\n\n show (2,3) matrix b0" );
alibPrintArrayb( 1, 1, 2, 3, b0, NULL );
printf( "\n\n tile a (2,3,4) array with (2,3,1) matrix b0" );
alibRepArrayb( 1, 6, 4, b0, b );
alibPrintArrayb( 1, 2, 3, 4, b, NULL );
printf( "\n\n also represents stretching a (2,3) into a (2,12) matrix" );
alibPrintArrayb( 1, 1, 2, 12, b, NULL );
printf( "\n\n show (3,2,4) array b0" );
alibPrintArrayb( 1, 3, 2, 4, b0, NULL );
printf( "\n\n tile a (3,2,4,5) array with (3,2,4,1) array b0" );
alibRepArrayb( 1, 24, 5, b0, b );
alibPrintArrayb( 3, 2, 4, 5, b, NULL );
printf( "\n\n also represents stretching (3,2,4) into (3,2,20) array" );
alibPrintArrayb( 1, 3, 2, 20, b, NULL );
/**/
printf( "\n\n TILE ALONG LEADING AND TRAILING DEGENERATE DIMS: \n" );
/**/
printf( "\n\n show 4-element vector b0" );
alibPrintArrayb( 1, 1, 1, 4, b0, NULL );
printf( "\n\n tile a (12,2) matrix with (4,1) vector b0" );
alibRepArrayb( 3, 4, 2, b0, b );
alibPrintArrayb( 1, 1, 12, 2, b, NULL );
printf( "\n\n also represents tiling (3,4,2) array with (1,4,1) vector" );
alibPrintArrayb( 1, 3, 4, 2, b, NULL );
/**/
printf( "\n\n TILE ALONG AN INTERMEDIATE OR TRAILING DIMENSION, \n" );
printf( " OR EQUIVALENTLY, STRETCH ALONG THE PRECEDING DIMENSION: \n" );
/**/
printf( "\n\n show (4,2) matrix b0" );
alibPrintArrayb( 1, 1, 4, 2, b0, NULL );
printf( "\n\n horizontally tile a (4,6) matrix with (4,2) matrix b0" );
alibRepArrayb( -3, 4, 2, b0, b );
alibPrintArrayb( 1, 1, 4, 6, b, NULL );
printf( "\n\n can also represent stretching (4,2) into (12,2) matrix" );
alibPrintArrayb( 1, 1, 12, 2, b, NULL );
printf( "\n\n or it can represent (4,3,2) tiling with a (4,1,2) matrix" );
alibPrintArrayb( 1, 4, 3, 2, b, NULL );
printf( "\n\n show (3,2,4) array b0" );
alibPrintArrayb( 1, 3, 2, 4, b0, NULL );
printf( "\n\n tile a (3,4,4) array with (3,2,4) array b0" );
alibRepArrayb( -2, 3, 8, b0, b );
alibPrintArrayb( 1, 3, 4, 4, b, NULL );
printf( "\n\n can also represent stretching (3,2,4) into (6,2,4) array" );
alibPrintArrayb( 1, 6, 2, 4, b, NULL );
printf( "\n\n tile a (3,2,8) array with (3,2,4) array b0" );
alibRepArrayb( -2, 6, 4, b0, b );
alibPrintArrayb( 1, 3, 2, 8, b, NULL );
printf( "\n\n can also represent stretching (3,2,4) into (3,4,4) array" );
alibPrintArrayb( 1, 3, 4, 4, b, NULL );
}
Output:
TILE ALONG LEADING DIMENSION:
show 3-element vector b0
0 1 2
concatenate 3-element vector b0 to itself 4 times
0 1 2 0 1 2 0 1 2 0 1 2
this can also represent (4,3) tiling with (1,3) vector
0 1 2
0 1 2
0 1 2
0 1 2
or it can represent (2,2,3) tiling with (1,1,3) vector
0 1 2
0 1 2
0 1 2
0 1 2
show (2,3) matrix b0
0 1 2
3 4 5
vertically tile an (8,3) matrix with (2,3) matrix b0
0 1 2
3 4 5
0 1 2
3 4 5
0 1 2
3 4 5
0 1 2
3 4 5
this also represents (4,2,3) tiling with (1,2,3) matrix
0 1 2
3 4 5
0 1 2
3 4 5
0 1 2
3 4 5
0 1 2
3 4 5
show (2,3,4) 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
tile a (6,3,4) array with (2,3,4) 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
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
also represents (3,2,3,4) tiling with (1,2,3,4) 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
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
TILE ALONG TRAILING DEGENERATE DIMENSION,
OR EQIVALENTLY, STRETCH ALONG TRAILING DIMENSION:
show 3-element vector b0
0 1 2
interleave 3-element vector b0 with itself 4 times
0 0 0 0 1 1 1 1 2 2 2 2
this can also represent (3,4) tiling with (3,1) vector
0 0 0 0
1 1 1 1
2 2 2 2
or it can represent (3,2,2) tiling with (3,1,1) vector
0 0
0 0
1 1
1 1
2 2
2 2
show (2,3) matrix b0
0 1 2
3 4 5
tile a (2,3,4) array with (2,3,1) matrix b0
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
also represents stretching a (2,3) into a (2,12) matrix
0 0 0 0 1 1 1 1 2 2 2 2
3 3 3 3 4 4 4 4 5 5 5 5
show (3,2,4) 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
tile a (3,2,4,5) array with (3,2,4,1) array b0
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
6 6 6 6 6
7 7 7 7 7
8 8 8 8 8
9 9 9 9 9
10 10 10 10 10
11 11 11 11 11
12 12 12 12 12
13 13 13 13 13
14 14 14 14 14
15 15 15 15 15
16 16 16 16 16
17 17 17 17 17
18 18 18 18 18
19 19 19 19 19
20 20 20 20 20
21 21 21 21 21
22 22 22 22 22
23 23 23 23 23
also represents stretching (3,2,4) into (3,2,20) array
0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7
8 8 8 8 8 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11
12 12 12 12 12 13 13 13 13 13 14 14 14 14 14 15 15 15 15 15
16 16 16 16 16 17 17 17 17 17 18 18 18 18 18 19 19 19 19 19
20 20 20 20 20 21 21 21 21 21 22 22 22 22 22 23 23 23 23 23
TILE ALONG LEADING AND TRAILING DEGENERATE DIMS:
show 4-element vector b0
0 1 2 3
tile a (12,2) matrix with (4,1) vector b0
0 0
1 1
2 2
3 3
0 0
1 1
2 2
3 3
0 0
1 1
2 2
3 3
also represents tiling (3,4,2) array with (1,4,1) vector
0 0
1 1
2 2
3 3
0 0
1 1
2 2
3 3
0 0
1 1
2 2
3 3
TILE ALONG AN INTERMEDIATE OR TRAILING DIMENSION,
OR EQUIVALENTLY, STRETCH ALONG THE PRECEDING DIMENSION:
show (4,2) matrix b0
0 1
2 3
4 5
6 7
horizontally tile a (4,6) matrix with (4,2) matrix b0
0 1 0 1 0 1
2 3 2 3 2 3
4 5 4 5 4 5
6 7 6 7 6 7
can also represent stretching (4,2) into (12,2) matrix
0 1
0 1
0 1
2 3
2 3
2 3
4 5
4 5
4 5
6 7
6 7
6 7
or it can represent (4,3,2) tiling with a (4,1,2) matrix
0 1
0 1
0 1
2 3
2 3
2 3
4 5
4 5
4 5
6 7
6 7
6 7
show (3,2,4) 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
tile a (3,4,4) array with (3,2,4) array b0
0 1 2 3
4 5 6 7
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
16 17 18 19
20 21 22 23
can also represent stretching (3,2,4) into (6,2,4) array
0 1 2 3
4 5 6 7
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
8 9 10 11
12 13 14 15
16 17 18 19
20 21 22 23
16 17 18 19
20 21 22 23
tile a (3,2,8) array with (3,2,4) array b0
0 1 2 3 0 1 2 3
4 5 6 7 4 5 6 7
8 9 10 11 8 9 10 11
12 13 14 15 12 13 14 15
16 17 18 19 16 17 18 19
20 21 22 23 20 21 22 23
can also represent stretching (3,2,4) into (3,4,4) array
0 1 2 3
0 1 2 3
4 5 6 7
4 5 6 7
8 9 10 11
8 9 10 11
12 13 14 15
12 13 14 15
16 17 18 19
16 17 18 19
20 21 22 23
20 21 22 23
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.