<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/NDArray/MutableView",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV11MutableViewV"
  },
  "title" : "NDArray.MutableView"
}
-->

# NDArray.MutableView

A mutable view over the storage of a tensor.

```
struct MutableView<Element> where Element : BitwiseCopyable
```

## Topics

### Creating a mutable view

[`init(mutableSpan: consuming MutableSpan<Element>, shape: [Int], strides: [Int])`](/documentation/CoreAI/NDArray/MutableView/init(mutableSpan:shape:strides:))

Initialize a view from a `MutableSpan`.

### Inspecting the view

[`var isContiguous: Bool`](/documentation/CoreAI/NDArray/MutableView/isContiguous)

Returns `true` if the elements in this view have a row-major contiguous layout.

[`var rank: Int`](/documentation/CoreAI/NDArray/MutableView/rank)

The rank of the tensor.

[`var shape: Span<Int>`](/documentation/CoreAI/NDArray/MutableView/shape)

The shape of the tensor.

[`var strides: Span<Int>`](/documentation/CoreAI/NDArray/MutableView/strides)

The strides of the tensor.

[`var interleaveLayout: NDArray.InterleaveLayout?`](/documentation/CoreAI/NDArray/MutableView/interleaveLayout)

Returns which dimension is interleaved, and by what factor it is interleaved. Or returns `nil`
if there is not an interleaved dimension.

### Accessing elements

[`var contiguousElements: MutableSpan<Element>?`](/documentation/CoreAI/NDArray/MutableView/contiguousElements)

Returns a `MutableSpan` over the backing memory of this view if the memory is in a contiguous layout, otherwise returns `nil`.

[`subscript<let rank : Int>(scalarAt _: InlineArray<rank, Int>) -> Element`](/documentation/CoreAI/NDArray/MutableView/subscript(scalarAt:))

Access the element at a multi-dimensional `index`.

### Writing data

[`func copyElements(from: some Sequence<Element>)`](/documentation/CoreAI/NDArray/MutableView/copyElements(from:))

Copies the elements from `sequence` into this view in row-major order.

[`func copyElements(fromContentsOf: some Collection<Element>)`](/documentation/CoreAI/NDArray/MutableView/copyElements(fromContentsOf:))

Copies the elements from `collection` into this view in row-major order.

### Accessing memory

[`func withUnsafeMutablePointer<R, E>((UnsafeMutablePointer<Element>, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R`](/documentation/CoreAI/NDArray/MutableView/withUnsafeMutablePointer(_:))

Invokes the provided closure with the backing data and memory layout of this view.

### Slicing the view

[`func slice<let indexRank : Int>(at: [indexRank of any NDArray.RangeExpression]) -> NDArray.MutableView<Element>`](/documentation/CoreAI/NDArray/MutableView/slice(at:)-50cpv)

Returns a sub-view with the same rank as this view by slicing the dimensions at the provided ranges.

[`func slice(at: [any NDArray.RangeExpression]) -> NDArray.MutableView<Element>`](/documentation/CoreAI/NDArray/MutableView/slice(at:)-qyjq)

Returns a sub-view with the same rank as this view by slicing the dimensions at the provided ranges.

[`func mutatingSlice<let indexRank : Int>(at: [indexRank of any NDArray.RangeExpression]) -> NDArray.MutableView<Element>`](/documentation/CoreAI/NDArray/MutableView/mutatingSlice(at:)-30asd)

Returns a sub-view with the same rank as this view by slicing the dimensions at the provided ranges.

[`func mutatingSlice(at: [any NDArray.RangeExpression]) -> NDArray.MutableView<Element>`](/documentation/CoreAI/NDArray/MutableView/mutatingSlice(at:)-9pmi4)

Returns a sub-view with the same rank as this view by slicing the dimensions at the provided ranges.

### Converting to other views

[`var view: NDArray.View<Element>`](/documentation/CoreAI/NDArray/MutableView/view)

An immutable view of this mutable view.

[`var mutableRawView: NDArray.MutableRawView`](/documentation/CoreAI/NDArray/MutableView/mutableRawView)

Returns a mutable raw view over the same data.



---

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)