CNL Stat : Utilities : permute_vector
permute_vector
Rearranges the elements of a vector as specified by a permutation.
Synopsis
#include <imsls.h>
float *imsls_f_permute_vector (int n_elements, float x[], int permutation[], Imsls_permute permute, ., 0)
The type double function is imsls_d_permute_vector.
Required Arguments
int n_elements (Input)
Number of elements in the input vector x.
float x[] (Input)
Array of length n_elements to be permuted.
int permutation[] (Input)
Array of length n_elements containing the permutation.
Imsls_permute permute (Input)
Keyword of type Imsls_permute. Argument permute must be either IMSLS_FORWARD_PERMUTATION or IMSLS_BACKWARD_PERMUTATION. If IMSLS_FORWARD_PERMUTATION is specified, then a forward permutation is performed, i.e., x[permutation[i]] is moved to location i in the return vector. If IMSLS_BACKWARD_PERMUTATION is specified, then a backward permutation is performed, i.e., x[i] is moved to location permutation[i] in the return vector.
Return Value
An array of length n_elements containing the input vector x permuted.
Synopsis with Optional Arguments
#include <imsls.h>
float *imsls_f_permute_vector (int n_elements, float x[], int permutation[], Imsls_permute permute,
IMSLS_RETURN_USER, float permuted_result[],
0)
Optional Arguments
IMSLS_RETURN_USER, float permuted_result[](Output)
User-allocated array containing the result of the permutation.
Description
Function imsls_f_permute_vector rearranges the elements of a vector according to a permutation vector. The function can perform both forward and backward permutation.
Example
This example rearranges the vector x using permutation. A forward permutation is performed.
 
#include <imsls.h>
 
int main()
{
float x[] = {5.0, 6.0, 1.0, 4.0};
int permutation[] = {2, 0, 3, 1};
float *output;
int n_elements = 4;
 
output = imsls_f_permute_vector (n_elements, x, permutation,
IMSLS_FORWARD_PERMUTATION, 0);
 
imsls_f_write_matrix ("permuted result", 1, n_elements, output,
IMSLS_COL_NUMBER_ZERO, 0);
}
Output
 
permuted result
0 1 2 3
1 5 4 6