<!--
{
  "availability" : [
    "iOS: 14.0.0 - 17.4.0",
    "iPadOS: 14.0.0 - 17.4.0",
    "macCatalyst: 14.0.0 - 17.4.0",
    "macOS: 11.0.0 - 14.3.0",
    "tvOS: 14.0.0 - 17.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "MLCompute",
  "identifier" : "/documentation/MLCompute/MLCGramMatrixLayer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCGramMatrixLayer"
  },
  "title" : "MLCGramMatrixLayer"
}
-->

# MLCGramMatrixLayer

A layer that computes the uncentered cross-correlation values between the spacial planes of each feature channel of a tensor.

```
class MLCGramMatrixLayer
```

## Overview

For example, if the input tensor batch function is:

`x = x[b, y, x, c]`

The computation performed by this layer is:

`y = y[b, 1, f, c] = alpha * sum_{x, y} x[b, y, x, f] * x[b, y, x, c]`

Interpret this operation as computing all combinations of fully connected layers between the different spatial planes of the input tensor.

The layer performs this operation independently for each tensor in a batch. Then the layer stores these results in the feature channel and x-coordinate indices of the output batch.

Legend:

- `b`: The batch index.
- `y` and `x`: The spatial coordinates.
- `c`: The feature channel index.
- `alpha`: The scaling factor.

## Topics

### Creating Gram Matrix Layers

[`init(scale:)`](/documentation/MLCompute/MLCGramMatrixLayer/init(scale:))

Creates a gram matrix layer with the scaling factor you specify.

### Inspecting Gram Matrix Layers

[`scale`](/documentation/MLCompute/MLCGramMatrixLayer/scale)

The scaling factor.



---

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)