MLArrayFeature

class NatML.Features.MLArrayFeature<T> : MLFeature, IMLEdgeFeature, IMLCloudFeature

This is a multidimensional array feature, a.k.a a tensor. Most models which accept tensors will accept an array feature in NatML.

circle-info

The array data type T is always unmanagedarrow-up-right.

circle-check

Creating the Feature

The array feature can be created from any numeric array or buffer representation:

From a Managed Array

/// <summary>
/// Create an array feature.
/// </summary>
/// <param name="data">Feature data.</param>
/// <param name="shape">Feature shape.</param>
MLArrayFeature (T[] data, int[] shape = null);

An array feature can be created from a managed array. In rare cases where it is useful to fully specify the feature type, there is an overload which accepts the array type:

/// <summary>
/// Create an array feature.
/// </summary>
/// <param name="data">Feature data.</param>
/// <param name="type">Feature type.</param>
MLArrayFeature (T[] data, MLArrayType type);

From a Native Array

The array feature provides variants of the managed array constructors where the data argument is a NativeArray<T>arrow-up-right. This can be useful for working with certain performance-critical Unity API's like Burst:

Similarly, in cases where it is necessary to explicitly specify the array feature type, there is a corresponding overload:

From a Native Buffer

The array feature provides variants of the managed array constructors where the data argument is a typed native buffer. These can be useful for making predictions on arrays from native code or external libraries like OpenCV:

There is a corresponding constructor for specifying the feature type:

circle-exclamation

From an Edge Feature

An array feature can be created from an MLEdgeFeature. This is useful for making predictions with an MLEdgeModel .

circle-exclamation

From a Cloud Feature

The array feature can be created from an MLCloudFeature. This is useful for making predictions with an MLCloudModel .

circle-exclamation

Inspecting the Feature

The array feature provides information about its shape.

Feature Type

Refer to the Inspecting the Feature section of the MLFeature class for more information.

circle-info

The type is always an MLArrayType.

Feature Shape

The feature shape is a convenience property which provides the shape from the feature type.

circle-exclamation

Element Count

The element count is a convenience property which provides the element count from the feature type.

circle-exclamation

Accessing Feature Data

The array feature provides accessors for reading and writing feature data.

Multi-Indexing

The array feature provides support for multi-indexing. This is a common pattern for working with tensors in machine learning:

circle-info

Multiple indexing requires the array feature to have a valid shape, but linear indexing (i.e. indexing with a single number) does not.

circle-exclamation

The array feature also supports linear indexing, in which case it accesses the elements of the feature assuming a flat shape:

Copying

The array feature can copy it data into another array feature.

circle-info

This method copies destination.elementCount * sizeof(U) bytes into the destination feature.

circle-exclamation
circle-check

Converting to Array

The array feature can copy its data into an array and return the array. The destination array type can also be specified:

circle-exclamation

Pinning

The array feature supports pinning, allowing direct access to the underlying feature data while bypassing all checks. This can be used in unsafe context with the fixed statement:

circle-check
triangle-exclamation

Viewing Operations

The array feature supports viewing operations. Each of these operations do not allocate any memory; they simply return a shallow feature that has the proper shape.

Permute

The array feature's dimensions can be permuted, allowing different dimensions to be swapped (like transposing):

View

The array feature supports creating a view of the feature data with a different shape:

circle-exclamation

Creating an Edge Feature

INCOMPLETE.

Creating a Cloud Feature

INCOMPLETE.

Last updated