<!--
{
  "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/BNNSFilterCreateLayerReduction(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSFilterCreateLayerReduction"
  },
  "title" : "BNNSFilterCreateLayerReduction(_:_:)"
}
-->

# BNNSFilterCreateLayerReduction(_:_:)

Returns a new reduction layer.

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

## Parameters

`layer_params`

Layer parameters.

`filter_params`

The filter runtime parameters.

## Discussion

Use a reduction layer to reduce an axis or axes of a tensor to a scalar value. Specify a size of one for the dimension or dimensions you need to reduce.

For example, given the following source data and n-dimensional array descriptors:

```swift
let sourceData: [Float] = [1, 4, 7,
                           2, 5, 8,
                           3, 6, 9]

let inDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                         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: 0,
                                         data_bias: 0)

var outDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                          layout: BNNSDataLayoutRowMajorMatrix,
                                          size: (0, 0, 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)
```

Use the following code to compute the sums of elements of each row:

```swift
outDescriptor.size = (1, 3, 0, 0, 0, 0, 0, 0)

var layerParams = BNNSLayerParametersReduction(i_desc: inDescriptor,
                                               o_desc: outDescriptor,
                                               w_desc: BNNSNDArrayDescriptor(),
                                               reduce_func: BNNSReduceFunctionSum,
                                               epsilon: 0)

let reductionLayer = BNNSFilterCreateLayerReduction(&layerParams, nil)
defer {
    BNNSFilterDestroy(reductionLayer)
}

var destinationData: [Float] = [0, 0, 0]

BNNSFilterApply(reductionLayer,
                sourceData,
                &destinationData)
```

On return, destination data contains `[12.0, 15.0, 18.0]`.

Use the following code to compute the sums of elements of each column:

```swift
outDescriptor.size = (3, 1, 0, 0, 0, 0, 0, 0)

var layerParams = BNNSLayerParametersReduction(i_desc: inDescriptor,
                                               o_desc: outDescriptor,
                                               w_desc: BNNSNDArrayDescriptor(),
                                               reduce_func: BNNSReduceFunctionSum,
                                               epsilon: 0)

let reductionLayer = BNNSFilterCreateLayerReduction(&layerParams, nil)
defer {
    BNNSFilterDestroy(reductionLayer)
}

var destinationData: [Float] = [0, 0, 0]

BNNSFilterApply(reductionLayer,
                sourceData,
                &destinationData)
```

On return, destination data contains `[6.0, 15.0, 24.0]`.

Use the following code to compute the sum of all elements:

```swift
outDescriptor.size = (1, 1, 0, 0, 0, 0, 0, 0)

var layerParams = BNNSLayerParametersReduction(i_desc: inDescriptor,
                                               o_desc: outDescriptor,
                                               w_desc: BNNSNDArrayDescriptor(),
                                               reduce_func: BNNSReduceFunctionSum,
                                               epsilon: 0)

let reductionLayer = BNNSFilterCreateLayerReduction(&layerParams, nil)
defer {
    BNNSFilterDestroy(reductionLayer)
}

var destinationData: [Float] = [0]

BNNSFilterApply(reductionLayer,
                sourceData,
                &destinationData)
```

On return, destination data contains `[45.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)