<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/HammingDistance(primary:secondary:resultDataType:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)HammingDistanceWithPrimaryTensor:secondaryTensor:resultDataType:name:"
  },
  "title" : "HammingDistance(primary:secondary:resultDataType:name:)"
}
-->

# HammingDistance(primary:secondary:resultDataType:name:)

Computes the hamming distance of two input tensors with support for broadcasting.

```
func HammingDistance(primary primaryTensor: MPSGraphTensor, secondary secondaryTensor: MPSGraphTensor, resultDataType: MPSDataType, name: String?) -> MPSGraphTensor
```

## Parameters

`primaryTensor`

The first input tensor.

`secondaryTensor`

The second input tensor.

`resultDataType`

The datatype of the return MPSGraphTensor. Must be either `MPSDataTypeUInt32` or `MPSDataTypeUInt16`.

`name`

The name for the operation.

## Return Value

A valid tensor containing the hamming distance between the input tensors.

## Discussion

The hamming distance is computed between 2 sets of vectors and the last dimension(s) of each
input tensor is considered a vector.

---

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)