---@meta onnxruntime

--------------------------------------------------------------------------------
-- ONNX Runtime module
--------------------------------------------------------------------------------

---@alias onnxruntime_tensor_type
---| '"float32"'
---| '"float"'
---| '"float16"'
---| '"bfloat16"'
---| '"uint8"'
---| '"uint16"'
---| '"int8"'
---| '"int16"'
---| '"int32"'
---| '"uint32"'
---| '"int64"'
---| '"uint64"'
---| '"double"'
---| '"float64"'
---| '"bool"'
---| '"string"'

---@alias onnxruntime_shape integer[]
---@alias onnxruntime_tensor_data number|boolean|string|number[]|boolean[]|string[]|table
---@alias onnxruntime_value_like onnxruntime_tensor*|onnxruntime_value*|onnxruntime_sequence*|onnxruntime_map*|onnxruntime_sparse_tensor*
---@alias onnxruntime_tensor_or_scalar onnxruntime_tensor*|number|boolean
---@alias onnxruntime_named_values table<string|integer, onnxruntime_value_like>

---@class onnxruntime_config*
---@field log_severity_level? integer Log level
---@field log_id? string Log ID
---@field use_global_thread_pools? boolean Whether to use the global thread pool
---@field global_intra_op_num_threads? integer intra-op Number of threads
---@field global_inter_op_num_threads? integer inter-op Number of threads

---@class onnxruntime_session_options*
---@field intra_op_num_threads? integer intra-op Number of threads
---@field inter_op_num_threads? integer inter-op Number of threads
---@field execution_mode? integer|string execution mode
---@field graph_optimization_level? integer|string graph optimization level
---@field optimized_model_filepath? string Optimize model output path
---@field enable_profiling? boolean Whether to enable profiling
---@field profiling_prefix? string profiling prefix
---@field log_id? string Log ID
---@field log_severity_level? integer Log level
---@field log_verbosity_level? integer Log verbosity level
---@field use_coreml? boolean Whether to enable CoreML EP
---@field coreml_flags? integer CoreML EP flags
---@field use_cpu? boolean Whether to enable CPU EP
---@field custom_op_libraries? onnxruntime_custom_op_library*[] Custom operator library

---@class onnxruntime_run_options*
---@field tag? string run tag
---@field log_severity_level? integer Log level
---@field log_verbosity_level? integer Log verbosity level

---@class onnxruntime_image_tensor_options*
---@field width? integer Output width
---@field height? integer Output high
---@field add_batch? boolean Whether to add batch dimension
---@field layout? '"nchw"'|'"nhwc"'|'"chw"'|'"hwc"' tensor layout
---@field channel_order? '"rgb"'|'"bgr"'|'"gray"'|'"grey"'|'"grayscale"' Channel order
---@field scale? number Pixel scaling
---@field data_type? onnxruntime_tensor_type tensor type
---@field resize_mode? '"stretch"'|'"letterbox"'|'"center_crop"' Zoom mode
---@field letterbox_mode? '"center"'|'"top_left"'|'"topleft"' letterbox Alignment
---@field pad_color? integer fill color
---@field interpolation? '"nearest"'|'"bilinear"' interpolation method
---@field alpha_mode? '"ignore"'|'"white"'|'"black"'|'"premultiply"' alpha Processing method
---@field crop? { x: integer, y: integer, width: integer, height: integer } crop area
---@field mean? number|number[] mean
---@field std? number|number[] standard deviation

---@class onnxruntime_image_tensor_meta*
---@field src_width integer Original image width
---@field src_height integer Original image height
---@field crop_x integer Crop X
---@field crop_y integer Crop Y
---@field crop_width integer Crop width
---@field crop_height integer Cut high
---@field dst_width integer target width
---@field dst_height integer Aim high
---@field resized_width integer Width after scaling
---@field resized_height integer height after scaling
---@field layout string Layout
---@field channel_order string Channel order
---@field resize_mode string Zoom mode
---@field scale_x number X Zoom
---@field scale_y number Y Zoom
---@field ratio number Zoom ratio
---@field offset_x integer X offset
---@field offset_y integer Y offset
---@field pad_left integer left padding
---@field pad_top integer top padding
---@field pad_right integer right padding
---@field pad_bottom integer bottom padding

---@class onnxruntime_image_from_tensor_options*
---@field layout? '"nchw"'|'"nhwc"'|'"chw"'|'"hwc"' tensor layout
---@field channel_order? '"rgb"'|'"bgr"'|'"gray"' Channel order
---@field batch_index? integer batch Index, starting from 1
---@field scale? number Output scaling
---@field mean? number|number[] mean
---@field std? number|number[] standard deviation
---@field clamp? boolean Whether to crop to 0..255
---@field range01? boolean Whether to denormalize according to the range of 0..1

---@class onnxruntime_type_info*
---@field name? string Name
---@field onnx_type string ONNX Type
---@field is_sparse? boolean Is it sparse?
---@field data_type? string Tensor element type
---@field type? string Type description
---@field has_shape? boolean Is there a shape
---@field shape? integer[] shape
---@field symbolic_shape? table symbolic shape
---@field element? onnxruntime_type_info Sequence element type
---@field key_type? string map key Type
---@field value? onnxruntime_type_info map value Type

---@class onnxruntime_memory_info*
---@field name string allocator Name
---@field id integer device id
---@field mem_type integer memory type
---@field allocator_type integer allocator type
---@field device_type? integer device type
---@field device_mem_type? integer device memory type
---@field vendor_id? integer vendor id

---@class onnxruntime_metadata*
---@field producer_name? string producer
---@field graph_name? string graph
---@field domain? string domain
---@field description? string description
---@field graph_description? string graph description
---@field version integer version
---@field custom_metadata table<string, string> Custom metadata

---@class onnxruntime_nms_options*
---@field score_threshold? number score threshold
---@field iou_threshold? number IoU threshold
---@field max_detections? integer Maximum reserved quantity
---@field class_agnostic? boolean Whether to ignore categories

---@class onnxruntime_box_record*
---@field box number[] box
---@field score number score
---@field class_id integer Category
---@field row_index? integer original row index
---@field x1? number
---@field y1? number
---@field x2? number
---@field y2? number
---@field width? number
---@field height? number
---@field cx? number
---@field cy? number

---@class onnxruntime_obb_record*
---@field cx number Center X
---@field cy number Center Y
---@field w number wide
---@field h number high
---@field theta number angle
---@field score number score
---@field class_id integer Category
---@field row_index? integer original row index

---@class onnxruntime_keypoint*
---@field x number X
---@field y number Y
---@field score? number score
---@field raw? number[] original value

---@class onnxruntime_track*
---@field id integer track id
---@field box number[] box
---@field score number score
---@field class_id? integer Category
---@field age integer age
---@field hits integer Number of hits
---@field first_seen integer first occurrence of frame
---@field last_seen integer Recent frames

---@class onnxruntime_mask_bitmap*
---@field width integer wide
---@field height integer high
---@field bits string bitmap data
---@field pixel_count integer Number of pixels
---@field bounds? table border

---@class onnxruntime_ctc_result*
---@field text? string text
---@field indices integer[] token Index
---@field confidence? number Confidence
---@field probabilities? number[][] Probability
---@field probability_confidence? number probability confidence

---@class onnxruntime_tensor*
local tensor = {}

--- Get the tensor shape.
---@return integer[] shape
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:shape() end

--- Get tensor rank.
---@return integer rank
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:rank() end

--- Get the number of elements.
---@return integer size
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:size() end

--- Get the element type.
---@return onnxruntime_tensor_type type
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:type() end

--- Convert to Lua table.
---@return table data
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to_table() end

--- Returns the underlying byte string, which is not supported by string tensor.
---@return string bytes
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:bytes() end

--- Convert to image.cv mat.
---@param opts? table Options
---@return image_cv_mat* mat
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to_cv_mat(opts) end

--- To read elements, the index starts from 1 according to Lua convention.
---@param ... integer Index
---@return any value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:get(...) end

--- Write elements, the last parameter is the value.
---@param ... any index and value
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:set(...) end

--- Fill tensor.
---@param value onnxruntime_tensor_data Scalar or element list
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:fill(value) end

--- Change shape.
---@param shape integer[] new shape
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:reshape(shape) end

--- Transpose dimensions.
---@param axes? integer[] Dimension order
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:transpose(axes) end

--- Flatten the dimension interval.
---@param start_dim? integer starting dimension
---@param end_dim? integer end dimension
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:flatten(start_dim, end_dim) end

--- Remove dimensions with size 1.
---@param dim? integer Specify dimensions
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:squeeze(dim) end

--- Insert a dimension with size 1.
---@param dim integer insertion position
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:unsqueeze(dim) end

--- Clone the tensor.
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:clone() end

--- Convert element type.
---@param type onnxruntime_tensor_type target type
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:to(type) end

--- slice.
---@param dim integer Dimensions
---@param start integer Starting point, starting from 1
---@param stop integer end point, including
---@param step? integer step length
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:slice(dim, start, stop, step) end

--- Select an index on a dimension and delete the dimension.
---@param dim integer Dimensions
---@param index integer Index, starting from 1
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:select(dim, index) end

--- Collect by index.
---@param dim integer Dimensions
---@param indices integer[]|onnxruntime_tensor* Index, starting from 1
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:gather(dim, indices) end

---@param rhs onnxruntime_tensor_or_scalar rvalue
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:add(rhs) end

---@param rhs onnxruntime_tensor_or_scalar rvalue
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sub(rhs) end

---@param rhs onnxruntime_tensor_or_scalar rvalue
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:mul(rhs) end

---@param rhs onnxruntime_tensor_or_scalar rvalue
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:div(rhs) end

---@param min_value number minimum value
---@param max_value number maximum value
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:clamp(min_value, max_value) end

---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sigmoid() end

---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:exp() end

---@param rhs onnxruntime_tensor* right matrix
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:matmul(rhs) end

---@param axis? integer Dimension; when omitted, returns the global maximum index
---@return onnxruntime_tensor*|integer result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:argmax(axis) end

---@param axis? integer Dimensions
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sum(axis) end

---@param axis? integer Dimensions
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:mean(axis) end

---@param axis? integer Dimensions
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:max(axis) end

---@param axis? integer Dimensions
---@return onnxruntime_tensor*|number result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:min(axis) end

---@param axis? integer Dimensions
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:softmax(axis) end

---@param opts? table Options
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:normalize(opts) end

---@param axis? integer Dimensions
---@param descending? boolean Is descending order
---@return onnxruntime_tensor* values
---@return onnxruntime_tensor* indices
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:sort(axis, descending) end

---@param rhs onnxruntime_tensor* rvalue
---@return number dot dot product
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:dot(rhs) end

---@param k integer k
---@param axis? integer Dimensions
---@return onnxruntime_tensor* values
---@return onnxruntime_tensor* indices
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:topk(k, axis) end

---@param bytes string raw bytes
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tensor:copy_from_bytes(bytes) end

---@class onnxruntime_value*
local value = {}

---@return string type Type description
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function value:type() end

---@return boolean ok Is it valuable?
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function value:has_value() end

---@return any value value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function value:get() end

---@class onnxruntime_sequence*: onnxruntime_value*
local sequence = {}

---@return string type Type description
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sequence:type() end

---@return boolean ok Is it valuable?
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sequence:has_value() end

---@param index integer Index, starting from 1
---@return onnxruntime_value_like value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sequence:get(index) end

---@return integer length length
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sequence:length() end

---@return onnxruntime_value_like[] items array of elements
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sequence:items() end

---@class onnxruntime_map*: onnxruntime_value*
local map = {}

---@return string type Type description
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:type() end

---@return boolean ok Is it valuable?
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:has_value() end

---@param key any key
---@return any value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:get(key) end

---@param key any key
---@param value any value
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:set(key, value) end

---@return any[] keys
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:keys() end

---@return table pairs
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function map:pairs() end

---@class onnxruntime_sparse_tensor*: onnxruntime_value*
local sparse_tensor = {}

---@return string type Type description
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:type() end

---@return boolean ok Is it valuable?
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:has_value() end

---@return any value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:get() end

---@return integer[] shape dense shape
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:dense_shape() end

---@return onnxruntime_tensor* values Sparse values
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:values() end

---@return onnxruntime_tensor* indices Index
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:indices() end

---@return string format sparse format
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:format() end

---@return onnxruntime_tensor* tensor dense tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function sparse_tensor:to_dense() end

---@class onnxruntime_session*
local session = {}

---@param inputs onnxruntime_named_values input
---@param outputs? string[]|table Output name; returns all output when omitted
---@param run_options? onnxruntime_run_options_object* Run options
---@return onnxruntime_named_values outputs output
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run(inputs, outputs, run_options) end

---@param inputs onnxruntime_named_values input
---@param outputs table<string|integer, onnxruntime_tensor*> Output multiplexing table
---@param run_options? onnxruntime_run_options_object* Run options
---@return onnxruntime_named_values outputs output
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run_into(inputs, outputs, run_options) end

---@param binding onnxruntime_io_binding* IO binding
---@param run_options? onnxruntime_run_options_object* Run options
---@return onnxruntime_io_binding* binding
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:run_with_iobinding(binding, run_options) end

---@return onnxruntime_io_binding* binding
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:create_io_binding() end

---@return string[] names
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_names() end

---@return string[] names
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_names() end

---@return string[] names
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_names() end

---@return integer count
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_count() end

---@return integer count
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_count() end

---@return integer count
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_count() end

---@param name_or_index string|integer name or index
---@return onnxruntime_type_info* info
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:input_info(name_or_index) end

---@param name_or_index string|integer name or index
---@return onnxruntime_type_info* info
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:output_info(name_or_index) end

---@param name_or_index string|integer name or index
---@return onnxruntime_type_info* info
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:overridable_initializer_info(name_or_index) end

---@return table<string|integer, onnxruntime_memory_info*> infos
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:memory_info_for_inputs() end

---@return table<string|integer, onnxruntime_memory_info*> infos
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:memory_info_for_outputs() end

---@return onnxruntime_metadata* metadata
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:metadata() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:close() end

---@return string? path profiling file path
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:end_profiling() end

---@return number time_ns profiling start time
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:profiling_start_time_ns() end

---@param options table<string, any> EP Dynamic options
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:set_ep_dynamic_options(options) end

---@param library onnxruntime_custom_op_library* Custom operator library
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function session:register_custom_op_library(library) end

---@class onnxruntime_io_binding*
local io_binding = {}

---@param name string Enter name
---@param value onnxruntime_value_like Enter value
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:bind_input(name, value) end

---@param name string output name
---@param value_or_spec? onnxruntime_tensor*|{ mode?: '"device"', type?: onnxruntime_tensor_type, shape?: integer[] } Output tensor or specification
---@return boolean|onnxruntime_tensor* result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:bind_output(name, value_or_spec) end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:clear_inputs() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:clear_outputs() end

---@return onnxruntime_named_values outputs
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:get_outputs() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:synchronize_inputs() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function io_binding:synchronize_outputs() end

---@class onnxruntime_run_options_object*
local run_options_object = {}

---@param tag? string new tag
---@return string? tag current tag
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:tag(tag) end

---@param level? integer new log level
---@return integer level Current log level
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:log_severity_level(level) end

---@param level? integer New log verbosity level
---@return integer level Current log detail level
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:log_verbosity_level(level) end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:terminate() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function run_options_object:reset_terminate() end

---@class onnxruntime_custom_op_library*
local custom_op_library = {}

---@class onnxruntime_decoder*
local decoder = {}

---@param outputs table<string, any>|onnxruntime_named_values Model output
---@param opts? table Options
---@return any result Decoding result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:decode(outputs, opts) end

---@return string task Task name
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:task() end

---@return table schema schema
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function decoder:schema() end

---@class onnxruntime_tracker*
local tracker = {}

---@param detections table[] Test results
---@param opts? table Options
---@return onnxruntime_track[] tracks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:update(detections, opts) end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:reset() end

---@return onnxruntime_track[] tracks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:state() end

---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function tracker:close() end

---@class onnxruntime*
---@type onnxruntime*
local M = {}

--- Get the ONNX Runtime version.
---@return string version
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.version() end

--- Get available execution providers.
---@return string[] providers
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.providers() end

--- Configure the global runtime, which needs to be called before creating a session.
---@param opts onnxruntime_config* Configuration
---@return boolean ok
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.configure(opts) end

--- Create a tensor.
---@param type onnxruntime_tensor_type element type
---@param shape integer[] shape
---@param data? onnxruntime_tensor_data initial data or scalar
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor(type, shape, data) end

--- Create a numeric tensor from bytes.
---@param type onnxruntime_tensor_type element type
---@param shape integer[] shape
---@param bytes string raw bytes
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_bytes(type, shape, bytes) end

--- Create tensor from image.cv mat.
---@param mat image_cv_mat* mat
---@param type? onnxruntime_tensor_type element type
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_cv_mat(mat, type) end

--- Create a tensor from the image quadrilateral area.
---@param image ImageObject* pictures
---@param quad table quadrilateral
---@param opts? onnxruntime_image_tensor_options* Options
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta* meta
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_quad(image, quad, opts) end

--- Create batch tensors from multiple image quad regions.
---@param image ImageObject* pictures
---@param quads table[] quadrilateral array
---@param opts? onnxruntime_image_tensor_options* Options
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta[] metas
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_quads(image, quads, opts) end

--- Create a tensor from an image.
---@param image ImageObject* pictures
---@param opts? onnxruntime_image_tensor_options* Options
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta* meta
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_image(image, opts) end

--- Create a batch tensor from an array of images.
---@param images ImageObject*[] Picture array
---@param opts? onnxruntime_image_tensor_options* Options
---@return onnxruntime_tensor* tensor
---@return onnxruntime_image_tensor_meta[] metas
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tensor_from_images(images, opts) end

--- Create a picture from an image tensor.
---@param tensor onnxruntime_tensor* Tensor
---@param opts? onnxruntime_image_from_tensor_options* Options
---@return ImageObject* image
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.image_from_tensor(tensor, opts) end

---@param tensor onnxruntime_tensor* input
---@param min_value number minimum value
---@param max_value number maximum value
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clamp(tensor, min_value, max_value) end

---@param tensor onnxruntime_tensor* input
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.sigmoid(tensor) end

---@param tensor onnxruntime_tensor* input
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.exp(tensor) end

---@param condition onnxruntime_tensor* Conditions
---@param then_value onnxruntime_tensor_or_scalar true value
---@param else_value onnxruntime_tensor_or_scalar false value
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.where(condition, then_value, else_value) end

---@param lhs onnxruntime_tensor* left matrix
---@param rhs onnxruntime_tensor* right matrix
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.matmul(lhs, rhs) end

---@param tensors onnxruntime_tensor*[] tensor array
---@param axis integer Splicing dimensions
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.concat(tensors, axis) end

---@param tensors onnxruntime_tensor*[] tensor array
---@param axis integer new dimension
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.stack(tensors, axis) end

--- Non-maximum suppression.
---@param boxes onnxruntime_tensor*|number[][] boxes
---@param scores onnxruntime_tensor*|number[] scores
---@param opts? onnxruntime_nms_options* Options
---@return integer[] keep_indices keep index
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.nms(boxes, scores, opts) end

---@param box onnxruntime_tensor*|number[] spin box
---@return table points vertex
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.box_points(box) end

---@param boxes onnxruntime_tensor* boxes
---@return onnxruntime_tensor* boxes
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.xywh_to_xyxy(boxes) end

---@param boxes onnxruntime_tensor* boxes
---@return onnxruntime_tensor* boxes
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.xyxy_to_xywh(boxes) end

---@param boxes1 onnxruntime_tensor* boxes1
---@param boxes2 onnxruntime_tensor* boxes2
---@return onnxruntime_tensor* iou
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.rotated_iou(boxes1, boxes2) end

---@param boxes onnxruntime_tensor* boxes
---@param scores onnxruntime_tensor* scores
---@param opts? table Options
---@return integer[] keep_indices
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.rotated_nms(boxes, scores, opts) end

---@param schema table|string decoder schema
---@return onnxruntime_decoder* decoder
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.create_decoder(schema) end

---@param outputs table<string, any>|onnxruntime_named_values Model output
---@param opts? table Options
---@return table records
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_yolo(outputs, opts) end

---@param outputs table<string, any>|onnxruntime_named_values Model output
---@param opts? table Options
---@return table records
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_yolo_obb(outputs, opts) end

---@param tensor onnxruntime_tensor* candidate matrix tensor
---@param schema table|string decoder schema
---@param opts? table Options
---@return table candidates
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_matrix_candidates(tensor, schema, opts) end

---@param boxes onnxruntime_tensor* boxes
---@param scores onnxruntime_tensor* scores
---@param class_ids onnxruntime_tensor* class ids
---@param keep_indices? onnxruntime_tensor* keep indices
---@return onnxruntime_box_record[] records
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.records_from_boxes(boxes, scores, class_ids, keep_indices) end

---@param rows onnxruntime_tensor* rows
---@param opts? table Options
---@return onnxruntime_obb_record[] records
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.obb_records_from_rows(rows, opts) end

---@param points onnxruntime_tensor* points
---@param opts? table Options
---@return onnxruntime_keypoint[] records
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.points_to_records(points, opts) end

---@param outputs table<string, any>|onnxruntime_named_values Model output
---@param opts? table Options
---@return table detections
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.decode_dense_detection(outputs, opts) end

---@param pred onnxruntime_tensor* DB Model prediction tensor
---@param opts? table Options
---@return table result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.db_postprocess(pred, opts) end

---@param masks onnxruntime_tensor* masks
---@param threshold? number threshold
---@return onnxruntime_mask_bitmap[] masks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.threshold_masks(masks, threshold) end

---@param masks onnxruntime_tensor* masks
---@param boxes onnxruntime_tensor* boxes
---@param opts? table Options
---@return onnxruntime_tensor* masks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.crop_masks_by_boxes(masks, boxes, opts) end

---@param masks onnxruntime_tensor* masks
---@param width integer target width
---@param height integer Aim high
---@param opts? table Options
---@return onnxruntime_tensor* masks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.resize_masks(masks, width, height, opts) end

---@param masks1 onnxruntime_mask_bitmap* masks1
---@param masks2 onnxruntime_mask_bitmap* masks2
---@param opts? table Options
---@return number iou
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.mask_iou(masks1, masks2, opts) end

---@param mask onnxruntime_tensor*|onnxruntime_mask_bitmap* mask
---@param opts? table Options
---@return table polygon
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.mask_to_polygon(mask, opts) end

---@param prototypes onnxruntime_tensor* prototypes
---@param coefficients onnxruntime_tensor* coefficients
---@param boxes onnxruntime_tensor* boxes
---@param width integer Image width
---@param height integer Image height
---@param opts? table Options
---@return onnxruntime_mask_bitmap[] masks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.proto_masks(prototypes, coefficients, boxes, width, height, opts) end

---@param prototypes onnxruntime_tensor* prototypes
---@param coefficients onnxruntime_tensor* coefficients
---@param boxes onnxruntime_tensor* boxes
---@param width integer Image width
---@param height integer Image height
---@param opts? table Options
---@return onnxruntime_mask_bitmap[] masks
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.project_masks(prototypes, coefficients, boxes, width, height, opts) end

---@param opts? table Options
---@return onnxruntime_tracker* tracker
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.tracker(opts) end

---@param tensor onnxruntime_tensor* input
---@param opts? table Options
---@return onnxruntime_tensor* tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.reshape_keypoints(tensor, opts) end

---@param boxes onnxruntime_tensor* boxes
---@param transform onnxruntime_image_tensor_meta*|table transform
---@return onnxruntime_tensor* boxes
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_boxes(boxes, transform) end

---@param boxes onnxruntime_tensor* boxes
---@param width number wide
---@param height number high
---@return onnxruntime_tensor* boxes
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clip_boxes(boxes, width, height) end

---@param points onnxruntime_tensor* points
---@param transform onnxruntime_image_tensor_meta*|table transform
---@param opts? table Options
---@return onnxruntime_tensor* points
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_points(points, transform, opts) end

---@param keypoints onnxruntime_tensor* keypoints
---@param transform onnxruntime_image_tensor_meta*|table transform
---@param opts? table Options
---@return onnxruntime_tensor* keypoints
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.scale_keypoints(keypoints, transform, opts) end

---@param keypoints onnxruntime_tensor* keypoints
---@param width number wide
---@param height number high
---@param opts? table Options
---@return onnxruntime_tensor* keypoints
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.clip_keypoints(keypoints, width, height, opts) end

---@param logits onnxruntime_tensor* logits
---@param alphabet string[]|table character table
---@param opts? table Options
---@return onnxruntime_ctc_result|onnxruntime_ctc_result[] result
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.ctc_greedy_decode(logits, alphabet, opts) end

---@param logits onnxruntime_tensor* logits
---@param opts? table Options
---@return integer token_index
---@return number probability
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.tensor_module)
---
function M.sample_logits(logits, opts) end

---@param value any Lua value
---@param type_decl? string explicit type declaration
---@return onnxruntime_value_like value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.value(value, type_decl) end

---@param type_decl string optional internal type declaration
---@param value? any value
---@return onnxruntime_value* value
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.optional(type_decl, value) end

---@param values any[] sequence elements
---@param type_decl? string Element type declaration
---@return onnxruntime_sequence* sequence
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.sequence(values, type_decl) end

---@param key_type string key Type
---@param value_type string value Type
---@param values table initial value
---@return onnxruntime_map* map
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.map(key_type, value_type, values) end

---@param type onnxruntime_tensor_type element type
---@param dense_shape integer[] dense shape
---@param indices integer[]|integer[][] COO indices
---@param values number[] values
---@return onnxruntime_sparse_tensor* sparse_tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.sparse_tensor(type, dense_shape, indices, values) end

---@param tensor onnxruntime_tensor* dense tensor
---@return onnxruntime_sparse_tensor* sparse_tensor
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime)
---
function M.sparse_tensor_from_dense(tensor) end

---@param model_path string model path
---@param opts? onnxruntime_session_options* Options
---@return onnxruntime_session* session
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.session(model_path, opts) end

---@param model_bytes string model bytes
---@param opts? onnxruntime_session_options* Options
---@return onnxruntime_session* session
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.session_from_bytes(model_bytes, opts) end

---@param opts? onnxruntime_run_options* Options
---@return onnxruntime_run_options_object* options
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.run_options(opts) end

---@param path string Dynamic library path
---@return onnxruntime_custom_op_library* library
---
---[Documentation](https://xxtouch.app/en/docs/handbook/onnxruntime/onnxruntime.session_module)
---
function M.load_custom_op_library(path) end

return M
