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

# BNNSCompareTensor(_:_:_:_:)

Returns a tensor of Boolean type by comparing or performing a logical operation between two inputs.

```
func BNNSCompareTensor(_ in0: UnsafePointer<BNNSNDArrayDescriptor>, _ in1: UnsafePointer<BNNSNDArrayDescriptor>, _ op: BNNSRelationalOperator, _ out: UnsafeMutablePointer<BNNSNDArrayDescriptor>) -> Int32
```

## Parameters

`in0`

The descriptor of the first input.

`in1`

The descriptor of the second input.

`op`

The operator for comparison.

`out`

The descriptor of the output.

## Discussion

Use relational operators, for example [`BNNSRelationalOperatorGreater`](/documentation/Accelerate/BNNSRelationalOperatorGreater) and [`BNNSRelationalOperatorLess`](/documentation/Accelerate/BNNSRelationalOperatorLess), to compare floating-point elements. The following code compares the elements of two arrays of single-precision values for equality:

```swift
let a: [Float] = [1, 2, 3, 4]
let b: [Float] = [5, 4, 3, 2]

let size = (a.count, 0, 0, 0, 0, 0, 0, 0)
let stride = (0, 0, 0, 0, 0, 0, 0, 0)

var destination = [Bool](repeating: false,
                         count: size.0)

a.withUnsafeBufferPointer { aPtr in
    b.withUnsafeBufferPointer { bPtr in
        destination.withUnsafeMutableBufferPointer { destinationPtr in
            var aDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                     layout: BNNSDataLayoutVector,
                                                     size: size,
                                                     stride: stride,
                                                     data: UnsafeMutableRawPointer(mutating: aPtr.baseAddress!),
                                                     data_type: .float,
                                                     table_data: nil,
                                                     table_data_type: .float,
                                                     data_scale: 1,
                                                     data_bias: 0)
            
            var bDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                     layout: BNNSDataLayoutVector,
                                                     size: size,
                                                     stride: stride,
                                                     data: UnsafeMutableRawPointer(mutating: bPtr.baseAddress!),
                                                     data_type: .float,
                                                     table_data: nil,
                                                     table_data_type: .float,
                                                     data_scale: 1,
                                                     data_bias: 0)
            
            var destinationDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                               layout: BNNSDataLayoutVector,
                                                               size: size,
                                                               stride: stride,
                                                               data: destinationPtr.baseAddress!,
                                                               data_type: BNNSDataTypeBoolean,
                                                               table_data: nil,
                                                               table_data_type: BNNSDataTypeBoolean,
                                                               data_scale: 1,
                                                               data_bias: 0)
            
            BNNSCompareTensor(&aDescription,
                              &bDescription,
                              BNNSRelationalOperatorEqual,
                              &destinationDescription)
        }
    }
}
```

On return, `destination` contains the values `[false, false, true, false]`.

Use logical operators, for example [`BNNSRelationalOperatorLogicalAND`](/documentation/Accelerate/BNNSRelationalOperatorLogicalAND) and [`BNNSRelationalOperatorLogicalOR`](/documentation/Accelerate/BNNSRelationalOperatorLogicalOR), to compare Boolean elements. The following code performs a logical AND operation on the elements of two arrays of Boolean values:

```swift
let a: [Bool] = [ true, false, false, true]
let b: [Bool] = [false, false,  true, true]

let size = (a.count, 0, 0, 0, 0, 0, 0, 0)
let stride = (0, 0, 0, 0, 0, 0, 0, 0)

var destination = [Bool](repeating: false,
                         count: size.0)

a.withUnsafeBufferPointer { aPtr in
    b.withUnsafeBufferPointer { bPtr in
        destination.withUnsafeMutableBufferPointer { destinationPtr in
            var aDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                     layout: BNNSDataLayoutVector,
                                                     size: size,
                                                     stride: stride,
                                                     data: UnsafeMutableRawPointer(mutating: aPtr.baseAddress!),
                                                     data_type: BNNSDataTypeBoolean,
                                                     table_data: nil,
                                                     table_data_type: BNNSDataTypeBoolean,
                                                     data_scale: 1,
                                                     data_bias: 0)
            
            var bDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                     layout: BNNSDataLayoutVector,
                                                     size: size,
                                                     stride: stride,
                                                     data: UnsafeMutableRawPointer(mutating: bPtr.baseAddress!),
                                                     data_type: BNNSDataTypeBoolean,
                                                     table_data: nil,
                                                     table_data_type: BNNSDataTypeBoolean,
                                                     data_scale: 1,
                                                     data_bias: 0)
            
            var destinationDescription = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                               layout: BNNSDataLayoutVector,
                                                               size: size,
                                                               stride: stride,
                                                               data: destinationPtr.baseAddress!,
                                                               data_type: BNNSDataTypeBoolean,
                                                               table_data: nil,
                                                               table_data_type: BNNSDataTypeBoolean,
                                                               data_scale: 1,
                                                               data_bias: 0)
            
            BNNSCompareTensor(&aDescription,
                              &bDescription,
                              BNNSRelationalOperatorLogicalAND,
                              &destinationDescription)
            
        }
    }
}
```

On return, `destination` contains the values `[false, false, false, true]`.

---

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)