The routine may be called by the names m01zcf or nagf_sort_permute_decompose.
m01zcf is provided as an aid to reordering arbitrary data structures without using additional storage. However, you should consider carefully whether it is necessary to rearrange yourr data, or whether it would be simpler and more efficient to refer to the data in sorted order using an index vector, or to create a copy of the data in sorted order.
To rearrange data into a different order without using additional storage, the simplest method is to decompose the permutation which specifies the new order into cycles and then to do a cyclic permutation of the data items in each cycle. (This is the method used by the reordering routines m01eaf,m01ebf,m01ecfandm01edf.) Given a vector IRANK which specifies the ranks of the data (as generated by the routines m01daf,m01dbf,m01dcf,m01def,m01dff,m01djf,m01dkfandm01dzf), m01zcf generates a new vector icycl, in which the permutation is represented in its component cycles, with the first element of each cycle negated. For example, the permutation
In order to rearrange the data according to the specified ranks:
item must be left in place;
items and must be interchanged;
items , , and must be moved right one place round the cycle.
The complete rearrangement can be achieved by the following
do k = m1, m2
i = icycl(k)
if (i < 0) then
j = -i
[swap items i and j]
1: – Integer arrayInput/Output
On entry: elements
of iperm must contain a permutation of the integers m1 to m2.
On exit: is used as internal workpsace prior to being restored and hence is unchanged.
2: – IntegerInput
3: – IntegerInput
On entry: m1 and m2 must specify the range of elements used in the array iperm and the range of values in the permutation, as specified under iperm.
4: – Integer arrayOutput
On exit: elements
of icycl contain a representation of the permutation as a list of cycles, with the first integer in each cycle negated. (See Section 3.)
5: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
On entry, and .
On entry, .
does not contain a permutation of the integers m1 to m2. contains an out-of-range value: , .
does not contain a permutation of the integers m1 to m2. iperm contains a repeated value: .
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
m01zcf is not threaded in any implementation.
This example reads a matrix of real numbers and rearranges its columns so that the elements of the th row are in ascending order. To do this, the program first calls m01djf to rank the elements of the th row, and then calls m01zcf to decompose the rank vector into cycles. It then rearranges the columns using the framework of code suggested in Section 3. The value of is read from the data file.