<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4ComputeCommandEncoder/copy(sourceTensor:sourceOrigin:sourceDimensions:destinationTensor:destinationOrigin:destinationDimensions:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4ComputeCommandEncoder(im)copyFromTensor:sourceOrigin:sourceDimensions:toTensor:destinationOrigin:destinationDimensions:"
  },
  "title" : "copy(sourceTensor:sourceOrigin:sourceDimensions:destinationTensor:destinationOrigin:destinationDimensions:)"
}
-->

# copy(sourceTensor:sourceOrigin:sourceDimensions:destinationTensor:destinationOrigin:destinationDimensions:)

Encodes a command to copy data from a slice of the data plane of a tensor into a slice of the data plane of
another tensor.

```
func copy(sourceTensor: any MTLTensor, sourceOrigin: MTLTensorExtents, sourceDimensions: MTLTensorExtents, destinationTensor: any MTLTensor, destinationOrigin: MTLTensorExtents, destinationDimensions: MTLTensorExtents)
```

## Parameters

`sourceTensor`

A tensor instance the method copies data from.

`sourceOrigin`

An array of per-dimension offsets that together locate the first element
to copy in `sourceTensor`. Each element in this array corresponds to the dimension at the
same index in `sourceDimensions`. Each offset value represents the number of elements from
the start of that dimension.

`sourceDimensions`

An array of per-dimension sizes that together define the extent of the
slice to copy from `sourceTensor`. Each element in this array corresponds to the dimension
at the same index in `sourceOrigin`. Each size value represents the number of elements to
include along that dimension, starting from the corresponding offset in `sourceOrigin`.

`destinationTensor`

A tensor instance the method copies data to.

`destinationOrigin`

An array of per-dimension offsets that together locate the first element
to write in `destinationTensor`. Each element in this array corresponds to the dimension at
the same index in `destinationDimensions`. Each offset value represents the number of elements
from the start of that dimension.

`destinationDimensions`

An array of per-dimension sizes that together define the extent of
the slice to write in `destinationTensor`. Each element in this array corresponds to the
dimension at the same index in `destinationOrigin`. Each size value represents the number of
elements to include along that dimension, starting from the corresponding offset in
`destinationOrigin`.

## Discussion

If `sourceTensor` and `destinationTensor` are not aliasable, this command applies a reshape operation.

Ensure the first dimension of `sourceOrigin`, `sourceDimensions`, `destinationOrigin`,
and `destinationDimensions` is byte aligned.

---

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)