Skip to content

Commit 51bc04a

Browse files
author
Joe Petviashvili
committed
add topk
1 parent bfb49d9 commit 51bc04a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/common.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export AF_NORM_MATRIX_1, AF_NORM_MATRIX_2, AF_NORM_MATRIX_INF, AF_NORM_MATRIX_L_
2323
export AF_NORM_VECTOR_INF, AF_NORM_VECTOR_P, AF_PAD_SYM, AF_PAD_ZERO, AF_RANDOM_ENGINE_DEFAULT, AF_RANDOM_ENGINE_MERSENNE
2424
export AF_RANDOM_ENGINE_MERSENNE_GP11213, AF_RANDOM_ENGINE_PHILOX, AF_RANDOM_ENGINE_PHILOX_4X32_10, AF_RANDOM_ENGINE_THREEFRY
2525
export AF_RANDOM_ENGINE_THREEFRY_2X32_16, AF_RGB, AF_SAD, AF_SHD, AF_SSD, AF_STORAGE_COO, AF_STORAGE_CSC
26-
export AF_STORAGE_CSR, AF_STORAGE_DENSE, AF_SUCCESS, AF_YCC_2020, AF_YCC_601, AF_YCC_709, AF_YCbCr, AF_ZNCC
27-
export AF_ZSAD, AF_ZSSD, afDevice, afHost, af_array, af_backend, af_binary_op, af_border_type, af_canny_threshold
28-
export af_colormap, af_connectivity, af_conv_domain, af_conv_mode, af_cspace_t, af_diffusion_eq, af_dtype
29-
export af_err, af_features, af_flux_function, af_homography_type, af_image_format, af_interp_type, af_marker_type
30-
export af_mat_prop, af_match_type, af_moment_type, af_norm_type, af_random_engine, af_random_engine_type
31-
export af_someenum_t, af_source, af_storage, af_window, af_ycc_std, b8, c32, c64, dim_t, f32, f64, intl
32-
export s16, s32, s64, u16, u32, u64, u8, uintl
26+
export AF_STORAGE_CSR, AF_STORAGE_DENSE, AF_SUCCESS, AF_TOPK_DEFAULT, AF_TOPK_MAX, AF_TOPK_MIN, AF_YCC_2020
27+
export AF_YCC_601, AF_YCC_709, AF_YCbCr, AF_ZNCC, AF_ZSAD, AF_ZSSD, afDevice, afHost, af_array, af_backend
28+
export af_binary_op, af_border_type, af_canny_threshold, af_colormap, af_connectivity, af_conv_domain
29+
export af_conv_mode, af_cspace_t, af_diffusion_eq, af_dtype, af_err, af_features, af_flux_function, af_homography_type
30+
export af_image_format, af_interp_type, af_marker_type, af_mat_prop, af_match_type, af_moment_type, af_norm_type
31+
export af_random_engine, af_random_engine_type, af_someenum_t, af_source, af_storage, af_topk_function
32+
export af_window, af_ycc_std, b8, c32, c64, dim_t, f32, f64, intl, s16, s32, s64, u16, u32, u64, u8, uintl
3333

3434
const dim_t = Clonglong
3535
const intl = Clonglong
@@ -295,6 +295,13 @@ const AF_DIFFUSION_MCDE = (UInt32)(2)
295295
const AF_DIFFUSION_DEFAULT = (UInt32)(0)
296296
# end enum af_diffusion_eq
297297

298+
# begin enum af_topk_function
299+
const af_topk_function = UInt32
300+
const AF_TOPK_MAX = (UInt32)(1)
301+
const AF_TOPK_MIN = (UInt32)(2)
302+
const AF_TOPK_DEFAULT = (UInt32)(0)
303+
# end enum af_topk_function
304+
298305
type af_seq
299306
_begin::Cdouble
300307
_end::Cdouble

src/wrap.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export set_device, set_intersect, set_manual_eval_flag, set_mem_step_size, set_p
3636
export set_title, set_union, set_unique, set_visibility, shift, show, sift, sigmoid, signbit, sin, sinh
3737
export skew, sobel_operator, solve, solve_lu, sort_by_key, sparse_convert_to, sparse_get_col_idx, sparse_get_info
3838
export sparse_get_nnz, sparse_get_row_idx, sparse_get_storage, sparse_get_values, sqrt, stdev_all, sub
39-
export sum, sum_all, sum_nan, sum_nan_all, susan, svd_inplace, sync, tan, tanh, tgamma, tile, transform
39+
export sum, sum_all, sum_nan, sum_nan_all, susan, svd_inplace, sync, tan, tanh, tgamma, tile, topk, transform
4040
export transform_coordinates, translate, transpose_inplace, trunc, unlock_array, unlock_device_ptr, unwrap
4141
export upper, var_all, var_all_weighted, wrap, write_array, ycbcr2rgb
4242

@@ -1850,6 +1850,13 @@ function corrcoef(X::AFArray,Y::AFArray)
18501850
(realVal[],imagVal[])
18511851
end
18521852

1853+
function topk(_in::AFArray,k::Integer,dim::Integer,order::af_topk_function)
1854+
values = RefValue{af_array}(0)
1855+
indices = RefValue{af_array}(0)
1856+
_error(ccall((:af_topk,af_lib),af_err,(Ptr{af_array},Ptr{af_array},af_array,Cint,Cint,af_topk_function),values,indices,_in.arr,Cint(k),Cint(dim - 1),order))
1857+
(AFArray!(values[]),AFArray!(indices[]))
1858+
end
1859+
18531860
function fast(_in::AFArray,thr::Cfloat,arc_length::Integer,non_max::Bool,feature_ratio::Cfloat,edge::Integer)
18541861
out = RefValue{af_features}(0)
18551862
_error(ccall((:af_fast,af_lib),af_err,(Ptr{af_features},af_array,Cfloat,UInt32,Bool,Cfloat,UInt32),out,_in.arr,thr,UInt32(arc_length),non_max,feature_ratio,UInt32(edge)))

0 commit comments

Comments
 (0)