DataSeries/sort - Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : DataSeries/sort

DataSeries/sort

sort a DataSeries

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

sort( DS )

sort( DS, ordering, options )

Parameters

DS

-

a DataSeries object

ordering

-

(optional) symbol or Boolean function of two arguments; sort ordering

options

-

(optional) equation(s) of the form option=value

Options

• 

nonstrict: specifies to use a nonstrict comparison function type

• 

strict: specifies to use a strict comparison function type

• 

key: specifies to use a key comparison function type

• 

output: sorted or permutation; specify whether to return the sorted DataSeries or the permutation of rows that sorts the DataSeries accordingly

Description

• 

The sort command sorts a DataSeries.

• 

If the ordering option is given, it specifies the ordering for sorting elements. By default, elements are sorted in ascending order for numeric values and lexicographic order for strings and names.

– 

`<`:  If ordering is the symbol `<` or numeric, then the DataSeries is sorted in ascending numerical order. The DataSeries must contain elements of type({numeric, real_infinity}),

– 

`>`:  If ordering is the symbol `>`, then the DataSeries is sorted into descending numerical order.

– 

address:  If ordering is the symbol address, then the elements are sorted by address (a non-deterministic run-time specific property of the underlying data structure).

– 

length:  If ordering is the symbol length, then the elements are sorted by length where length is as determined by the length function.

– 

lexorder:  If ordering is the symbol lexorder or string, then lists of strings or symbols are sorted into lexicographic order.

– 

Otherwise, ordering must be a Boolean-valued function, F, of two arguments.  Specifically, Fa&comma;b returns false if and only if b must precede a in the sorted output.  That is Fa&comma;b is a non-strict less than comparison function.  In addition, Fa&comma;b must be defined for all pairs a,b for a and b in the input structure and Fa&comma;b must be transitive, that is, if Fa&comma;b=true and Fb&comma;c=true then Fa&comma;c=true.

• 

By specifying comptype=Function, different styles of comparison functions can be given to sort.  The supported values for comptype are:

– 

nonstrict: the comparison Function is a non-strict less than function, as described above.

– 

strict: the comparison Function is a strict less than function.  That is Fa&comma;b returns true if and only if a must precede b in the sorted output.  Function must still be defined for all pairs of inputs and be transitive, as described above.  This argument is necessary if you want to specify a less than or equal to comparison function and want stable sorting.  Specifying a strict less than function without using the strict option will result in an non-stable, sorted output.

– 

key: the Function maps each element in the DataSeries to a key value.  The DataSeries is sorted by sorting the corresponding keys.  Using a key function is preferable to a comparison function because the key function is called On times, whereas a comparison function will be called Onlogn times.  This is generally faster.  In addition, sorting the keys may be done in parallel, whereas this may not be possible with a comparison function.

• 

If an argument output = sorted is supplied, sort returns the sorted argument. This is the default behavior.

  

If an argument output = permutation is supplied, then sort does not return the sorted argument, but the permutation that would be applied to the argument in order to sort it. The permutation is given as a list of integers: the ith entry of the permutation is the integer j such that the jth entry of the DataSeries would occur at the ith position in the sorted argument. This means that if a=sortDataSeries&comma;output=permutation then sortDataSeries could be obtained as DataSeriesa.

  

In order to obtain both the sorted argument and the permutation, one can supply the argument output = [sorted, permutation]. This will return a sequence of two elements, the first being the sorted argument, the second the permutation.

Examples

Consider a DataSeries:

DSDataSeries1&comma;3&comma;2&comma;labels&equals;a&comma;c&comma;b

DSa1c3b2

(1)

By default, the values are sorted in ascending order:

sortDS

a1b2c3

(2)

It is also possible to sort in descending order:

sortDS&comma;`>`

c3b2a1

(3)

It is also possible to sort a DataSeries containing strings or names in alphabetic (lexicographic) order:

sortDataSeriesa&comma;c&comma;b

1a3b2c

(4)

The output option controls the returned output for the sort command. Using permutation returns the list of numeric indices that sort the original DataSeries.

index_ordersortDataSeriesa&comma;c&comma;b&comma;output&equals;permutation

index_order1&comma;3&comma;2

(5)

DataSeriesa&comma;c&comma;bindex_order

1a3b2c

(6)

Several other sort options are also supported by the DataSeries sort command:

sortDataSeries1&comma;3&comma;2&comma;key&equals;abs

113−223

(7)

Compatibility

• 

The DataSeries/sort command was introduced in Maple 2017.

• 

For more information on Maple 2017 changes, see Updates in Maple 2017.

See Also

DataFrame/sort

sort