---
title: "BNNSFilterCreateLayerReduction(_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/bnnsfiltercreatelayerreduction(_:_:)"
---

# BNNSFilterCreateLayerReduction(_:_:)

Returns a new reduction layer.

## Declaration

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

## Parameters

- `layer_params`: Layer parameters.
- `filter_params`: The filter runtime parameters.

## Discussion

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: 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: 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: 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: 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].

## See Also

### Reduction layers

- [BNNS.ReductionLayer](accelerate/bnns/reductionlayer.md)
- [applyReduction(_:input:output:weights:filterParameters:)](accelerate/bnns/applyreduction(_:input:output:weights:filterparameters:).md)
- [BNNSReduceFunction](accelerate/bnnsreducefunction.md)
- [BNNSLayerParametersReduction](accelerate/bnnslayerparametersreduction.md)
- [BNNSDirectApplyReduction(_:_:)](accelerate/bnnsdirectapplyreduction(_:_:).md)
