ONNX Runtime
Loading...
Searching...
No Matches
Ort::Float16_t Struct Reference

IEEE 754 half-precision floating point data type. More...

#include <onnxruntime_cxx_api.h>

Inheritance diagram for Ort::Float16_t:

Public Types

using Base = onnxruntime_float16::Float16Impl< Float16_t >
 

Public Member Functions

 Float16_t ()=default
 Default constructor.
 
 Float16_t (float v) noexcept
 __ctor from float. Float is converted into float16 16-bit representation.
 
float ToFloat () const noexcept
 Converts float16 to float.
 
 operator float () const noexcept
 User defined conversion operator. Converts Float16_t to float.
 

Static Public Member Functions

static constexpr Float16_t FromBits (uint16_t v) noexcept
 Explicit conversion to uint16_t representation of float16.
 

Detailed Description

IEEE 754 half-precision floating point data type.

This struct is used for converting float to float16 and back so the user could feed inputs and fetch outputs using these type.

The size of the structure should align with uint16_t and one can freely cast uint16_t buffers to/from Ort::Float16_t to feed and retrieve data.

// This example demonstrates converion from float to float16
constexpr float values[] = {1.f, 2.f, 3.f, 4.f, 5.f};
std::vector<Ort::Float16_t> fp16_values;
fp16_values.reserve(std::size(values));
std::transform(std::begin(values), std::end(values), std::back_inserter(fp16_values),
[](float value) { return Ort::Float16_t(value); });

Member Typedef Documentation

◆ Base

using Ort::Float16_t::Base = onnxruntime_float16::Float16Impl<Float16_t>

Constructor & Destructor Documentation

◆ Float16_t() [1/2]

Ort::Float16_t::Float16_t ( )
default

Default constructor.

◆ Float16_t() [2/2]

Ort::Float16_t::Float16_t ( float  v)
inlineexplicitnoexcept

__ctor from float. Float is converted into float16 16-bit representation.

Parameters
vfloat value

Member Function Documentation

◆ FromBits()

static constexpr Float16_t Ort::Float16_t::FromBits ( uint16_t  v)
inlinestaticconstexprnoexcept

Explicit conversion to uint16_t representation of float16.

Parameters
vuint16_t bit representation of float16
Returns
new instance of Float16_t

◆ operator float()

Ort::Float16_t::operator float ( ) const
inlineexplicitnoexcept

User defined conversion operator. Converts Float16_t to float.

◆ ToFloat()

float Ort::Float16_t::ToFloat ( ) const
inlinenoexcept

Converts float16 to float.

Returns
float representation of float16 value