<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/sparseTensor(sparseTensorWithDescriptor:tensors:shape:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)sparseTensorWithDescriptor:tensors:shape:name:"
  },
  "title" : "sparseTensor(sparseTensorWithDescriptor:tensors:shape:name:)"
}
-->

# sparseTensor(sparseTensorWithDescriptor:tensors:shape:name:)

Creates a sparse tensor representation.

```
func sparseTensor(sparseTensorWithDescriptor sparseDescriptor: MPSGraphCreateSparseOpDescriptor, tensors inputTensorArray: [MPSGraphTensor], shape: [NSNumber], name: String?) -> MPSGraphTensor
```

## Parameters

`sparseDescriptor`

A sparseDescriptor.

`inputTensorArray`

An array of input tensors as [sparseVals, indexTensor0, indexTensor1].

`shape`

The shape of the sparse tensor.

`name`

A name for the operation.

## Return Value

A valid [`MPSGraphTensor`](/documentation/MetalPerformanceShadersGraph/MPSGraphTensor) object

## Discussion

sparseVals corresponds to non zero values in matrix.
indexTensor0 and indexTensor1 are indices used for indexing into sparse data structure.
For COO, indexTensor0 is x index and indexTensor1 is y index .
For CSC, indexTensor0 and indexTensor1 correspond to rowIndex and colStarts respectively.
For CSR, indexTensor0 and indexTensor1 correspond to colIndex and rowStarts respectively.
You must set input tensors appropriately for each sparse storage type.

---

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)