Struct Float16
This value type represents A Float16 value it is blittable as defined in https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types and as such, represented the same way in managed and native memories. This means that arrays of this type do not have to be copied to be passed to native memory but simply pinned and read by native code. Thus, one can create a Tensor on top of an array of these structures and feed it directly to Onnxruntime library. Binary wise, it is the same as ushort[] (uint16_t in C++). However, we would like a separate type for type dispatching.
The implementation is derived from https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Half.cs,7895d5942d33f974
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public readonly struct Float16
Constructors
| Improve this Doc View SourceFloat16(UInt16)
Ctor from ushort bits, no conversion is done
Declaration
public Float16(ushort v)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | v |
Fields
| Improve this Doc View Sourcevalue
float16 representation bits
Declaration
public readonly ushort value
Field Value
Type | Description |
---|---|
System.UInt16 |
Properties
| Improve this Doc View SourceEpsilon
Float16 Epsilon value
Declaration
public static readonly Float16 Epsilon { get; }
Property Value
Type | Description |
---|---|
Float16 |
MaxValue
Float16 Max value
Declaration
public static readonly Float16 MaxValue { get; }
Property Value
Type | Description |
---|---|
Float16 |
MinValue
Float16 Min value
Declaration
public static readonly Float16 MinValue { get; }
Property Value
Type | Description |
---|---|
Float16 |
NaN
Float16 NaN
Declaration
public static readonly Float16 NaN { get; }
Property Value
Type | Description |
---|---|
Float16 |
NegativeInfinity
Float16 Negative Infinity value
Declaration
public static readonly Float16 NegativeInfinity { get; }
Property Value
Type | Description |
---|---|
Float16 |
NegativeZero
Float16 Negative Zero value
Declaration
public static readonly Float16 NegativeZero { get; }
Property Value
Type | Description |
---|---|
Float16 |
One
Float16 One value
Declaration
public static readonly Float16 One { get; }
Property Value
Type | Description |
---|---|
Float16 |
Pi
Float16 Pi value
Declaration
public static readonly Float16 Pi { get; }
Property Value
Type | Description |
---|---|
Float16 |
PositiveInfinity
Float16 Positive Infinity value
Declaration
public static readonly Float16 PositiveInfinity { get; }
Property Value
Type | Description |
---|---|
Float16 |
Zero
Float16 Zero value
Declaration
public static readonly Float16 Zero { get; }
Property Value
Type | Description |
---|---|
Float16 |
Methods
| Improve this Doc View SourceCompareTo(Float16)
Compares this object to another object, returning an integer that indicates the relationship.
Declaration
public readonly int CompareTo(Float16 other)
Parameters
Type | Name | Description |
---|---|---|
Float16 | other | Object to compare to |
Returns
Type | Description |
---|---|
System.Int32 | A value less than zero if this is less than |
CompareTo(Object)
Compares this object to another object, returning an integer that indicates the relationship.
Declaration
public readonly int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | Object to compare to |
Returns
Type | Description |
---|---|
System.Int32 | A value less than zero if this is less than |
Equals(Float16)
Returns a value indicating whether this instance and other Float16 represent the same value.
Declaration
public readonly bool Equals(Float16 other)
Parameters
Type | Name | Description |
---|---|---|
Float16 | other | A Float16 object to compare to this instance. |
Returns
Type | Description |
---|---|
System.Boolean | true if other.value is equal to this instance; otherwise, false. |
Equals(Object)
Returns a value indicating whether this instance and a specified System.Object represent the same type and value.
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | An System.Object. |
Returns
Type | Description |
---|---|
System.Boolean | true if obj is Float16 and its value is equal to this instance; otherwise, false. |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer hash code. |
IsFinite(Float16)
Determines whether the specified value is finite (zero, subnormal, or normal).
Declaration
public static bool IsFinite(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance. |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is finite |
IsInfinity(Float16)
Determines whether the specified value is infinite.
Declaration
public static bool IsInfinity(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance. |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is infinite |
IsNaN(Float16)
Determines whether the specified value is NaN.
Declaration
public static bool IsNaN(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is not a number |
IsNaNOrZero(Float16)
The function returns true if the value is either NaN or zero.
Declaration
public static bool IsNaNOrZero(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | instance of Float16 |
Returns
Type | Description |
---|---|
System.Boolean | true if NaN or zero. |
IsNegative(Float16)
This value type represents A Float16 value it is blittable as defined in https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types and as such, represented the same way in managed and native memories. This means that arrays of this type do not have to be copied to be passed to native memory but simply pinned and read by native code. Thus, one can create a Tensor on top of an array of these structures and feed it directly to Onnxruntime library. Binary wise, it is the same as ushort[] (uint16_t in C++). However, we would like a separate type for type dispatching.
The implementation is derived from https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Half.cs,7895d5942d33f974
Declaration
public static bool IsNegative(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value |
Returns
Type | Description |
---|---|
System.Boolean |
IsNegativeInfinity(Float16)
Determines whether the specified value is negative infinity.
Declaration
public static bool IsNegativeInfinity(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is negative infinity |
IsNormal(Float16)
Determines whether the specified value is normal
Declaration
public static bool IsNormal(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value |
Returns
Type | Description |
---|---|
System.Boolean | true or false |
IsPositiveInfinity(Float16)
Determines whether the specified value is positive infinity.
Declaration
public static bool IsPositiveInfinity(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance |
Returns
Type | Description |
---|---|
System.Boolean |
IsSubnormal(Float16)
Determines whether the specified value is subnormal.
Declaration
public static bool IsSubnormal(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | Float16 instance |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is subnormal |
Negate(Float16)
Flips the sign. NaNs are not affected. IEEE 754 specifies NaNs to be propagated
Declaration
public static Float16 Negate(Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value |
Returns
Type | Description |
---|---|
Float16 |
ToFloat()
Explicit conversion
Declaration
public readonly float ToFloat()
Returns
Type | Description |
---|---|
System.Single | single precision value converted from Float16 |
ToString()
Returns a string representation of the current value.
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
System.String | Text representation of Float16 |
Operators
| Improve this Doc View SourceEquality(Float16, Float16)
Compares values of two Float16 for binary equality. If either of the values is NaN, this will return false.
Declaration
public static bool operator ==(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | left hand side |
Float16 | right | right hand side |
Returns
Type | Description |
---|---|
System.Boolean | true if values are equal according to IEEE |
Explicit(Float16 to Single)
Explicitly converts a half-precision floating-point value to its nearest representable
Declaration
public static explicit operator float (Float16 value)
Parameters
Type | Name | Description |
---|---|---|
Float16 | value | The value to convert. |
Returns
Type | Description |
---|---|
System.Single |
|
Explicit(Single to Float16)
Explicitly converts a
Declaration
public static explicit operator Float16(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value to convert. |
Returns
Type | Description |
---|---|
Float16 |
|
GreaterThan(Float16, Float16)
Compares values of two Float16
Declaration
public static bool operator>(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | left hand side |
Float16 | right | right hand side |
Returns
Type | Description |
---|---|
System.Boolean | returns true if left is greater than right according to IEEE |
GreaterThanOrEqual(Float16, Float16)
Compares values of two Float16
Declaration
public static bool operator >=(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | left hand side |
Float16 | right | right hand side |
Returns
Type | Description |
---|---|
System.Boolean | returns true if left is greater or equal than right according to IEEE |
Inequality(Float16, Float16)
Compares values of two Float16 for binary inequality
Declaration
public static bool operator !=(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | |
Float16 | right |
Returns
Type | Description |
---|---|
System.Boolean | true if values are not equal according to IEEE |
LessThan(Float16, Float16)
Compares values of two Float16
Declaration
public static bool operator <(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | left hand side |
Float16 | right | right hand side |
Returns
Type | Description |
---|---|
System.Boolean | returns true if left is less than right according to IEEE |
LessThanOrEqual(Float16, Float16)
Compares values of two Float16
Declaration
public static bool operator <=(Float16 left, Float16 right)
Parameters
Type | Name | Description |
---|---|---|
Float16 | left | left hand side |
Float16 | right | right hand side |
Returns
Type | Description |
---|---|
System.Boolean | returns true if left is less or equal than right according to IEEE |