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

# NDArray.RawView

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

```
struct RawView
```

## Topics

### Creating a raw view

[`init(bytes: RawSpan, byteOffset: Int, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int], interleaveLayout: NDArray.InterleaveLayout?)`](/documentation/CoreAI/NDArray/RawView/init(bytes: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/RawView/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/RawView/init(ioSurface:byteOffset:scalarType:shape:strides:interleaveLayout:))

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

### Inspecting the view

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

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

The shape of the tensor.

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

The strides of the tensor.

[`var bytes: RawSpan`](/documentation/CoreAI/NDArray/RawView/bytes)

A span over the backing bytes of this tensor.

[`var interleaveLayout: NDArray.InterleaveLayout?`](/documentation/CoreAI/NDArray/RawView/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.View<T>`](/documentation/CoreAI/NDArray/RawView/view(as:))

Consume this raw view to create a typed view.

### Slicing the view

[`func slice<let indexRank : Int>(at: [indexRank of any NDArray.RangeExpression]) -> NDArray.RawView`](/documentation/CoreAI/NDArray/RawView/slice(at:)-1gght)

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

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

### Instance Methods

[`func withUnsafeBytes<R, E>((UnsafeRawPointer, Span<Int>, Span<Int>) throws(E) -> R) throws(E) -> R`](/documentation/CoreAI/NDArray/RawView/withUnsafeBytes(_:))

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)