<!--
{
  "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/MutableRawView",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV14MutableRawViewV"
  },
  "title" : "NDArray.MutableRawView"
}
-->

# NDArray.MutableRawView

A type-erased mutable view over the memory owned by a tensor.

```
struct MutableRawView
```

## Topics

### Creating a mutable raw view

[`init(mutableBytes: consuming MutableRawSpan, byteOffset: Int, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int], interleaveLayout: NDArray.InterleaveLayout?)`](/documentation/CoreAI/NDArray/MutableRawView/init(mutableBytes:byteOffset:scalarType:shape:strides:interleaveLayout:))

Initialize a raw view from existing raw memory, interpreted as the specified scalar type.

[`init(metalBuffer: borrowing any MTLBuffer, byteOffset: Int, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int], interleaveLayout: NDArray.InterleaveLayout?)`](/documentation/CoreAI/NDArray/MutableRawView/init(metalBuffer:byteOffset:scalarType:shape:strides:interleaveLayout:))

Initialize a raw view from an existing metal buffer, interpreted as the specified scalar type.

[`init(ioSurface: borrowing IOSurface, byteOffset: Int, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int], interleaveLayout: NDArray.InterleaveLayout?)`](/documentation/CoreAI/NDArray/MutableRawView/init(ioSurface:byteOffset:scalarType:shape:strides:interleaveLayout:))

Initialize a mutable raw view from an existing IOSurface, interpreted as the specified scalar type.

### Inspecting the view

[`var scalarType: NDArray.ScalarType`](/documentation/CoreAI/NDArray/MutableRawView/scalarType)

The scalar type of the ndArray.

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

The shape of the ndArray.

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

The strides of the ndArray.

[`var mutableBytes: MutableRawSpan`](/documentation/CoreAI/NDArray/MutableRawView/mutableBytes)

A mutable span over the backing bytes of this tensor.

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

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

### Creating typed views

[`func view<T>(as: T.Type) -> NDArray.MutableView<T>`](/documentation/CoreAI/NDArray/MutableRawView/view(as:))

Create a typed `MutableView` of the same storage as this raw view.

### Converting to immutable

[`var rawView: NDArray.RawView`](/documentation/CoreAI/NDArray/MutableRawView/rawView)

Returns an immutable raw view over the same backing data.

### Slicing the view

[`func slice<let indexRank : Int>(at: [indexRank of any NDArray.RangeExpression]) -> NDArray.MutableRawView`](/documentation/CoreAI/NDArray/MutableRawView/slice(at:)-47fbq)

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.MutableRawView`](/documentation/CoreAI/NDArray/MutableRawView/slice(at:)-82sdj)

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.MutableRawView`](/documentation/CoreAI/NDArray/MutableRawView/mutatingSlice(at:)-5tnq5)

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.MutableRawView`](/documentation/CoreAI/NDArray/MutableRawView/mutatingSlice(at:)-5ts4w)

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

### Instance Methods

[`func withUnsafeMutableBytes<R, E>((UnsafeMutableRawPointer, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R`](/documentation/CoreAI/NDArray/MutableRawView/withUnsafeMutableBytes(_:))

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

---

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)