<!--
{
  "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/MTLTensor/replace(sliceOrigin:sliceDimensions:withBytes:strides:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLTensor(im)replaceSliceOrigin:sliceDimensions:withBytes:strides:"
  },
  "title" : "replace(sliceOrigin:sliceDimensions:withBytes:strides:)"
}
-->

# replace(sliceOrigin:sliceDimensions:withBytes:strides:)

Replaces a slice of the data plane of this tensor with data from a pointer you provide.

```
func replace(sliceOrigin: MTLTensorExtents, sliceDimensions: MTLTensorExtents, withBytes bytes: UnsafeRawPointer, strides: MTLTensorExtents)
```

## Parameters

`sliceOrigin`

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

`sliceDimensions`

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

`bytes`

A pointer to bytes of data to copy into the slice.

`strides`

An array of strides, in elements, that describes the layout
of the data in `bytes`.

## Discussion

Create the tensor with [`storageModeShared`](/documentation/Metal/MTLResourceOptions/storageModeShared)
for CPU access via this method.

Strides need to be monotonically non-decreasing: for any `i > 0`,
`strides[i] >= strides[i-1] * dimensions[i-1]`.

The first dimension of `sliceOrigin` and `sliceDimensions` needs to be 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)