Class

MLMultiArray

A multidimensional array used as a feature input or feature output for a model.

Overview

Multidimensional arrays are commonly used to represent input and output data. Often, each dimension of a multidimensional array has an associated label or meaning. For example, Core ML neural network models use a C x H x W layout for images, where C is the number of channels, H is the height of the image, and W is the width.

When an MLMultiArray instance of a specific shape and data type is expected as input for a Core ML model, the specifications are defined in an MLMultiArrayConstraint instance associated with the feature's MLFeatureDescription.

All features with type MLFeatureType.multiArray must be provided as an MLMultiArray instance.

Topics

Creating a Multidimensional Array

init(shape: [NSNumber], dataType: MLMultiArrayDataType)

Creates a multidimensional array of the given dimensions.

enum MLMultiArrayDataType

The different types the array can hold.

Accessing Values

subscript([NSNumber]) -> NSNumber

Subscript access, with an array of indexes, for the multidimensional array.

subscript(Int) -> NSNumber

Single, linear subscript access for the multidimensional array.

Inspecting the Multidimensional Array

var count: Int

The total number of elements in the multidimensional array.

var dataType: MLMultiArrayDataType

The type of value held in the array.

var shape: [NSNumber]

The array containing the sizes of each dimension of the multidimensional array.

var strides: [NSNumber]

An array containing the number of data elements to step in each dimension, when traversing the array.

var dataPointer: UnsafeMutableRawPointer

Pointer to the underlying buffer holding the elements of the array.

Relationships

Inherits From

Conforms To

See Also

Accessing the Value

var isUndefined: Bool

A Boolean value indicating whether the feature value is undefined.

var int64Value: Int64

The integer wrapped in this feature value.

var doubleValue: Double

The double wrapped in this feature value.

var stringValue: String

The string wrapped in this feature value.

var dictionaryValue: [AnyHashable : NSNumber]

The dictionary wrapped in this feature value.

var imageBufferValue: CVPixelBuffer?

The image, or pixelBuffer, wrapped in this feature value.

var multiArrayValue: MLMultiArray?

The multidimensional array wrapped in this feature value.

var sequenceValue: MLSequence?

The sequence wrapped in this feature value.

class MLSequence

A sequence of data used as a feature input or feature output for a model.