---
title: "init(unsafeUninitializedShape:scalarType:initializingWith:)"
framework: coreml
role: symbol
role_heading: Initializer
path: "coreml/mltensor/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.

## Declaration

```swift
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.

## See Also

### Creating a tensor

- [init(_:)](coreml/mltensor/init(_:).md)
- [init(_:alongAxis:)](coreml/mltensor/init(_:alongaxis:).md)
- [init(_:scalarType:)](coreml/mltensor/init(_:scalartype:).md)
- [init(bytesNoCopy:shape:scalarType:deallocator:)](coreml/mltensor/init(bytesnocopy:shape:scalartype:deallocator:).md)
- [init(concatenating:alongAxis:)](coreml/mltensor/init(concatenating:alongaxis:).md)
- [init(linearSpaceFrom:through:count:)](coreml/mltensor/init(linearspacefrom:through:count:).md)
- [init(linearSpaceFrom:through:count:scalarType:)](coreml/mltensor/init(linearspacefrom:through:count:scalartype:).md)
- [init(ones:scalarType:)](coreml/mltensor/init(ones:scalartype:).md)
- [init(randomNormal:mean:standardDeviation:seed:scalarType:)](coreml/mltensor/init(randomnormal:mean:standarddeviation:seed:scalartype:).md)
- [init(randomUniform:in:seed:scalarType:)](coreml/mltensor/init(randomuniform:in:seed:scalartype:).md)
- [init(rangeFrom:to:by:)](coreml/mltensor/init(rangefrom:to:by:).md)
- [init(rangeFrom:to:by:scalarType:)](coreml/mltensor/init(rangefrom:to:by:scalartype:).md)
- [init(repeating:shape:)](coreml/mltensor/init(repeating:shape:).md)
- [init(repeating:shape:scalarType:)](coreml/mltensor/init(repeating:shape:scalartype:).md)
- [init(shape:data:scalarType:)](coreml/mltensor/init(shape:data:scalartype:).md)
