<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLTensor/init(unsafeUninitializedShape:scalarType:initializingWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV24unsafeUninitializedShape10scalarType16initializingWithACSaySiG_AA0C6Scalar_pXpySwKXEtKcfc"
  },
  "title" : "init(unsafeUninitializedShape:scalarType:initializingWith:)"
}
-->

# init(unsafeUninitializedShape:scalarType:initializingWith:)

Creates a tensor with the specified shape, then calls the given closure with a buffer covering the tensor’s uninitialized memory.

```
init(unsafeUninitializedShape shape: [Int], scalarType: any MLTensorScalar.Type, initializingWith initializer: (UnsafeMutableRawBufferPointer) throws -> Void) rethrows
```

## Parameters

`shape`

The dimensions of the tensor.

`scalarType`

The scalar type.

`initializer`

A closure which will be called to initialize the underlying memory of the tensor. Scalars expected to be
stored contiguously in first-major order.

---

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)