<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSNDArrayDescriptor",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@SA@BNNSNDArrayDescriptor"
  },
  "title" : "BNNSNDArrayDescriptor"
}
-->

# BNNSNDArrayDescriptor

A structure that describes the shape, stride, data type, and, optionally, the memory location of an n-dimensional array.

```
struct BNNSNDArrayDescriptor
```

## Overview

You use a [`BNNSNDArrayDescriptor`](/documentation/Accelerate/BNNSNDArrayDescriptor) structure as the primary mechanism to pass the description of data to and from BNNS functions. The description may include a pointer to the memory location.

For example, use the following code when you’re passing immutable weights to a convolution layer:

```swift
let weights: [Float] = [ ... ]

weights.withUnsafeBufferPointer { weightsPtr in
    
    let weightsDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                  layout: BNNSDataLayoutConvolutionWeightsOIHW,
                                                  size: (3, 3, 1, 1, 0, 0, 0, 0),
                                                  stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                  data: UnsafeMutableRawPointer(mutating: weightsPtr.baseAddress!),
                                                  data_type: .float,
                                                  table_data: nil,
                                                  table_data_type: .float,
                                                  data_scale: 1,
                                                  data_bias: 0)

    // Create and apply convolution layer.

}
```

Setting a stride value of `0` indicates that BNNS calculates stride, without padding, for that axis. For example, the stride for both of the following n-dimensional array descriptors is the same:

```swift
let inputDescriptor = BNNSNDArrayDescriptor(flags: flags,
                                           layout: BNNSDataLayoutRowMajorMatrix,
                                           size: (3, 3, 0, 0, 0, 0, 0, 0),
                                           stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                           data: nil,
                                           data_type: .float,
                                           table_data: nil,
                                           table_data_type: .float,
                                           data_scale: 1,
                                           data_bias: 0)

let inputDescriptor = BNNSNDArrayDescriptor(flags: flags,
                                           layout: BNNSDataLayoutRowMajorMatrix,
                                           size: (3, 3, 0, 0, 0, 0, 0, 0),
                                           stride: (1, 3, 0, 0, 0, 0, 0, 0),
                                           data: nil,
                                           data_type: .float,
                                           table_data: nil,
                                           table_data_type: .float,
                                           data_scale: 1,
                                           data_bias: 0)
```

You don’t need to specify the data when, for example, you’re passing that data directly to [`BNNSFilterApplyBatch(_:_:_:_:_:_:)`](/documentation/Accelerate/BNNSFilterApplyBatch(_:_:_:_:_:_:)). The following code creates [`BNNSNDArrayDescriptor`](/documentation/Accelerate/BNNSNDArrayDescriptor) structures for the input and output of a convolution operation. The data property of both descriptors is nil, and the input and output data are passed directly to [`BNNSFilterApplyBatch(_:_:_:_:_:_:)`](/documentation/Accelerate/BNNSFilterApplyBatch(_:_:_:_:_:_:)):

```swift
let input: [Float] = [ ... ]
var output: [Float] = [ ... ]

let inDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                         layout: BNNSDataLayoutImageCHW,
                                         size: (6, 6, 1, 0, 0, 0, 0, 0),
                                         stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                         data: nil,
                                         data_type: .float,
                                         table_data: nil,
                                         table_data_type: .float,
                                         data_scale: 1,
                                         data_bias: 0)

let outDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                          layout: BNNSDataLayoutImageCHW,
                                          size: (4, 4, 1, 0, 0, 0, 0, 0),
                                          stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                          data: nil,
                                          data_type: .float,
                                          table_data: nil,
                                          table_data_type: .float,
                                          data_scale: 1,
                                          data_bias: 0)

var parameters = BNNSLayerParametersConvolution(i_desc: inDescriptor,
                                                w_desc: weightsDescriptor,
                                                o_desc: outDescriptor,
                                                bias: biasDescriptor,
                                                activation: .identity,
                                                x_stride: 1, y_stride: 1,
                                                x_dilation_stride: 0, y_dilation_stride: 0,
                                                x_padding: 0, y_padding: 0,
                                                groups: 1,
                                                pad: (0, 0, 0, 0))

// `convolutionLayer` is a `BNNSFilter` created by `BNNSFilterCreateLayerConvolution` using `parameters`.

let error = BNNSFilterApplyBatch(convolutionLayer, 1,
                                 input, inStride,
                                 &output, outStride)
```

## Topics

### Creating an Array Descriptor

[`init(flags:layout:size:stride:data:data_type:table_data:table_data_type:data_scale:data_bias:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/init(flags:layout:size:stride:data:data_type:table_data:table_data_type:data_scale:data_bias:))

Returns a new n-dimensional array descriptor with the specified parameters.

[`init(data:scalarType:shape:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/init(data:scalarType:shape:))

Returns a new n-dimensional array descriptor that references the same data as the specified raw pointer.

[`init(data:shape:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/init(data:shape:))

Returns a new n-dimensional array descriptor that references the same data as the specified pointer.

[`init(dataType:shape:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/init(dataType:shape:))

Returns a new n-dimensional array descriptor from the specified data type and shape.

[`init()`](/documentation/Accelerate/BNNSNDArrayDescriptor/init())

Returns a new n-dimensional array descriptor.

### Specifying the Behavior of an N-Dimensional Array.

[`BNNSNDArrayFlags`](/documentation/Accelerate/BNNSNDArrayFlags)

Options that control the behavior of an n-dimensional array.

### Accessing the Properties of an Array Descriptor

[`flags`](/documentation/Accelerate/BNNSNDArrayDescriptor/flags)

Flags that control some behaviors of the n-dimensional array.

[`layout`](/documentation/Accelerate/BNNSNDArrayDescriptor/layout)

The dimension of the n-dimensional array.

[`size`](/documentation/Accelerate/BNNSNDArrayDescriptor/size)

The number of values in each dimension.

[`stride`](/documentation/Accelerate/BNNSNDArrayDescriptor/stride)

The increment, in values, between consecutive elements in each dimension.

[`data`](/documentation/Accelerate/BNNSNDArrayDescriptor/data)

A pointer that is optional and points to the underlying data.

[`data_type`](/documentation/Accelerate/BNNSNDArrayDescriptor/data_type)

The data type of the n-dimensional array.

[`table_data`](/documentation/Accelerate/BNNSNDArrayDescriptor/table_data)

The lookup table for indexed data types.

[`table_data_type`](/documentation/Accelerate/BNNSNDArrayDescriptor/table_data_type)

The data type of the lookup table.

[`data_scale`](/documentation/Accelerate/BNNSNDArrayDescriptor/data_scale)

The scale you use to convert integer and unsigned integer data to floating point.

[`data_bias`](/documentation/Accelerate/BNNSNDArrayDescriptor/data_bias)

The bias you use to convert integer and unsigned integer data to floating point.

[`shape`](/documentation/Accelerate/BNNSNDArrayDescriptor/shape)

The shape of the n-dimensional array.

### Allocating and Deallocating Memory

[`allocate(initializingFrom:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(initializingFrom:shape:batchSize:))

Returns a new n-dimensional array descriptor that’s initialized with a copy of the elements in the specified collection.

[`allocate(randomUniformUsing:range:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomUniformUsing:range:shape:batchSize:)-2rorb)

Returns a new array descriptor that’s initialized with random integer values from the continuous uniform distribution.

[`allocate(randomUniformUsing:range:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomUniformUsing:range:shape:batchSize:)-761hg)

Returns a new array descriptor that’s initialized with random floating-point values from the continuous uniform distribution.

[`allocate(randomIn:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomIn:shape:batchSize:)-1697a)

Returns a new n-dimensional array descriptor that’s initialized with random values within the specified range.

[`allocate(randomIn:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomIn:shape:batchSize:)-5a2p2)

Returns a new n-dimensional array descriptor that’s initialized with random values within the specified range.

[`allocate(randomIn:using:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomIn:using:shape:batchSize:)-5kbi8)

Returns a new array descriptor that’s initialized with random values within the specified range, using the given generator as a source for randomness.

[`allocate(randomIn:using:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(randomIn:using:shape:batchSize:)-3w6ig)

Returns a new array descriptor that’s initialized with random values within the specified range, using the given generator as a source for randomness.

[`allocate(repeating:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocate(repeating:shape:batchSize:))

Returns a new n-dimensional array descriptor that’s initialized with a single, repeated scalar value.

[`allocateUninitialized(scalarType:shape:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/allocateUninitialized(scalarType:shape:batchSize:))

Returns a new n-dimensional array descriptor that’s allocated with uninitialized memory.

[`deallocate()`](/documentation/Accelerate/BNNSNDArrayDescriptor/deallocate())

Deallocates the memory block previously allocated to this n-dimensional array descriptor.

### Generating an Array from an Array Descriptor’s Data

[`makeArray(of:batchSize:)`](/documentation/Accelerate/BNNSNDArrayDescriptor/makeArray(of:batchSize:))

Returns a new array that contains a copy of the n-dimensional array descriptor’s data.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)