# NAG CL Interfacem01zac (permute_​invert)

Settings help

CL Name Style:

## 1Purpose

m01zac inverts a permutation, and hence converts a rank vector to an index vector, or vice versa.

## 2Specification

 #include
 void m01zac (size_t ranks[], size_t n, NagError *fail)
The function may be called by the names: m01zac, nag_sort_permute_invert or nag_make_indices.

## 3Description

There are two common ways of describing a permutation using an Integer vector ranks. The first uses ranks: ${\mathbf{ranks}}\left[i\right]$ holds the index value to which the $\left(i+1\right)$th data element should be moved in order to sort the data; in other words its rank in the sorted order. The second uses indices: ${\mathbf{ranks}}\left[i\right]$ holds the current index value of the data element which would occur in $\left(i+1\right)$th position in sorted order. For example, given the values
 $3.5 5.9 2.9 0.5$
to be sorted in ascending order, the ranks would be
 $2 3 1 0$
and the indices would be
 $3 2 0 1 .$
The m01d- functions generate ranks, and the m01e- functions require indices to be supplied to specify the re-ordering. However if it is desired simply to refer to the data in sorted order without actually re-ordering them, indices are more convenient than ranks (see Section 10). m01zac can be used to convert ranks to indices, or indices to ranks, as the two permutations are inverses of one another.

None.

## 5Arguments

1: $\mathbf{ranks}\left[{\mathbf{n}}\right]$size_t Input/Output
On entry: ranks must contain a permutation of the Integers 0 to ${\mathbf{n}}-1$.
On exit: ranks contains the inverse permutation.
2: $\mathbf{n}$size_t Input
On entry: the length of the array ranks.
Constraint: $0\le {\mathbf{n}}\le \mathrm{MAX_LENGTH}$, where $\mathrm{MAX_LENGTH}$ is an implementation-dependent value for the maximum size of an array.
3: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

Invalid ranks vector.
Elements of ranks contain a value outside the range 0 to ${\mathbf{n}}-1$ or contain a repeated value. ranks does not contain a permutation of the Integers 0 to ${\mathbf{n}}-1$; on exit these elements are usually corrupted.
NE_INT_ARG_GT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\le ⟨\mathit{\text{value}}⟩$, an implementation-dependent size that is printed in the error message.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.

Not applicable.

## 8Parallelism and Performance

m01zac is not threaded in any implementation.

None.

## 10Example

The example program reads a matrix of real numbers and prints its rows with the elements of the 1st column in ascending order as ranked by m01dsc. The program first calls m01dsc to rank the rows, and then calls m01zac to convert the rank vector to an index vector, which is used to refer to the rows in sorted order.

### 10.1Program Text

Program Text (m01zace.c)

### 10.2Program Data

Program Data (m01zace.d)

### 10.3Program Results

Program Results (m01zace.r)