Chapter 15: Utilities

permute_matrix

Permutes the rows or columns of a matrix.

Synopsis

#include <imsls.h>

float *imsls_f_permute_matrix (int n_rows, int n_columns, float a[], int permutation[], Imsls_permute permute, ..., 0)

The type double function is imsls_d_permute_matrix.

Required Arguments

int n_rows   (Input)
Number of rows in the input matrix a.

int n_columns   (Input)
Number of columns in the input matrix a.

float a[]   (Input)
Matrix of size n_rows × n_columns to be permuted.

int permutation[]   (Input)
Array of length n containing the permutation permutation[0],, permutation[n-1] of the integers  0, …, n, where n = n_rows if the rows of a are to be permuted and n=n_columns if the columns of a are to be permuted.

Imsls_permute permute   (Input)
Keyword of type Imsls_permute. Argument permute must be either IMSLS_PERMUTE_ROWS, if the rows of a are to be interchanged, or IMSLS_PERMUTE_COLUMNS, if the columns of a are to be interchanged.

Return Value

Array of size n_rows × n_columns containing the permuted input matrix a.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_permute_matrix (int n_rows, int n_columns, float a[],
int permutation[], Imsls_permute permute,
IMSLS_RETURN_USER, float permuted_result[],
0)

Optional Arguments

IMSLS_RETURN_USER, float permuted_result[]   (Output)
User-allocated array of size n_rows × n_columns containing the result of the permutation.

Description

Function imsls_f_permute_matrix interchanges the rows or columns of a matrix using a permutation vector. The function permutes a column (row) at a time using function imsls_f_permute_vector. This process is continued until all the columns (rows) are permuted. On completion, let B = result and pi = permutation [i], then Bij = Apij for all i, j.

Example

This example permutes the columns of a matrix a.

#include <imsls.h>

 

int main()

{

    float 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};

    int permutation[] = {2, 3, 0, 4, 1};

    float     *output;

    int        n_rows = 3;

    int        n_columns = 5;

 

    output = imsls_f_permute_matrix (n_rows, n_columns, a, permutation,

        IMSLS_PERMUTE_COLUMNS,

        0);

 

    imsls_f_write_matrix ("permuted matrix", n_rows, n_columns, output,

        IMSLS_ROW_NUMBER_ZERO,

        IMSLS_COL_NUMBER_ZERO,

        0);

}

Output

                       permuted matrix

            0           1           2           3           4

0           1           2           3           4           5

1           1           2           3           4           5

2           1           2           3           4           5


Visual Numerics, Inc.
Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260