Contents

MLShapedArray

A machine learning collection type that stores scalar values in a multidimensional array.

Declaration

struct MLShapedArray<Scalar> where Scalar : MLShapedArrayScalar

Overview

A shaped array is a multidimensional array type that’s the Swift counterpart to MLMultiArray. MLShapedArray is one of the underlying types of MLFeatureValue that stores scalar values. You can convert a shaped array to an MLMultiArray with its init(_:) initializer, and convert back to a shaped array with its init(_:) initializer. All elements in an MLShapedArray are of the same type, and that type must conform to MLShapedArrayScalar:

Each dimension in a shaped array is typically significant or meaningful. For example, a model could have an input that accepts images as a three-dimensional array of pixels, C x H x W. The first dimension, C,_ _represents the number of color channels, and the second and third dimensions, H and W, represent the image’s height and width, respectively. The number of dimensions and size of each dimension define the shaped array’s shape.

A shaped array’s shape property is an integer array in which each element defines the size of the corresponding dimension. To inspect the shape and constraints of a model’s multiarray input or output feature:

  1. Access the model’s modelDescription property.

  2. Find the multiarray input or output feature in the model description’s inputDescriptionsByName or outputDescriptionsByName property, respectively.

  3. Access the feature description’s multiArrayConstraint property.

  4. Inspect the multiarray constraint’s shape and shapeConstraint.

Topics

Creating a shaped array

Creating a shaped array from another type

Creating a shaped array with pointers to memory

Creating a shaped array from data

Shaping the array

Reading and writing the pixel buffer

Modifying a shaped array

Encoding and decoding

Default Implementations

See Also

Supporting types