<!--
{
  "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/View/init(span:shape:strides:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime7NDArrayV4ViewV4span5shape7stridesAEy_xGs4SpanVyxG_SaySiGAMtcfc"
  },
  "title" : "init(span:shape:strides:)"
}
-->

# init(span:shape:strides:)

Initialize a view from a `Span`.

```
init(span: Span<Element>, shape: [Int], strides: [Int] = [])
```

## Discussion

The lifetime of the resulting view copies the lifetime of the provided span.

Also note that the `shape/strides` must not be able to produce offsets that go outside of the range of `span`.
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`](/documentation/CoreAI/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.

- span: The span to be referenced by the resulting view.
- 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.

---

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)