FNLMath : Utilities : PERMA
PERMA
Permutes the rows or columns of a matrix.
Required Arguments
ANRA by NCA matrix to be permuted. (Input)
IPERMU — Vector of length K containing a permutation IPERMU(1),, IPERMU(K) of the integers 1,, K where K = NRA if the rows of A are to be permuted and K = NCA if the columns of A are to be permuted. (Input)
APERNRA by NCA matrix containing the permuted matrix. (Output)
If A is not needed, A and APER can share the same storage locations.
Optional Arguments
NRA — Number of rows. (Input)
Default: NRA = size (A,1).
NCA — Number of columns. (Input)
Default: NCA = size (A,2).
LDA — Leading dimension of A exactly as specified in the dimension statement of the calling program. (Input)
Default: LDA = size (A,1).
IPATH — Option parameter. (Input)
IPATH = 1 means the rows of A will be permuted. IPATH = 2 means the columns of A will be permuted.
Default: IPATH = 1.
LDAPER — Leading dimension of APER exactly as specified in the dimension statement of the calling program. (Input)
Default: LDAPER = size (APER,1).
FORTRAN 90 Interface
Generic: CALL PERMA (A, IPERMU, APER [])
Specific: The specific interface names are S_PERMA and D_PERMA.
FORTRAN 77 Interface
Single: CALL PERMA (NRA, NCA, A, LDA, IPERMU, IPATH, APER, LDAPER)
Double: The double precision name is DPERMA.
Description
Routine PERMA interchanges the rows or columns of a matrix using a permutation vector such as the one obtained from routines SVRBP or SVRGP.
The routine PERMA permutes a column (row) at a time by calling PERMU. This process is continued until all the columns (rows) are permuted. On completion, let B = APER and pi = IPERMU(I), then
for all i, j.
Comments
1. Workspace may be explicitly provided, if desired, by use of P2RMA/DP2RMA. The reference is:
CALL P2RMA (NRA, NCA, A, LDA, IPERMU, IPATH, APER, LDAPER, WORK)
The additional argument is:
WORK — Real work vector of length NCA.
Example
This example permutes the columns of a matrix A.
 
USE PERMA_INT
USE UMACH_INT
 
IMPLICIT NONE
! Declare variables
INTEGER IPATH, LDA, LDAPER, NCA, NRA
PARAMETER (IPATH=2, LDA=3, LDAPER=3, NCA=5, NRA=3)
!
INTEGER I, IPERMU(5), J, NOUT
! Set values for A, IPERMU
! A = ( 3.0 5.0 1.0 2.0 4.0 )
! ( 3.0 5.0 1.0 2.0 4.0 )
! ( 3.0 5.0 1.0 2.0 4.0 )
!
! IPERMU = ( 3 4 1 5 2 )
!
DATA A/3*3.0, 3*5.0, 3*1.0, 3*2.0, 3*4.0/, IPERMU/3, 4, 1, 5, 2/
! Perform column permutation on A,
! giving APER
CALL PERMA (A, IPERMU, APER, IPATH=IPATH)
! Get output unit number
CALL UMACH (2, NOUT)
! Print results
WRITE (NOUT,99999) ((APER(I,J),J=1,NCA),I=1,NRA)
!
99999 FORMAT (' The output matrix is:', /, 3(5F8.1,/))
END
Output
 
The Output matrix is:
1.0 2.0 3.0 4.0 5.0
1.0 2.0 3.0 4.0 5.0
1.0 2.0 3.0 4.0 5.0