---
title: "init(bytes:byteOffset:scalarType:shape:strides:interleaveLayout:)"
framework: coreai
role: symbol
role_heading: Initializer
path: "coreai/ndarray/rawview/init(bytes:byteoffset:scalartype:shape:strides:interleavelayout:)"
---

# init(bytes:byteOffset:scalarType:shape:strides:interleaveLayout:)

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

## Declaration

```swift
init(bytes: RawSpan, byteOffset: Int = 0, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int] = [], interleaveLayout: NDArray.InterleaveLayout? = nil)
```

## Discussion

Discussion The lifetime of the resulting view copies the lifetime of the provided span. Note that the provided scalarType will be stored and later checked if you attempt to convert the raw view to a typed view. let myBytes: RawSpan = ... let ndArrayRawView = NDArray.RawView(bytes: myBytes, scalarType: .float32, shape: [4, 5])

// This conversion is checked. If the type does not match the originally provided scalar type // it will trap at runtime. let floatView = ndArrayRawView.view(as: Float32.self) The shape/strides must not be able to produce offsets that go outside of the range of bytes. As such, negative strides are not supported by this initializer. Performance note: Making an ndArray view from a normal VM pointer to be used as an input or backing of an InferenceFunction could be a performance anti-pattern if you intend to pass the same underlying memory in repeatedly to many inferences. This can be a function of which compute units the model was specialized for. For example if the inference function runs compute on the GPU or Neural Engine, you may incur a copy of the view into the required memory primitive if it cannot be toll-free converted. bytes: The raw bytes to be referenced by the resulting view. byteOffset: The offset into the span to be interpreted as the start of this view. scalarType: The type of scalars in the provided span. shape: The shape of the resulting view. strides: The strides of the resulting view. If left empty, they will be computed as contiguous row-major. interleaveLayout: Which dimension is interleaved and by what factor. See NDArray.InterleaveLayout.
