NSArray(TIOData)

@interface NSArray (TIOData)

An array of numbers, also typed as a TIOVector, is able to provide bytes to or capture bytes from a tensor.

  • Initializes an NSArray object with bytes from a tensor.

    Bytes are copied according to the following rules, with information about quantization taken from the description:

    • If the layer is unquantized, the tensor’s bytes are copied directly into numeric values and added to the resulting array (the bytes are implicitly interpreted as float_t values)

    • If the layer is quantized and no dequantizer block is provided, the tensor’s bytes are copied directly into numeric values and added to the resulting array (the bytes are implicitly interpreted as uint8_t values)

    • If the layer is quantized and a dequantizer block is provided, the tensor’s bytes are interpreted as uint8_t values, passed to the dequantizer block, and the resulting float_t bytes are copied into numeric values and added to the resulting array

    Declaration

    Objective-C

    - (nullable instancetype)initWithBytes:(nonnull const void *)bytes
                                    length:(NSUInteger)length
                               description:
                                   (nonnull id<TIOLayerDescription>)description;

    Swift

    convenience init?(bytes: UnsafeRawPointer, length: UInt, description: TIOLayerDescription)

    Parameters

    bytes

    The output buffer to read from.

    length

    The length of the buffer.

    description

    A description of the data this buffer produces.

    Return Value

    instancetype An instance of NSData.

  • Request to fill a tensor with bytes.

    Bytes are copied according to the following rules, with information about quantization taken from the description:

    • If the layer is unquantized, the bytes of the array’s numeric entries are copied directly to the buffer (and implicitly interpreted as float_t values)

    • If the layer is quantized and no quantizer block is provided, the bytes of the array’s numeric entries are copied directly to the buffer (and implicitly interpreted as uint8_t values)

    • If the layer is quantized and a quantizer block is provided, the the bytes of the array’s numeric entries are interpreted as float_t values, passed to the quantizer block, and the uint8_t values returned from it are copied to the buffer

    Declaration

    Objective-C

    - (void)getBytes:(nonnull void *)buffer
              length:(NSUInteger)length
         description:(nonnull id<TIOLayerDescription>)description;

    Swift

    func getBytes(_ buffer: UnsafeMutableRawPointer, length: UInt, description: TIOLayerDescription)

    Parameters

    buffer

    The input buffer to copy bytes to.

    length

    The length of the input buffer.

    description

    A description of the data this buffer expects.