gpucoder.sort
Optimized GPU implementation of the MATLAB sort function
Syntax
Description
sorts the elements of an array B
= gpucoder.sort(A
)A
, and the generated CUDA® code from gpucoder.sort
performs the sort
operation on the GPU. The function sorts A
along the first
non-singleton dimension. For example:
If
A
is a vector,gpucoder.sort(A)
sorts the elements ofA
,If
A
is a matrix,gpucoder.sort(A)
sorts the elements of each column ofA
.
The sorted output in B
has the same type and size
as A
.
has the optional argument B
= gpucoder.sort(A
,dim
)dim
that specifies the dimension along
which the sort operation is performed.
has the optional argument B
= gpucoder.sort(A
,direction
)direction
that specifies the sort
direction. direction
can take one of two values:
'ascend'
- Sorts in the ascending order. This is the default option.'descend'
- Sorts in the descending order.
[
returns a sort index B
,I
] = gpucoder.sort(A
,...)I
which specifies how the elements of
A
were rearranged to obtain the sorted output
B
.
If
A
is a vector, thenB = A(I)
.If
A
is an m-by-n matrix anddim = 1
, thenfor j = 1:n B(:,j) = A(I(:,j),j); end
The sort ordering is stable. Namely, when more than one element has the same value, the order of the equal elements is preserved in the sorted output B and the indices I relating to equal elements are ascending.
When gpucoder.sort
is called from MATLAB®, it uses the built-in sort
function.
Examples
Input Arguments
Output Arguments
Limitations
gpucoder.sort
does not support complex numbers.gpucoder.sort
does not support'MissingPlacement'
and'ComparisonMethod'
name-value pairs supported by the MATLABsort
function.
Version History
Introduced in R2018bSee Also
Apps
Functions
codegen
|coder.gpu.kernel
|coder.gpu.kernelfun
|stencilfun
|coder.gpu.constantMemory
|gpucoder.reduce