<!--
{
  "availability" : [
    "iOS: 14.0.0 - 18.0.0",
    "iPadOS: 14.0.0 - 18.0.0",
    "macCatalyst: 14.0.0 - 18.0.0",
    "macOS: 11.0.0 - 15.0.0",
    "tvOS: 14.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0",
    "watchOS: 7.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSFilterCreateLayerDropout(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSFilterCreateLayerDropout"
  },
  "title" : "BNNSFilterCreateLayerDropout(_:_:)"
}
-->

# BNNSFilterCreateLayerDropout(_:_:)

Returns a new dropout layer.

```
func BNNSFilterCreateLayerDropout(_ layer_params: UnsafePointer<BNNSLayerParametersDropout>, _ filter_params: UnsafePointer<BNNSFilterParameters>?) -> BNNSFilter?
```

## Parameters

`layer_params`

Layer parameters.

`filter_params`

Filter runtime parameters.

## Discussion

Use a dropout layer to randomly set the elements—or entire dimensions—of a tensor to 0. The layer scales the unchanged elements by `1 / (1 -` [`rate`](/documentation/Accelerate/BNNSLayerParametersDropout/rate) `)`. The following code randomly drops half the elements from a 4 x 4 matrix:

```swift
let input: [Float] = [1, 1, 1, 1,
                      1, 1, 1, 1,
                      1, 1, 1, 1,
                      1, 1, 1, 1]

var output = [Float](repeating: 0,
                     count: input.count)

let descriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                       layout: BNNSDataLayoutRowMajorMatrix,
                                       size: (4, 4, 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: 0,
                                       data_bias: 0)

let control: UInt8 = 0b0000
let rate: Float = 0.5

var dropoutParams = BNNSLayerParametersDropout(i_desc: descriptor,
                                               o_desc: descriptor,
                                               rate: rate,
                                               seed: 0,
                                               control: control)

let dropoutFilter = BNNSFilterCreateLayerDropout(&dropoutParams, nil)

BNNSFilterApply(dropoutFilter, input, &output)
```

On return, output contains the following values:

```c
[ 2.0, 2.0, 0.0, 0.0, 
  2.0, 2.0, 0.0, 2.0, 
  2.0, 0.0, 0.0, 2.0, 
  0.0, 0.0, 0.0, 2.0 ]
```

Use the [`control`](/documentation/Accelerate/BNNSLayerParametersDropout/control) parameter to dropout entire dimensions. For example, setting `control` to `0b0010` and `rate` to `0.75` drops three quarters of the columns, and scales the remaining values by 4:

```c
[ 0.0, 4.0, 0.0, 0.0, 
  0.0, 4.0, 0.0, 0.0, 
  0.0, 4.0, 0.0, 0.0, 
  0.0, 4.0, 0.0, 0.0 ]
```

---

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)