RWalib C Array Library User Guide > Linear Algebra > alibTranspose
  

alibTranspose
Transposes any two dimensions of an array. General permutations are obtained as products of transpositions. The PV-WAVE API for this routine is the TRANSPOSE Function.
Prototypes
void alibTransposeb( wvlong n, wvlong b, wvlong e, wvlong *d, UCHAR *p, UCHAR *q )
void alibTransposes( wvlong n, wvlong b, wvlong e, wvlong *d, short *p, short *q )
void alibTransposei( wvlong n, wvlong b, wvlong e, wvlong *d, int *p, int *q )
void alibTransposel( wvlong n, wvlong b, wvlong e, wvlong *d, wvlong *p, wvlong *q )
void alibTransposef( wvlong n, wvlong b, wvlong e, wvlong *d, float *p, float *q )
void alibTransposed( wvlong n, wvlong b, wvlong e, wvlong *d, double *p, double *q )
void alibTransposec( wvlong n, wvlong b, wvlong e, wvlong *d, COMPLEX *p, COMPLEX *q )
void alibTransposez( wvlong n, wvlong b, wvlong e, wvlong *d, DCOMPLEX *p, DCOMPLEX *q )
Parameters
n — (Input) The number of dimensions in the array to be transposed.
b — (Input) The first of the dimensions to be transposed.
e — (Input) The second of the dimensions to be transposed.
*d — (Input) The n-element array of dimensions for the array to be transposed.
*p — (Input) The source array.
*q — (Input/Output) The destination array. On return, array q contains the result of transposing dimensions b and e in n-dimensional array p of dimensions d.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* dimension arrays to use for the examples */
   wvlong da[2]={3,4}, dc[3]={2,3,6}, de[3]={3,2,6}, dd[4]={2,2,3,4};
   /* input and output arrays to be used in all the examples */
   UCHAR    b0[48], b[48], b1[48];
   /* initialize the data */
   alibinit( NULL, NULL, NULL, NULL );
   alibIndexb( 48, 0, 1, b0 );
   printf( "\n\n print (3,4) matrix b0 and its transpose" );
      alibPrintArrayb( 1, 1, 3, 4, b0, NULL );
      alibTransposeb( 2, 0, 1, da, b0, b );
      alibPrintArrayb( 1, 1, 4, 3, b, NULL );
   printf( "\n\n show (2,3,6) array b0 and transpose its 0 & 1 dimensions" );
      alibPrintArrayb( 1, 2, 3, 6, b0, NULL );
      alibTransposeb( 3, 0, 1, dc, b0, b );
      alibPrintArrayb( 1, 3, 2, 6, b, NULL );
   printf( "\n\n show (2,3,6) array b0 and transpose its 0 & 2 dimensions" );
      alibPrintArrayb( 1, 2, 3, 6, b0, NULL );
      alibTransposeb( 3, 0, 2, dc, b0, b );
      alibPrintArrayb( 1, 6, 3, 2, b, NULL );
   printf( "\n\n show (2,3,6) array b0 and transpose its 1 & 2 dimensions" );
      alibPrintArrayb( 1, 2, 3, 6, b0, NULL );
      alibTransposeb( 3, 1, 2, dc, b0, b );
      alibPrintArrayb( 1, 2, 6, 3, b, NULL );
   printf( "\n\n show (2,3,6) array b0, then cyclically permute dimensions");
      alibPrintArrayb( 1, 2, 3, 6, b0, NULL );
      alibTransposeb( 3, 0, 1, dc, b0, b1 );
      alibTransposeb( 3, 1, 2, de, b1, b );
      alibPrintArrayb( 1, 3, 6, 2, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 0 & 1 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 0, 1, dd, b0, b );
      alibPrintArrayb( 2, 2, 3, 4, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 0 & 2 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 0, 2, dd, b0, b );
      alibPrintArrayb( 3, 2, 2, 4, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 0 & 3 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 0, 3, dd, b0, b );
      alibPrintArrayb( 4, 2, 3, 2, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 1 & 2 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 1, 2, dd, b0, b );
      alibPrintArrayb( 2, 3, 2, 4, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 1 & 3 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 1, 3, dd, b0, b );
      alibPrintArrayb( 2, 4, 3, 2, b, NULL );
   printf( "\n\n show (2,2,3,4) array b0 and transpose its 2 & 3 dims" );
      alibPrintArrayb( 2, 2, 3, 4, b0, NULL );
      alibTransposeb( 4, 2, 3, dd, b0, b );
      alibPrintArrayb( 2, 2, 4, 3, b, NULL );
}
 
Output:
 
 print (3,4) matrix b0 and its transpose
 
   0   1   2   3
   4   5   6   7
   8   9  10  11
 
   0   4   8
   1   5   9
   2   6  10
   3   7  11
 
 show (2,3,6) array b0 and transpose its 0 & 1 dimensions
 
   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
 
   0   1   2   3   4   5
  18  19  20  21  22  23
 
   6   7   8   9  10  11
  24  25  26  27  28  29
 
  12  13  14  15  16  17
  30  31  32  33  34  35
 
 show (2,3,6) array b0 and transpose its 0 & 2 dimensions
 
   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
 
   0  18
   6  24
  12  30
 
   1  19
   7  25
  13  31
 
   2  20
   8  26
  14  32
 
   3  21
   9  27
  15  33
 
   4  22
  10  28
  16  34
 
   5  23
  11  29
  17  35
 
 show (2,3,6) array b0 and transpose its 1 & 2 dimensions
 
   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
 
   0   6  12
   1   7  13
   2   8  14
   3   9  15
   4  10  16
   5  11  17
 
  18  24  30
  19  25  31
  20  26  32
  21  27  33
  22  28  34
  23  29  35
 
 show (2,3,6) array b0, then cyclically permute dimensions
 
   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
 
   0  18
   1  19
   2  20
   3  21
   4  22
   5  23
 
   6  24
   7  25
   8  26
   9  27
  10  28
  11  29
 
  12  30
  13  31
  14  32
  15  33
  16  34
  17  35
 
 show (2,2,3,4) array b0 and transpose its 0 & 1 dims
 
   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
 
   0   1   2   3
   4   5   6   7
   8   9  10  11
 
  24  25  26  27
  28  29  30  31
  32  33  34  35
 
  12  13  14  15
  16  17  18  19
  20  21  22  23
 
  36  37  38  39
  40  41  42  43
  44  45  46  47
 
 show (2,2,3,4) array b0 and transpose its 0 & 2 dims
 
   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
 
   0   1   2   3
  24  25  26  27
 
  12  13  14  15
  36  37  38  39
 
   4   5   6   7
  28  29  30  31
 
  16  17  18  19
  40  41  42  43
 
   8   9  10  11
  32  33  34  35
 
  20  21  22  23
  44  45  46  47
 
 show (2,2,3,4) array b0 and transpose its 0 & 3 dims
 
 
   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
 
   0  24
   4  28
   8  32
 
  12  36
  16  40
  20  44
 
   1  25
   5  29
   9  33
 
  13  37
  17  41
  21  45
 
   2  26
   6  30
  10  34
 
  14  38
  18  42
  22  46
 
   3  27
   7  31
  11  35
 
  15  39
  19  43
  23  47
 
 show (2,2,3,4) array b0 and transpose its 1 & 2 dims
 
   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
 
   0   1   2   3
  12  13  14  15
 
   4   5   6   7
  16  17  18  19
 
   8   9  10  11
  20  21  22  23
 
 
  24  25  26  27
  36  37  38  39
 
  28  29  30  31
  40  41  42  43
 
  32  33  34  35
  44  45  46  47
 
 show (2,2,3,4) array b0 and transpose its 1 & 3 dims
 
   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
 
   0  12
   4  16
   8  20
 
   1  13
   5  17
   9  21
 
   2  14
   6  18
  10  22
 
   3  15
   7  19
  11  23
 
  24  36
  28  40
  32  44
 
  25  37
  29  41
  33  45
 
  26  38
  30  42
  34  46
 
  27  39
  31  43
  35  47
 
 show (2,2,3,4) array b0 and transpose its 2 & 3 dims
 
   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
 
   0   4   8
   1   5   9
   2   6  10
   3   7  11
 
  12  16  20
  13  17  21
  14  18  22
  15  19  23
 
  24  28  32
  25  29  33
  26  30  34
  27  31  35
 
  36  40  44
  37  41  45
  38  42  46
  39  43  47

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.