ORTValue

Objective-C

@interface ORTValue : NSObject

Swift

class ORTValue : NSObject

An ORT value encapsulates data used as an input or output to a model at runtime.

  • Unavailable

    Declaration

    Objective-C

    - (instancetype)init NS_UNAVAILABLE;
  • Creates a value that is a tensor. The tensor data is allocated by the caller.

    Declaration

    Objective-C

    - (nullable instancetype)
        initWithTensorData:(nonnull NSMutableData *)tensorData
               elementType:(ORTTensorElementDataType)elementType
                     shape:(nonnull NSArray<NSNumber *> *)shape
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    init(tensorData: NSMutableData, elementType: ORTTensorElementDataType, shape: [NSNumber]) throws

    Parameters

    tensorData

    The tensor data.

    elementType

    The tensor element data type.

    shape

    The tensor shape.

    error

    Optional error information set if an error occurs.

    Return Value

    The instance, or nil if an error occurs.

  • Creates a value that is a string tensor. The string data will be copied into a buffer owned by this ORTValue instance.

    Available since 1.16.

    Declaration

    Objective-C

    - (nullable instancetype)
        initWithTensorStringData:(nonnull NSArray<NSString *> *)tensorStringData
                           shape:(nonnull NSArray<NSNumber *> *)shape
                           error:(NSError *_Nullable *_Nullable)error;

    Swift

    init(tensorStringData: [String], shape: [NSNumber]) throws

    Parameters

    tensorStringData

    The tensor string data.

    shape

    The tensor shape.

    error

    Optional error information set if an error occurs.

    Return Value

    The instance, or nil if an error occurs.

  • Gets the type information.

    Declaration

    Objective-C

    - (nullable ORTValueTypeInfo *)typeInfoWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func typeInfo() throws -> ORTValueTypeInfo

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    The type information, or nil if an error occurs.

  • Gets the tensor type and shape information. This assumes that the value is a tensor.

    Declaration

    Objective-C

    - (nullable ORTTensorTypeAndShapeInfo *)tensorTypeAndShapeInfoWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func tensorTypeAndShapeInfo() throws -> ORTTensorTypeAndShapeInfo

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    The tensor type and shape information, or nil if an error occurs.

  • Gets the tensor data. This assumes that the value is a tensor.

    This returns the value’s underlying data directly, not a copy of it. The memory’s lifetime may be tied to this value, i.e., if it was allocated by ORT. On the other hand, the memory’s lifetime is independent of the value if the value was created with user-provided data.

    Declaration

    Objective-C

    - (nullable NSMutableData *)tensorDataWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func tensorData() throws -> NSMutableData

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    The tensor data, or nil if an error occurs.

  • Gets the tensor string data. This assumes that the value is a string tensor.

    This returns a copy of the value’s underlying string data.

    Available since 1.16.

    Declaration

    Objective-C

    - (nullable NSArray<NSString *> *)tensorStringDataWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func tensorStringData() throws -> [String]

    Parameters

    error

    Optional error information set if an error occurs.

    Return Value

    The copy of the tensor string data, or nil if an error occurs.