MLModelErrorDomain
TypeScriptconst MLModelErrorDomain: stringSwift declarationlet MLModelErrorDomain: StringIntegrate machine learning models into your app.
100 types
474 callable entries
123 skipped
79% entry coverage
Generated from iOS SDK 27.1. Availability is shown on each declaration; permissions and entitlements still apply.
MLArrayBatchProvider
class · iOS 12.0+
MLBatchProvider
protocol · iOS 12.0+
MLComputeDevice
enum · iOS 17.0+
MLComputeDeviceProtocol
protocol · iOS 17.0+
MLComputePlan
class · iOS 17.4+
MLComputePlan.Cost
struct · iOS 17.4+
MLComputePlan.DeviceUsage
struct · iOS 17.4+
MLComputePolicy
struct · iOS 18.0+
MLComputeUnits
enum · iOS 12.0+
MLCPUComputeDevice
class · iOS 17.0+
MLCustomLayer
protocol · iOS 11.2+
MLCustomModel
protocol · iOS 12.0+
MLDictionaryConstraint
class · iOS 11.0+
MLDictionaryFeatureProvider
class · iOS 11.0+
MLFeatureDescription
class · iOS 11.0+
MLFeatureProvider
protocol · iOS 11.0+
MLFeatureType
enum · iOS 11.0+
MLFeatureValue
class · iOS 11.0+
MLFeatureValue.ImageOption
struct
MLGPUComputeDevice
class · iOS 17.0+
MLImageConstraint
class · iOS 11.0+
MLImageSize
class · iOS 12.0+
MLImageSizeConstraint
class · iOS 12.0+
MLImageSizeConstraintType
enum · iOS 12.0+
MLKey
class · iOS 13.0+
MLMetricKey
class · iOS 13.0+
MLModel
class · iOS 11.0+
MLModelAsset
class · iOS 16.0+
MLModelConfiguration
class · iOS 12.0+
MLModelDescription
class · iOS 11.0+
MLModelError
struct · iOS 11.0+
MLModelError.Code
enum · iOS 11.0+
MLModelMetadataKey
struct
MLModelStructure
enum · iOS 17.4+
MLModelStructure.NeuralNetwork
struct · iOS 17.4+
MLModelStructure.NeuralNetwork.Layer
struct · iOS 17.4+
MLModelStructure.Pipeline
struct · iOS 17.4+
MLModelStructure.Program
struct · iOS 17.4+
MLModelStructure.Program.Argument
struct · iOS 17.4+
MLModelStructure.Program.Binding
enum · iOS 17.4+
MLModelStructure.Program.Block
struct · iOS 17.4+
MLModelStructure.Program.Function
struct · iOS 17.4+
MLModelStructure.Program.NamedValueType
struct · iOS 17.4+
MLModelStructure.Program.Operation
struct · iOS 17.4+
MLModelStructure.Program.Value
struct · iOS 17.4+
MLModelStructure.Program.ValueType
struct · iOS 17.4+
MLMultiArray
class · iOS 11.0+
MLMultiArrayConstraint
class · iOS 11.0+
MLMultiArrayDataType
enum · iOS 11.0+
MLMultiArrayShapeConstraint
class · iOS 12.0+
MLMultiArrayShapeConstraintType
enum · iOS 12.0+
MLNeuralEngineComputeDevice
class · iOS 17.0+
MLNumericConstraint
class · iOS 13.0+
MLOptimizationHints
struct · iOS 17.4+
MLOptimizationHints.ReshapeFrequency
enum · iOS 17.4+
MLOptimizationHints.ReshapeFrequency.RawValue
typealias · iOS 17.4+
MLOptimizationHints.SpecializationStrategy
enum · iOS 18.0+
MLOptimizationHints.SpecializationStrategy.RawValue
typealias · iOS 18.0+
MLParameterDescription
class · iOS 13.0+
MLParameterKey
class · iOS 13.0+
MLPredictionOptions
class · iOS 11.0+
MLSendableFeatureValue
struct · iOS 18.0+
MLSequence
class · iOS 12.0+
MLSequenceConstraint
class · iOS 12.0+
MLShapedArray
struct · iOS 15.0+
MLShapedArray.ArrayLiteralElement
typealias · iOS 15.0+
MLShapedArray.Element
typealias · iOS 15.0+
MLShapedArray.Index
typealias · iOS 15.0+
MLShapedArray.Indices
typealias · iOS 15.0+
MLShapedArray.Iterator
typealias · iOS 15.0+
MLShapedArray.SubSequence
typealias · iOS 15.0+
MLShapedArrayBufferLayout
enum · iOS 18.0+
MLShapedArrayProtocol
protocol · iOS 15.0+
MLShapedArrayRangeExpression
protocol · iOS 15.0+
MLShapedArrayScalar
protocol · iOS 15.0+
MLShapedArraySlice
struct · iOS 15.0+
MLShapedArraySlice.ArrayLiteralElement
typealias · iOS 15.0+
MLShapedArraySlice.Element
typealias · iOS 15.0+
MLShapedArraySlice.Index
typealias · iOS 15.0+
MLShapedArraySlice.Indices
typealias · iOS 15.0+
MLShapedArraySlice.Iterator
typealias · iOS 15.0+
MLShapedArraySlice.SubSequence
typealias · iOS 15.0+
MLState
class · iOS 18.0+
MLStateConstraint
class · iOS 18.0+
MLTask
class · iOS 13.0+
MLTaskState
enum · iOS 13.0+
MLTensor
struct · iOS 18.0+
MLTensor.ArrayLiteralElement
typealias · iOS 18.0+
MLTensor.BooleanLiteralType
typealias · iOS 18.0+
MLTensor.FloatLiteralType
typealias · iOS 18.0+
MLTensor.IntegerLiteralType
typealias · iOS 18.0+
MLTensor.PaddingMode
enum · iOS 18.0+
MLTensor.ResizeMethod
enum · iOS 18.0+
MLTensorRangeExpression
protocol · iOS 18.0+
MLTensorScalar
protocol · iOS 18.0+
MLUpdateContext
class · iOS 13.0+
MLUpdateProgressEvent
struct · iOS 13.0+
MLUpdateProgressHandlers
class · iOS 13.0+
MLUpdateTask
class · iOS 13.0+
MLWritable
protocol · iOS 13.0+
const MLModelErrorDomain: stringSwift declarationlet MLModelErrorDomain: StringpointwiseMax(lhs: MLTensor, rhs: MLTensor): MLTensorSwift declarationfunc pointwiseMax(_ lhs: MLTensor, _ rhs: MLTensor) -> MLTensorComputes the element-wise minimum between two tensors. For example: ```swift let x = MLTensor([1.0, 3.0, 6.0]) let y = MLTensor([6.0, 3.0, 1.0]) let z = pointwiseMax(x, y) await z.shapedArray(of: Float.self) // is [6.0, 3.0, 6.0] ``` Shapes must be broadcastable, where the broadcasted shape becomes the shape of the output.
pointwiseMin(lhs: MLTensor, rhs: MLTensor): MLTensorSwift declarationfunc pointwiseMin(_ lhs: MLTensor, _ rhs: MLTensor) -> MLTensorComputes the element-wise minimum of two tensors. For example: ```swift let x = MLTensor([1.0, 3.0, 6.0]) let y = MLTensor([6.0, 3.0, 1.0]) let z = pointwiseMin(x, y) await z.shapedArray(of: Float.self) // is [1.0, 3.0, 1.0] ``` Shapes must be broadcastable, where the broadcasted shape becomes the shape of the output.
get startIndex(): numberSwift declarationvar startIndex: Int { get }The position of the first element in a nonempty collection. If the collection is empty, `startIndex` is equal to `endIndex`.
transposedPermutation(axes: Array<number>): MLShapedArray<number>Swift declarationfunc transposed(permutation axes: [Int]) -> MLShapedArray<Scalar>Returns a transposed shaped array using a custom permutation. Use this method to convert, for example, the image data layout from `[C, H, W]` to `[C, W, H]`, where `C` is channel, `W` is width, and `H` is height. ```swift // The source tensor has 3 channels, 128 x 64 image in [C, H, W] layout. let imageCHW = MLShapedArray<Int32>(scalars: pixelValues, shape: [3, 64, 128]) let imageCWH = imageCHW.transposed(permutation: [0, 2, 1]) imageCHW.shape // [3, 64, 128] imageCWH.shape // [3, 128, 64] ``` The shape (`shape_out`) is transposed from the input shape (`shape_in`) as follows. ```swift shape_out[i] == permutation.map { shape_in[$0] } ``` The scalar value of the output shaped array (`array_out`) is related to the input shaped array (`array_in`) as follows. ```swift array_out(scalarAt: permutation.map { indices[$0] }) == array_in[scalarAt: indices]] ``` - Parameter permutation: The permutation of source axis index.
transposed(): MLShapedArray<number>Swift declarationfunc transposed() -> MLShapedArray<Scalar>Returns a new transposed shaped array. This is equivalent to `transposed(permutation:)` where `permutation:` parameter is `[shape.count-1, shape.count-2, ..., 0]`, which reverses the shape. ```swift let original = MLShapedArray<Int32>(scalars: 0..., shape: [1, 2, 3]) let transposed = original.transposed() transposed.shape // [3, 2, 1] ```
static initBytesNoCopyShapeStridesDeallocator(bytes: SDKHandle, shape: Array<number>, strides: Array<number>, deallocator: _Foundation_Data_Deallocator): MLShapedArray<number>Swift declarationinit(bytesNoCopy bytes: UnsafeRawPointer, shape: [Int], strides: [Int], deallocator: Data.Deallocator)Creates a shaped array with memory content without copying the bytes. - Parameter bytes: The buffer pointer - Parameter shape: The shape of the buffer - Parameter strides: The strides of the buffer - Parameter deallocator: Specifies the mechanism to free the indicated buffer, or `.none`.
get description(): stringSwift declarationvar description: String { get }A textual representation of this `ShapedArray`.
changingLayout(bufferLayout: MLShapedArrayBufferLayout): MLShapedArray<number>Swift declarationfunc changingLayout(to bufferLayout: MLShapedArrayBufferLayout) -> MLShapedArray<Scalar>Returns a copy with the specified buffer layout. The returned shaped array will have `.strides` property according to the requested layout. The function may return a heap-memory backed shaped array even if `self` is backed by a pixel buffer. ```swift let source = MLShapedArray<Int32>(scalars: 0..., shape: [2, 2]) // Returns a new MLShapedArray with the specified strides. _ = source.changingLayout(to: .custom(strides: [4, 1])) // Returns a new MLShapedArray with the first-major contiguous layout. _ = source.changingLayout(to: .firstMajorContiguous) // Returns a new MLShapedArray with the last-major contiguous layout. _ = source.changingLayout(to: .lastMajorContiguous) ``` The `withUnsafeShapedBufferPointer` function provides read-only access to the underlying buffer of the layout. The `withUnsafeMutableShapedBufferPointer(body:)` function may provide a buffer of different layout due to copy-on-write. Use `withUnsafeMutableShapedBufferPointer(bufferLayout:body:)` if you need a specific buffer layout. It raises a precondition error if the custom strides and the shape have different ranks. - Parameters: - bufferLayout: The desired buffer layout.
expandingShape(axis: number): MLShapedArray<number>Swift declarationfunc expandingShape(at axis: Int) -> MLShapedArray<Scalar>Returns a new shaped array with expanded dimensions. The shape of the new `MLShapedArray` gets a new dimension of 1 at the specified axis index. ```swift let original = MLShapedArray<Int32>(scalars: 0..., shape: [2, 3]) let expanded = original.expandingShape(at: 0) expanded.shape // [1, 2, 3] ``` - Parameter dimension: The index into the current shape where dimension of 1 will be inserted.
squeezingShape(): MLShapedArray<number>Swift declarationfunc squeezingShape() -> MLShapedArray<Scalar>Returns a new squeezed shaped array. The new shape removes 1s in the original shape. ```swift let original = MLShapedArray<Int32>(scalars: 0..., shape: [1, 2, 1, 2]) let squeezed = original.squeezingShape() squeezed.shape // [2, 2] ``` When all the dimensions of the original shape is one, the resultant shaped array is a scalar. ```swift let original = MLShapedArray<Int32>(scalars: 42, shape: [1, 1]) let squeezed = original.squeezingShape() squeezed.scalar // 42 ```
static initUnsafeUninitializedShapeInitializingWith(shape: Array<number>, initializer: ((arg0: Float64Array, arg1: Array<number>) => void)): MLShapedArray<number>Swift declarationinit(unsafeUninitializedShape shape: [Int], initializingWith initializer: (inout UnsafeMutableBufferPointer<Scalar>, [Int]) throws -> Void) rethrowsInitialize with a closure. - Parameter shape: The shape - Parameter initializer: The initializing closure. - Parameter ptr: The buffer pointer to be initialized by the closure. - Parameter strides: The strides of the buffer.
withPixelBufferIfAvailable(body: ((arg0: _CoreVideo_CVBuffer) => unknown)): (unknown) | nullSwift declarationfunc withPixelBufferIfAvailable<R>(_ body: (CVPixelBuffer) throws -> R) rethrows -> R?Reads the underlying pixel buffer. Use this method to read the contents of the underlying pixel buffer. The pixel buffer is read only. Do not write to it. ```swift let array = MLShapedArray<Float16>(mutating: pixelBuffer, shape: [2, 3]) array.withPixelBuffer { backingPixelBuffer in // read backingPixelBuffer here. } ``` - Parameters: - body: The closure to run with the pixel buffer. - pixelBuffer: The backing pixel buffer. - Returns: The value returned from body, unless the shaped array doesn't use a pixel buffer backing, in which case the method ignores body and returns nil.
withUnsafeShapedBufferPointer(body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationfunc withUnsafeShapedBufferPointer<R>(_ body: (UnsafeBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls a closure with a pointer to the shaped array’s storage. The storage contains the scalars according to the strides in the closure parameters. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` - Parameter body: A closure with an `UnsafeBufferPointer` parameter that points to the storage for the shaped array. If body has a return value, that value is also used as the return value for the `withUnsafeShapedBufferPointer(_:)` method. The pointer argument is valid only for the duration of the method's execution. - Parameter ptr: The pointer to the memory buffer of the shaped array. - Parameter shape: The shape of the array. - Parameter strides: The strides of the array.
withMutablePixelBufferIfAvailable(body: ((arg0: _CoreVideo_CVBuffer) => unknown)): (unknown) | nullSwift declarationmutating func withMutablePixelBufferIfAvailable<R>(_ body: (CVPixelBuffer) throws -> R) rethrows -> R?Writes to the underlying pixel buffer. Use this method to writes the contents of the underlying pixel buffer. ```swift let array = MLShapedArray<Float16>(mutating: pixelBuffer, shape: [2, 3]) array.withMutablePixelBuffer { backingPixelBuffer in // write backingPixelBuffer here. } ``` - Parameters: - body: The closure to run with the pixel buffer. - pixelBuffer: The backing pixel buffer. `nil` if the shaped array doesn't use pixel buffer backing.
withUnsafeMutableShapedBufferPointerUsing(bufferLayout: MLShapedArrayBufferLayout, body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationmutating func withUnsafeMutableShapedBufferPointer<R>(using bufferLayout: MLShapedArrayBufferLayout, _ body: (inout UnsafeMutableBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls the given closure with a pointer to the array’s mutable storage that has a specified buffer layout. The storage contains the scalars according to buffer layout parameter. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` Unlike `withUnsafeMutableShapedBufferPointer(:)`, this function allows the caller to specify the buffer layout. ```swift // Initialize 2x3 shaped array using an external data that lays out scalars in // last-major order. let data: [Int32] = [0, 3, 1, 4, 2, 5] var array = MLShapedArray<Int32>(repeating: 0, shape: [2, 3]) array.withUnsafeMutableShapedBufferPointer(using: .lastMajorContiguous) { destinationPtr, _, _ in data.withUnsafeBufferPointer() { sourcePtr in destinationPtr.update(from: sourcePtr) } } print(array.strides) // [1, 2] print(array.scalars) // [0, 1, 2, 3, 4, 5]) ```
withUnsafeMutableShapedBufferPointer(body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationmutating func withUnsafeMutableShapedBufferPointer<R>(_ body: (inout UnsafeMutableBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls the given closure with a pointer to the array’s mutable storage. The storage contains the scalars according to the strides in the closure parameters. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` The function may change the underlying buffer layout. Always use the `strides` passed in the closure parameters to access the buffer because it can be different from `self.strides` before invoking this function. - Parameter body: A closure with an `UnsafeMutableBufferPointer` parameter that points to the storage for the array. If no such storage exists, it is created. If body has a return value, that value is also used as the return value for the `withUnsafeMutableShapedBufferPointer(_:)` method. The pointer argument is valid only for the duration of the method's execution. - Parameter ptr: The pointer to the memory buffer of the shaped array. - Parameter shape: The shape of the array. - Parameter strides: The strides of the array.
static initDataShapeStrides(data: ArrayBuffer, shape: Array<number>, strides: Array<number>): MLShapedArray<number>Swift declarationinit(data: Data, shape: [Int], strides: [Int])Creates a shaped array from Data. - Parameter data: The storage of the scalars. - Parameter shape: The shape - Parameter strides: The strides of the buffer.
static initDataShape(data: ArrayBuffer, shape: Array<number>): MLShapedArray<number>Swift declarationinit(data: Data, shape: [Int])Creates a shaped array from Data using default strides - Parameter data: The storage of the scalars. - Parameter shape: The shape
get shape(): Array<number>Swift declarationvar shape: [Int] { get }The shape of the array. For example, 2 x 3 matrix may be represented as a shaped array with the shape of `[2, 3]`.
static initScalar(scalar: number): MLShapedArray<number>Swift declarationinit(scalar: Scalar)Creates a scalar. A scalar is a MLShapedArray with rank zero. The `.scalar` property vends the value. - Parameter scalar: The value of the scalar.
get indices(): SDKHandleSwift declarationvar indices: Range<Int> { get }The indices that are valid for subscripting the collection, in ascending order. A collection's `indices` property can hold a strong reference to the collection itself, causing the collection to be nonuniquely referenced. If you mutate the collection while iterating over its indices, a strong reference can result in an unexpected copy of the collection. To avoid the unexpected copy, use the `index(after:)` method starting with `startIndex` to produce indices instead. var c = MyFancyCollection([10, 20, 30, 40, 50]) var i = c.startIndex while i != c.endIndex { c[i] /= 5 i = c.index(after: i) } // c == MyFancyCollection([2, 4, 6, 8, 10])
static initScalarsShape(scalars: Array<number>, shape: Array<number>): MLShapedArray<number>Swift declarationinit<S>(scalars: S, shape: [Int]) where Scalar == S.Element, S : SequenceInitialize with a sequence and the shape. The length of the sequence must not be less than the number of scalars in the shaped array. - Parameter scalars: The initializing sequence. - Parameter shape: The shape
get strides(): Array<number>Swift declarationvar strides: [Int] { get }The strides of the underlying buffer. The strides defines where each scalar is placed in the memory. With strides `[s1, s2, .. sn]`, the element at `[x1, x2, .., xn]` is located in `s1 * x1 + s2 * x2 + ... + sn * xn`-th position in the memory. Use the property to access the buffer provided through Unsafe(Mutable)BufferPointer. There is no need to use the property in index, subscript, or scalars array access.
get endIndex(): numberSwift declarationvar endIndex: Int { get }The collection's "past the end" position---that is, the position one greater than the last valid subscript argument. When you need a range that includes the last element of a collection, use the half-open range operator (`..<`) with `endIndex`. The `..<` operator creates a range that doesn't include the upper bound, so it's always safe to use with `endIndex`. For example: let numbers = [10, 20, 30, 40, 50] if let index = numbers.firstIndex(of: 30) { print(numbers[index ..< numbers.endIndex]) } // Prints "[30, 40, 50]" If the collection is empty, `endIndex` is equal to `startIndex`.
reshaped(newShape: Array<number>): MLShapedArray<number>Swift declarationfunc reshaped(to newShape: [Int]) -> MLShapedArray<Scalar>Returns a new reshaped shaped array. The reshaped array gets scalars of the original array in first-major order. Therefore, the initializer is semantically equivalent to: ```swift let reshaped = MLShapedArray(scalars: original.scalars, shape: newShape) ``` Usage example: ```swift let original = MLShapedArray<Int32>(scalars: 0..., shape: [4]) let reshaped = original.reshaping(to: [1, 2, 2]) ``` A scalar can be reshaped to and from a shape where the product of dimensions is one. The method raises a runtime error if the product of dimensions in the new shape is different from the current one. - Parameter newShape: The new shape after reshaping.
subscriptScalarAt(indices: Array<number>): numberSwift declarationsubscript<C>(scalarAt indices: C) -> Scalar where C : Collection, C.Element == Int { get set }The scalar value at the indices. The subscript is the scalar value of the slice pointed by the specified indices. It raises a runtime error if the specified indices is a slice with `.isScalar == false`. - Parameter indices: The indices to a scalar
subscript(index: number): MLShapedArraySlice<number>Swift declarationsubscript(index: Int) -> MLShapedArraySlice<Scalar> { get set }Accesses the element at the specified position. For example, you can replace an element of an array by using its subscript. var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"] streets[1] = "Butler" print(streets[1]) // Prints "Butler" You can subscript a collection with any valid index other than the collection's end index. The end index refers to the position one past the last element of a collection, so it doesn't correspond with an element. - Parameter position: The position of the element to access. `position` must be a valid index of the collection that is not equal to the `endIndex` property. - Complexity: O(1)
subscript30778(indices: Array<number>): MLShapedArraySlice<number>Swift declarationsubscript<C>(indices: C) -> MLShapedArraySlice<Scalar> where C : Collection, C.Element == Int { get set }A slice of the shaped array for the selected leading axes. The slice has a rank of `self.rank - indices.count`. For example, given a shaped array `m` with the shape being `3 x 3`, `m[[1]]` returns a slice of shape `[3]` with the contents labeld as `x` below. ``` O O O x x x O O O ``` - Parameter indices: The indices to slice the array.
subscript2169(sliceRanges: Array<SDKHandle>): MLShapedArraySlice<number>Swift declarationsubscript<C>(sliceRanges: C) -> MLShapedArraySlice<Scalar> where C : Collection, C.Element == Range<Int> { get set }A slice of the shaped array for the specified ranges. The slice has the same rank as the source. For example, given a shaped array `m` with the shape being `[3, 3]`, `m[1...2, 0...1]` returns a slice of shape `[2, 2]` with the contents labeld as `x` below. ``` O O O x x O x x O ```
static init(multiArray: MLMultiArray): MLShapedArray<number>Swift declarationinit(_ multiArray: MLMultiArray)get startIndex(): numberSwift declarationvar startIndex: Int { get }The position of the first element in a nonempty collection. If the collection is empty, `startIndex` is equal to `endIndex`.
transposedPermutation(axes: Array<number>): MLShapedArraySlice<number>Swift declarationfunc transposed(permutation axes: [Int]) -> MLShapedArraySlice<Scalar>Returns a new transposed shaped array using a custom permutation. Use this method to convert, for example, the image data layout from `[C, H, W]` to `[C, W, H]`, where `C` is channel, `W` is width, and `H` is height. ```swift // The source tensor has 3 channels, 128 x 64 image in [C, H, W] layout. let imageCHW = MLShapedArray<Int32>(scalars: pixelValues, shape: [3, 64, 128]) // Slice for the first two channels. let imageSliceCHW = imageCHW[0..<2] // Transpose. let imageSliceCWH = imageSliceCHW.transposed(permutation: [0, 2, 1]) imageSliceCHW.shape // [2, 64, 128] imageSliceCWH.shape // [2, 128, 64] ``` The shape (`shape_out`) is transposed from the input shape (`shape_in`) as follows. ```swift shape_out[i] == permutation.map { shape_in[$0] } ``` The scalar value of the output shaped array (`array_out`) is related to the input shaped array (`array_in`) as follows. ```swift array_out(scalarAt: permutation.map { indices[$0] }) == array_in[scalarAt: indices]] ``` - Parameter permutation: The permutation of source axis index.
transposed(): MLShapedArraySlice<number>Swift declarationfunc transposed() -> MLShapedArraySlice<Scalar>Returns a new transposed shaped array This is equivalent to `transposed(permutation:)` where `permutation:` parameter is `[shape.count-1, shape.count-2, ..., 0]`, which reverses the shape. ```swift let original = MLShapedArraySlice<Int32>(scalars: 0..., shape: [1, 2, 3]) let transposed = original.transposed() transposed.shape // [3, 2, 1] ```
static initBytesNoCopyShapeStridesDeallocator(bytes: SDKHandle, shape: Array<number>, strides: Array<number>, deallocator: _Foundation_Data_Deallocator): MLShapedArraySlice<number>Swift declarationinit(bytesNoCopy bytes: UnsafeRawPointer, shape: [Int], strides: [Int], deallocator: Data.Deallocator)Creates a shaped array with memory content without copying the bytes. - Parameter bytes: The buffer pointer - Parameter shape: The shape of the buffer - Parameter strides: The strides of the buffer - Parameter deallocator: Specifies the mechanism to free the indicated buffer, or `.none`.
changingLayout(bufferLayout: MLShapedArrayBufferLayout): MLShapedArraySlice<number>Swift declarationfunc changingLayout(to bufferLayout: MLShapedArrayBufferLayout) -> MLShapedArraySlice<Scalar>Returns a copy with the specified buffer layout. The returned shaped array slice will have `.strides` property according to the requested layout. The function may return a heap-memory backed shaped array even if `self` is backed by a pixel buffer. ```swift let source = MLShapedArray<Int32>(scalars: 0..., shape: [4, 4]) let slice = source[1...2, 1...2] // slice.shape == [2, 2] // Returns a new MLShapedArraySlice with the specified strides. _ = slice.changingLayout(to: .custom(strides: [3, 1])) // Returns a new MLShapedArraySlice with the first-major contiguous layout. _ = source.changingLayout(to: .firstMajorContiguous) // strides = [2, 1] // Returns a new MLShapedArraySlice with the last-major contiguous layout. _ = source.changingLayout(to: .lastMajorContiguous) // strides = [1, 2] ``` The `withUnsafeShapedBufferPointer` function provides read-only access to the underlying buffer of the layout. The `withUnsafeMutableShapedBufferPointer(body:)` function may provide a buffer of different layout due to copy-on-write. Use `withUnsafeMutableShapedBufferPointer(bufferLayout:body:)` if you need a specific buffer layout. It raises a precondition error if the custom strides and the shape have different ranks. - Parameters: - bufferLayout: The desired buffer layout.
expandingShape(axis: number): MLShapedArraySlice<number>Swift declarationfunc expandingShape(at axis: Int) -> MLShapedArraySlice<Scalar>Returns a new shaped array with expanded dimensions The shape of the new `MLShapedArraySlice` gets a new dimension of 1 at the specified axis index. ```swift let original = MLShapedArraySlice<Int32>(scalars: 0..., shape: [2, 3]) let expanded = original.expanded(alongAxis: 0) expanded.shape // [1, 2, 3] ``` - Parameter alongAxis: The index into the current shape where dimension of 1 will be inserted.
squeezingShape(): MLShapedArraySlice<number>Swift declarationfunc squeezingShape() -> MLShapedArraySlice<Scalar>Returns a new squeezed shaped array. The new shape removes 1s in the original shape. ```swift let original = MLShapedArraySlice<Int32>(scalars: 0..., shape: [1, 2, 1, 2]) let squeezed = original.squeezed() squeezed.shape // [2, 2] ``` When all the dimensions of the original shape is one, the resultant shaped array is a scalar. ```swift let original = MLShapedArray<Int32>(scalars: 42, shape: [1, 1]) let squeezed = original.squeezed() squeezed.scalar // 42 ```
static initUnsafeUninitializedShapeInitializingWith(shape: Array<number>, initializer: ((arg0: Float64Array, arg1: Array<number>) => void)): MLShapedArraySlice<number>Swift declarationinit(unsafeUninitializedShape shape: [Int], initializingWith initializer: (inout UnsafeMutableBufferPointer<Scalar>, [Int]) throws -> Void) rethrowsInitialize with a closure. - Parameter shape: The shape - Parameter initializer: The initializing closure. - Parameter ptr: The pointer to the buffer to be initialized by the closure. - Parameter strides: The strides of the buffer.
withUnsafeShapedBufferPointer(body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationfunc withUnsafeShapedBufferPointer<R>(_ body: (UnsafeBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls a closure with a pointer to the shaped array’s storage. The storage contains the scalars according to the strides in the closure parameters. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` - Parameter body: A closure with an `UnsafeBufferPointer` parameter that points to the storage for the shaped array. If body has a return value, that value is also used as the return value for the `withUnsafeShapedBufferPointer(_:)` method. The pointer argument is valid only for the duration of the method's execution. - Parameter ptr: The pointer to the memory buffer of the shaped array. - Parameter shape: The shape of the array. - Parameter strides: The strides of the array.
withUnsafeMutableShapedBufferPointerUsing(bufferLayout: MLShapedArrayBufferLayout, body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationmutating func withUnsafeMutableShapedBufferPointer<R>(using bufferLayout: MLShapedArrayBufferLayout, _ body: (inout UnsafeMutableBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls the given closure with a pointer to the array’s mutable storage that has a specified buffer layout. The storage contains the scalars according to buffer layout parameter. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` Unlike `withUnsafeMutableShapedBufferPointer(:)`, this function allows the caller to specify the buffer layout. ```swift // Initialize the middle 2x2 of 4x4 shaped array using an external data that lays out // scalars in last-major order. let data: [Int32] = [1, 3, 2, 4] var array = MLShapedArray<Int32>(repeating: 0, shape: [4, 4]) array[1...2, 1...2].withUnsafeMutableShapedBufferPointer(using: .lastMajorContiguous) { destinationPtr, _, _ in data.withUnsafeBufferPointer() { sourcePtr in destinationPtr.update(from: sourcePtr) } } // array.scalars == [0, 0, 0, 0, // 0, 1, 2, 0, // 0, 3, 4, 0, // 0, 0, 0, 0,]) ```
withUnsafeMutableShapedBufferPointer(body: ((arg0: Float64Array, arg1: Array<number>, arg2: Array<number>) => unknown)): unknownSwift declarationmutating func withUnsafeMutableShapedBufferPointer<R>(_ body: (inout UnsafeMutableBufferPointer<Scalar>, [Int], [Int]) throws -> R) rethrows -> RCalls the given closure with a pointer to the array’s mutable storage. The storage contains the scalars according to the strides in the closure parameters. For example, the scalar at `[x1, x2, ... xn]` with strides `[s1, s2, ... sn]` is stored at `ptr[x1 * s1 + x2 * s2 + ... + xn * sn]` The function may change the underlying buffer layout. Always use the `strides` passed in the closure parameters to access the buffer because it can be different from `self.strides` before invoking this function. - Parameter body: A closure with an `UnsafeMutableBufferPointer` parameter that points to the storage for the array. If no such storage exists, it is created. If body has a return value, that value is also used as the return value for the `withUnsafeMutableShapedBufferPointer(_:)` method. The pointer argument is valid only for the duration of the method's execution. - Parameter ptr: The pointer to the memory buffer of the shaped array. - Parameter shape: The shape of the array. - Parameter strides: The strides of the array.
static initDataShapeStrides(data: ArrayBuffer, shape: Array<number>, strides: Array<number>): MLShapedArraySlice<number>Swift declarationinit(data: Data, shape: [Int], strides: [Int])Creates a shaped array slice from Data. - Parameter data: The storage of the scalars. - Parameter shape: The shape - Parameter strides: The strides of the buffer.
static initDataShape(data: ArrayBuffer, shape: Array<number>): MLShapedArraySlice<number>Swift declarationinit(data: Data, shape: [Int])Creates a shaped array slice from Data using default strides. - Parameter data: The storage of the scalars. - Parameter shape: The shape
get shape(): Array<number>Swift declarationlet shape: [Int]The shape of the array. For example, 2 x 3 matrix may be represented as a shaped array with the shape of `[2, 3]`.
static initScalar(scalar: number): MLShapedArraySlice<number>Swift declarationinit(scalar: Scalar)Creates a scalar. A scalar is a MLShapedArray with rank zero. The `.scalar` property vends the value. - Parameter scalar: The value of the scalar.
static initScalarsShape(scalars: Array<number>, shape: Array<number>): MLShapedArraySlice<number>Swift declarationinit<S>(scalars: S, shape: [Int]) where Scalar == S.Element, S : SequenceInitialize with a sequence and the shape. The length of the sequence must not be less than the number of scalars in the shaped array. - Parameter scalars: The initializing sequence. - Parameter shape: The shape
get strides(): Array<number>Swift declarationvar strides: [Int] { get }The strides of the underlying buffer. The strides defines where each scalar is placed in the memory. With strides `[s1, s2, .. sn]`, the element at `[x1, x2, .., xn]` is located in `s1 * x1 + s2 * x2 + ... + sn * xn`-th position in the memory. Use the property to access the buffer provided through Unsafe(Mutable)BufferPointer. There is no need to use the property in index, subscript, or scalars array access.
get endIndex(): numberSwift declarationvar endIndex: Int { get }The collection's "past the end" position---that is, the position one greater than the last valid subscript argument. When you need a range that includes the last element of a collection, use the half-open range operator (`..<`) with `endIndex`. The `..<` operator creates a range that doesn't include the upper bound, so it's always safe to use with `endIndex`. For example: let numbers = [10, 20, 30, 40, 50] if let index = numbers.firstIndex(of: 30) { print(numbers[index ..< numbers.endIndex]) } // Prints "[30, 40, 50]" If the collection is empty, `endIndex` is equal to `startIndex`.
reshaped(newShape: Array<number>): MLShapedArraySlice<number>Swift declarationfunc reshaped(to newShape: [Int]) -> MLShapedArraySlice<Scalar>Returns a new reshaped shaped array. The reshaped array gets scalars of the original array in first-major order. Therefore, the initializer is semantically equivalent to: ```swift let reshaped = MLShapedArray(scalars: original.scalars, shape: newShape) ``` Usage example: ```swift let original = MLShapedArraySlice<Int32>(scalars: 0..., shape: [4]) let reshaped = original.reshaped(to: [1, 2, 2]) ``` A scalar can be reshaped to and from a shape where the product of dimensions is one. The method raises a runtime error if the product of dimensions in the new shape is different from the current one. - Parameter newShape: The new shape after reshaping.
subscriptScalarAt(indices: Array<number>): numberSwift declarationsubscript<C>(scalarAt indices: C) -> Scalar where C : Collection, C.Element == Int { get set }The scalar value at the indices. The subscript is the scalar value of the slice pointed by the specified indices. It raises a runtime error if the specified indices is a slice with `.isScalar == false`. - Parameter indices: The indices to a scalar
static init(multiArray: MLMultiArray): MLShapedArraySlice<number>Swift declarationinit(_ multiArray: MLMultiArray)Creates a new MLShapedArraySlice using a `MLMultiArray` as a backing storage. Use this initializer to access `MLMultiArray` through `MLShapedArray` interface. Mutating operations trigger copy-on-write. Non-mutating operations access the `MLMultiArray`'s backing storage including the pixel buffer. - Parameters: - multiArray: The `MLMultiArray` object.
subscript(indices: Array<number>): MLShapedArraySlice<number>Swift declarationsubscript<C>(indices: C) -> MLShapedArraySlice<Scalar> where C : Collection, C.Element == Int { get set }A slice of the shaped array for the selected leading axes. The slice has a rank of `self.rank - indices.count`. For example, given a shaped array `m` with the shape being `3 x 3`, `m[[1]]` returns a slice of shape `[3]` with the contents labeld as `x` below. ``` O O O x x x O O O ``` - Parameter indices: The indices to slice the array.
subscript96786(sliceRanges: Array<SDKHandle>): MLShapedArraySlice<number>Swift declarationsubscript<C>(sliceRanges: C) -> MLShapedArraySlice<Scalar> where C : Collection, C.Element == Range<Int> { get set }A slice of the shaped array for the specified ranges. The slice has the same rank as the source. For example, given a shaped array `m` with the shape being `[3, 3]`, `m[1...2, 0...1]` returns a slice of shape `[2, 2]` with the contents labeld as `x` below. ``` O O O x x O x x O ```
withMLTensorComputePolicy(computePolicy: MLComputePolicy, body: (() => unknown)): unknownSwift declarationfunc withMLTensorComputePolicy<Result>(_ computePolicy: MLComputePolicy, _ body: () throws -> Result) rethrows -> ResultCalls the given closure within a task-local context using the specified compute policy to influence what compute device tensor operations are executed on. - Parameters: - computePolicy: A compute policy that will be set before the closure gets called and restored after the closure returns. - body: A nullary closure. If the closure has a return value, that value is also used as the return value of the `withMLTensorComputePolicy(_:_:)` function. - Returns: The return value, if any, of the `body` closure.
withMLTensorComputePolicy83181(computePolicy: MLComputePolicy, body: (() => Promise<unknown>)): Promise<unknown>Swift declarationfunc withMLTensorComputePolicy<R>(_ computePolicy: MLComputePolicy, _ body: () async throws -> R) async rethrows -> RCalls the given closure within a task-local context using the specified compute policy to influence what compute device tensor operations are executed on. - Parameters: - computePolicy: A compute policy that will be set before the closure gets called and restored after the closure returns. - body: A nullary closure. If the closure has a return value, that value is also used as the return value of the `withMLTensorComputePolicy(_:_:)` function. - Returns: The return value, if any, of the `body` closure.
123 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
UnsafeBufferPointer.init(_:)
The containing type is outside the generated SDK type index.
UnsafeMutableBufferPointer.init(_:)
The containing type is outside the generated SDK type index.
Int32.multiArrayDataType
The containing type is outside the generated SDK type index.
Int8.multiArrayDataType
The containing type is outside the generated SDK type index.
Double.multiArrayDataType
The containing type is outside the generated SDK type index.
Float.multiArrayDataType
The containing type is outside the generated SDK type index.
Float16.multiArrayDataType
The containing type is outside the generated SDK type index.
Range.relative(toShapedArrayAxis:)
The containing type is outside the generated SDK type index.
PartialRangeFrom.relative(toShapedArrayAxis:)
The containing type is outside the generated SDK type index.
PartialRangeUpTo.relative(toShapedArrayAxis:)
The containing type is outside the generated SDK type index.
ClosedRange.relative(toShapedArrayAxis:)
The containing type is outside the generated SDK type index.
PartialRangeThrough.relative(toShapedArrayAxis:)
The containing type is outside the generated SDK type index.
MLShapedArraySlice.init(concatenating:alongAxis:)
This declaration needs Swift generic type arguments. (no canonical witness for S)
MLShapedArraySlice.init(mutating:shape:)
The iOS SDK compiler rejected this binding: cannot find 'o' in scope
MLShapedArrayProtocol.subscript(_:)
The iOS SDK compiler rejected this binding: cannot access associated type 'Scalar' from 'MLShapedArrayProtocol'; use a concrete type or generic parameter base instead
MLShapedArrayProtocol.subscript(_:)
A variable number of Swift arguments is not supported.
MLShapedArrayProtocol.subscript(_:)
The iOS SDK compiler rejected this binding: member 'subscript' cannot be used on value of type 'any MLShapedArrayProtocol'; consider using a generic constraint instead [#ExistentialMemberAccess]
MLShapedArrayProtocol.subscript(_:)
A variable number of Swift arguments is not supported.
MLShapedArrayProtocol.subscript(scalarAt:)
A variable number of Swift arguments is not supported.
MLShapedArrayProtocol.scalars
The iOS SDK compiler rejected this binding: cannot assign to property: 'o' is a 'let' constant
MLShapedArrayProtocol.scalar
The iOS SDK compiler rejected this binding: cannot assign to property: 'o' is a 'let' constant
MLShapedArrayProtocol.fill(with:)
The iOS SDK compiler rejected this binding: cannot access associated type 'Scalar' from 'MLShapedArrayProtocol'; use a concrete type or generic parameter base instead
MLShapedArrayProtocol.fill(with:)
This declaration needs Swift generic type arguments. (no canonical witness for C)
MLShapedArrayProtocol.index(after:)
The iOS SDK compiler rejected this binding: ambiguous type name 'Index' in 'MLShapedArrayProtocol'
MLShapedArrayProtocol.index(_:offsetBy:)
The iOS SDK compiler rejected this binding: ambiguous type name 'Index' in 'MLShapedArrayProtocol'
MLShapedArrayProtocol.init(identityMatrixOfSize:)
A protocol cannot be constructed directly.
MLShapedArrayProtocol.init(randomScalarsIn:shape:)
A protocol cannot be constructed directly.
MLShapedArrayProtocol.init(identityMatrixOfSize:)
A protocol cannot be constructed directly.
MLShapedArrayProtocol.init(randomScalarsIn:shape:)
A protocol cannot be constructed directly.
MLShapedArrayProtocol.init(arrayLiteral:)
A variable number of Swift arguments is not supported.