Skip to content

Commit 7a638b7

Browse files
author
Joe Petviashvili
committed
sort by key
1 parent dcb8a12 commit 7a638b7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/util.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base: cumsum, cumprod, cummin, cummax, chol, abs2
33

44
export constant, get_last_error, err_to_string, sort_index, fir, iir
55
export mean_weighted, var_weighted, set_array_indexer, set_seq_param_indexer
6-
export afeval, iota
6+
export afeval, iota, sortbykey
77

88
const af_threshold = Ref(4*1024*1024*1024)
99
const af_gc_count = Ref(0)
@@ -479,3 +479,10 @@ function iota{T,N}(dims::NTuple{N,Int}, typ::Type{T} = Int32)
479479
out,UInt32(N),[dims...],UInt32(1),[1],af_type(T)))
480480
AFArray{T,N}(out[])+T(1)
481481
end
482+
483+
function sortbykey{T1,T2,N}(keys::AFArray{T1,N},values::AFArray{T2,N},dim::Integer,isAscending::Bool=true)
484+
out_keys = RefValue{af_array}(0)
485+
out_values = RefValue{af_array}(0)
486+
_error(ccall((:af_sort_by_key,af_lib),af_err,(Ptr{af_array},Ptr{af_array},af_array,af_array,UInt32,Bool),out_keys,out_values,keys.arr,values.arr,UInt32(dim - 1),isAscending))
487+
(AFArray{T1,N}(out_keys[]),AFArray{T2,N}(out_values[]))
488+
end

0 commit comments

Comments
 (0)