### Padding Operation Setup Source: https://developer.apple.com/documentation/accelerate/bnnspaddingmodeconstant Example setup for a padding operation using source data and padding sizes. ```swift let paddingSize = (2, 4) let source: [Float] = [ 0, 1, 2, 3, 4, 5, 7, 8, 9 ] var destination = [Float](repeating: 0, count: source.count + paddingSize.0 + paddingSize.1) ``` -------------------------------- ### Create FFT Setup - Swift Source: https://developer.apple.com/documentation/accelerate/vdsp_fouriertransformfunctions/makefftsetup%28log2n%3Aradix%3A%29 Use this method to create an FFT setup. Requires the base-2 logarithm of the FFT size and the radix for the transform. Returns an opaque pointer to the setup or nil if creation fails. ```swift static func makeFFTSetup( log2n: vDSP_Length, radix: vDSP.Radix ) -> OpaquePointer? ``` -------------------------------- ### Create a biquad setup object with two sections Source: https://developer.apple.com/documentation/accelerate/vdsp_biquad_createsetup Example of creating a biquad setup object with two sections using vDSP_biquad_CreateSetup. Ensure to call vDSP_biquad_DestroySetup to free allocated memory. ```swift let section0 = (b0: 0.984764420, b1: -1.969528840, b2: 0.984764420, a1: -1.969331359, a2: 0.969726321) let section1 = (b0: 0.984764420, b1: -1.969528840, b2: 0.984764420, a1: -1.955243388, a2: 0.969726321) let sectionCount = vDSP_Length(2) let setup = vDSP_biquad_CreateSetup([ section0.b0, section0.b1, section0.b2, section0.a1, section0.a2, section1.b0, section1.b1, section1.b2, section1.a1, section1.a2 ], sectionCount) ``` -------------------------------- ### Create FFT Setup Source: https://developer.apple.com/documentation/accelerate/vdsp_fouriertransformfunctions Use this method to create an FFT setup object. It requires the logarithm base 2 of the FFT size and the radix for the transform. ```swift static func makeFFTSetup(log2n: vDSP_Length, radix: vDSP.Radix) -> OpaquePointer? ``` -------------------------------- ### Create Double-Precision Real DFT Setup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zrop_createsetupd Use this function to create a setup structure for real, double-precision DFT functions. Pass nil for the previous setup if initializing memory, otherwise pass an existing setup to share memory. Ensure the length satisfies the supported values (f * 2^n, where f is 1, 3, 5, or 15 and n is at least 4). ```c vDSP_DFT_SetupD vDSP_DFT_zrop_CreateSetupD(vDSP_DFT_SetupD __Previous, vDSP_Length __Length, vDSP_DFT_Direction __Direction); ``` -------------------------------- ### Initialize vDSP DFT setup structure Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zrop_createsetup The function signature for creating a setup structure for real, single-precision DFT functions. ```C vDSP_DFT_SetupvDSP_DFT_zrop_CreateSetup(vDSP_DFT_Setup __Previous, vDSP_Length __Length, vDSP_DFT_Direction __Direction); ``` -------------------------------- ### Create single-precision DFT setup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_interleaved_executed%28_%3A_%3A_%3A%29 Returns a setup structure containing precalculated data for single-precision interleaved DFT functions. ```Swift func vDSP_DFT_Interleaved_CreateSetup(vDSP_DFT_Interleaved_Setup?, vDSP_Length, vDSP_DFT_Direction, vDSP_DFT_RealtoComplex) -> vDSP_DFT_Interleaved_Setup? ``` -------------------------------- ### Create double-precision DFT setup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_interleaved_executed%28_%3A_%3A_%3A%29 Returns a setup structure containing precalculated data for double-precision interleaved DFT functions. ```Swift func vDSP_DFT_Interleaved_CreateSetupD(vDSP_DFT_Interleaved_SetupD?, vDSP_Length, vDSP_DFT_Direction, vDSP_DFT_RealtoComplex) -> vDSP_DFT_Interleaved_SetupD? ``` -------------------------------- ### Initialize a double-precision DFT setup structure Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zop_createsetupd The function signature for creating a setup structure for double-precision complex DFT operations. ```C vDSP_DFT_SetupDvDSP_DFT_zop_CreateSetupD(vDSP_DFT_SetupD __Previous, vDSP_Length __Length, vDSP_DFT_Direction __Direction); ``` -------------------------------- ### Usage Example for multiply(addition:_:) Source: https://developer.apple.com/documentation/accelerate/vdsp/multiply%28addition%3A_%3A%29-7t59 A practical example demonstrating how to use the vDSP multiply function with three input arrays. ```swift let a: [Float] = [ 1, 2, 3, 4, 5] let b: [Float] = [10, 20, 30, 40, 50] let c: [Float] = [ 5, 4, 3, 2, 1] let d = vDSP.multiply(addition: (a, b), c) // Prints "[55.0, 88.0, 99.0, 88.0, 55.0]". print(d) ``` -------------------------------- ### Usage Example for add(multiplication:multiplication:) Source: https://developer.apple.com/documentation/accelerate/vdsp/add%28multiplication%3Amultiplication%3A%29-8rjh8 A practical example demonstrating how to use the function with two input vectors and two scalar values. ```swift let a: [Float] = [ 1, 2, 3, 4, 5] let b: Float = 10 let c: [Float] = [ 5, 4, 3, 2, 1] let d: Float = 50 let e = vDSP.add(multiplication: (a, b), multiplication: (c, d)) // Prints "[260.0, 220.0, 180.0, 140.0, 100.0]". print(e) ``` -------------------------------- ### vDSP_DFT_CreateSetup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_createsetup Initializes a setup structure for DFT operations. ```APIDOC ## vDSP_DFT_CreateSetup ### Description Creates a setup structure for Discrete Fourier Transform (DFT) operations. ### Method C Function ### Parameters #### Arguments - **__Previous** (vDSP_DFT_Setup) - The previous setup structure, or NULL. - **__Length** (vDSP_Length) - The length of the DFT. ### Request Example ```c vDSP_DFT_Setup setup = vDSP_DFT_CreateSetup(NULL, 1024); ``` ``` -------------------------------- ### static func makeFFTSetup(log2n:radix:) Source: https://developer.apple.com/documentation/accelerate/vdsp_splitcomplexdouble/makefftsetup%28log2n%3Aradix%3A%29 Returns a setup structure to perform a fast Fourier transform. ```APIDOC ## static func makeFFTSetup(log2n:radix:) ### Description Returns a setup structure to perform a fast Fourier transform. ### Method static func ### Parameters #### Parameters - **log2n** (vDSP_Length) - Required - The base-2 logarithm of the number of elements in the FFT. - **radix** (vDSP.Radix) - Required - The radix of the FFT. ### Response - **OpaquePointer?** - A setup structure to perform a fast Fourier transform, or nil if the setup fails. ``` -------------------------------- ### Example Usage of SparseMultiplyAdd Source: https://developer.apple.com/documentation/accelerate/sparsemultiplyadd%28_%3A_%3A_%3A_%3A%29-3oa6n This example demonstrates how to use SparseMultiplyAdd to perform y += alpha * Ax. It includes setup for the sparse matrix A, dense vectors x and y, and the scalar alpha. Ensure to clean up the sparse matrix A using defer. ```swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _y+=Ax_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _x_ in _y+=Ax_. var xValues = [10.0, -1.0, -1.0, 10.0] var yValues = [1.0, 1.0, 1.0, 1.0] let alpha = 2.0 /// The values for _y_ in _y+=Ax_. yValues.withUnsafeMutableBufferPointer { yValuesPtr in xValues.withUnsafeMutableBufferPointer { xValuesPtr in /// The _x_ in _y+=Ax_. let x = DenseVector_Double(count: 4, data: xValuesPtr.baseAddress!) /// The _y_ in _y+=Ax_. let y = DenseVector_Double(count: 4, data: yValuesPtr.baseAddress!) SparseMultiplyAdd(alpha, A, x, y) } } /// On return, `yValues` contains: /// `[ 281.0, 1.0, 1.0, 401.0 ]` ``` -------------------------------- ### static func makeFFTSetup(log2n:radix:) Source: https://developer.apple.com/documentation/accelerate/vdsp_splitcomplexfloat/makefftsetup%28log2n%3Aradix%3A%29 Returns a setup structure to perform a fast Fourier transform. ```APIDOC ## static func makeFFTSetup(log2n:radix:) ### Description Returns a setup structure to perform a fast Fourier transform. ### Parameters - **log2n** (vDSP_Length) - Required - The base-2 logarithm of the number of elements in the FFT. - **radix** (vDSP.Radix) - Required - The radix of the FFT. ### Response - **OpaquePointer?** - A pointer to the FFT setup structure, or nil if the setup fails. ``` -------------------------------- ### Performing Sparse Matrix-Dense Matrix Multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiplyadd%28_%3A_%3A_%3A_%3A%29-n61k Example demonstrating the setup of sparse and dense matrices and the execution of the SparseMultiplyAdd operation. ```swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data: [Float] = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _Y += alpha * AX_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _X_ in _Y += alpha * AX_. var xValues: [Float] = [10.0, -1.0, -1.0, 10.0, 100.0, -1.0, -1.0, 100.0] /// The values for _Y_ in _Y += alpha * AX_. var yValues = [Float](repeating: 1, count: xValues.count) let alpha: Float = 2.0 yValues.withUnsafeMutableBufferPointer { yValuesPtr in xValues.withUnsafeMutableBufferPointer { denseMatrixPtr in /// The _X_ in _Y += alpha * AX_. let X = DenseMatrix_Float(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: denseMatrixPtr.baseAddress!) /// The _Y_ in _Y += alpha * AX_. let Y = DenseMatrix_Float(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: yValuesPtr.baseAddress!) SparseMultiplyAdd(alpha, A, X, Y) } } // On return, `yValues` contains: // `[ 281.0, 1.0, 1.0, 401.0, // 2801.0, 1.0, 1.0, 4001.0]` ``` -------------------------------- ### Perform sparse matrix-matrix multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiplyadd%28_%3A_%3A_%3A%29-lgm5 Example demonstrating the setup of sparse and dense matrices followed by the execution of the SparseMultiplyAdd operation. ```Swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _Y+=AX_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _X_ in _Y+=AX_. var xValues = [10.0, -1.0, -1.0, 10.0, 100.0, -1.0, -1.0, 100.0] /// The values for _Y_ in _Y+=AX_. var yValues = [Double](repeating: 1, count: xValues.count) yValues.withUnsafeMutableBufferPointer { yValuesPtr in xValues.withUnsafeMutableBufferPointer { denseMatrixPtr in /// The _X_ in _Y+=AX_. let X = DenseMatrix_Double(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: denseMatrixPtr.baseAddress!) /// The _Y_ in _Y+=AX_. let Y = DenseMatrix_Double(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: yValuesPtr.baseAddress!) SparseMultiplyAdd(A, X, Y) } } // On return, `yValues` contains: // `[ 141.0, 1.0, 1.0, 201.0, // 1401.0, 1.0, 1.0, 2001.0]` ``` -------------------------------- ### Initialize a Discrete Fourier Transform Setup Source: https://developer.apple.com/documentation/accelerate/vdsp/dftdoubleprecisionsplitcomplexfunctions/makediscretefouriertransform%28previous%3Acount%3Adirection%3Atransformtype%3A%29 Use this method to create a configuration for performing discrete Fourier transforms. It requires specifying the transform count, direction, and type. ```swift static func makeDiscreteFourierTransform( previous: OpaquePointer? = nil, count: Int, direction: vDSP.FourierTransformDirection, transformType: vDSP.DFTTransformType ) throws -> OpaquePointer ``` -------------------------------- ### Performing Scalar-Sparse-Dense Matrix Multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiply%28_%3A_%3A_%3A_%3A%29-73ruq Example demonstrating the setup of sparse and dense matrices followed by the execution of the SparseMultiply operation. ```swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _Y = alpha * AX_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _X_ in _Y = alpha * AX_. var xValues = [10.0, -1.0, -1.0, 10.0, 100.0, -1.0, -1.0, 100.0] let alpha = 2.0 /// The values for _Y_ in _Y = alpha * AX_. let yValues = [Double](unsafeUninitializedCapacity: xValues.count) { resultBuffer, count in xValues.withUnsafeMutableBufferPointer { denseMatrixPtr in /// The _X_ in _Y = alpha * AX_. let X = DenseMatrix_Double(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: denseMatrixPtr.baseAddress!) /// The _Y_ in _Y = alpha * AX_. let Y = DenseMatrix_Double(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: resultBuffer.baseAddress!) SparseMultiply(alpha, A, X, Y) } count = xValues.count } // On return, `yValues` contains: // `[ 280.0, 0.0, 0.0, 400.0, // 2800.0, 0.0, 0.0, 4000.0]` ``` -------------------------------- ### static func makeFFTSetup(log2n:radix:) Source: https://developer.apple.com/documentation/accelerate/vdsp_fouriertransformfunctions/makefftsetup%28log2n%3Aradix%3A%29 Initializes an FFT setup for the specified log2n and radix. ```APIDOC ## static func makeFFTSetup(log2n:radix:) ### Description Creates an FFT setup object required for performing Fourier transforms. ### Parameters - **log2n** (vDSP_Length) - Required - The base-2 logarithm of the number of elements. - **radix** (vDSP.Radix) - Required - The radix to use for the FFT. ### Response - **OpaquePointer?** - Returns an opaque pointer to the FFT setup, or nil if initialization fails. ``` -------------------------------- ### Performing Scalar-Matrix-Vector Multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiply%28_%3A_%3A_%3A_%3A%29-76o5l Example demonstrating the setup of a sparse matrix and dense vector, followed by the execution of the SparseMultiply operation. ```swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _y = alpha * Ax_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _x_ in _y = alpha * Ax_. var xValues = [10.0, -1.0, -1.0, 10.0] let alpha = 2.0 /// The values for _y_ in _y = alpha * Ax_. let yValues = [Double](unsafeUninitializedCapacity: xValues.count) { resultBuffer, count in xValues.withUnsafeMutableBufferPointer { xValuesPtr in /// The _x_ in _y = alpha * Ax_. let x = DenseVector_Double(count: 4, data: xValuesPtr.baseAddress!) /// The _y_ in _y = alpha * Ax_. let y = DenseVector_Double(count: 4, data: resultBuffer.baseAddress!) SparseMultiply(alpha, A, x, y) } count = xValues.count } /// On return, `yValues` contains: /// `[ 280.0, 0.0, 0.0, 400.0 ]` ``` -------------------------------- ### Perform DFT with vDSP_DFT_zrop_CreateSetup Source: https://developer.apple.com/documentation/accelerate/understanding-data-packing-for-fourier-transforms Creates a setup object using vDSP_DFT_zrop_CreateSetup to perform a discrete Fourier transform on real values. This is an alternative to the FFT approach. ```swift signal.withUnsafeBytes { signalPtr in complexReals.withUnsafeMutableBufferPointer { realPtr in complexImaginaries.withUnsafeMutableBufferPointer { imagPtr in var splitComplex = DSPSplitComplex(realp: realPtr.baseAddress!, imagp: imagPtr.baseAddress!) vDSP_ctoz([DSPComplex](signalPtr.bindMemory(to: DSPComplex.self)), 2, &splitComplex, 1, vDSP_Length(complexValuesCount)) if let dft = vDSP_DFT_zrop_CreateSetup(nil, vDSP_Length(realValuesCount), .FORWARD) { vDSP_DFT_Execute(dft, realPtr.baseAddress!, imagPtr.baseAddress!, realPtr.baseAddress!, imagPtr.baseAddress!) vDSP_DFT_DestroySetup(dft) } } } } ``` -------------------------------- ### Performing Sparse Matrix-Matrix Multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiply%28_%3A_%3A_%3A%29-9kraw Example demonstrating the setup of sparse and dense matrices followed by the execution of the SparseMultiply operation. ```Swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data: [Float] = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _Y=AX_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _X_ in _Y=AX_. var xValues: [Float] = [10.0, -1.0, -1.0, 10.0, 100.0, -1.0, -1.0, 100.0] /// The values for _Y_ in _Y=AX_. let yValues = [Float](unsafeUninitializedCapacity: xValues.count) { resultBuffer, count in xValues.withUnsafeMutableBufferPointer { denseMatrixPtr in /// The _X_ in _Y=AX_. let X = DenseMatrix_Float(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: denseMatrixPtr.baseAddress!) /// The _Y_ in _Y=AX_. let Y = DenseMatrix_Float(rowCount: 4, columnCount: 2, columnStride: 4, attributes: SparseAttributes_t(), data: resultBuffer.baseAddress!) SparseMultiply(A, X, Y) } count = xValues.count } ``` -------------------------------- ### Performing Sparse Matrix-Vector Multiplication Source: https://developer.apple.com/documentation/accelerate/sparsemultiply%28_%3A_%3A_%3A%29-4hrs4 Example demonstrating the setup of a sparse matrix, dense vector, and the execution of the multiplication operation. ```Swift let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data: [Float] = [1.0, 4.0, 13.0, 16.0] /// The _A_ in _y=Ax_. let A = SparseConvertFromCoordinate(rowCount, columnCount, blockCount, blockSize, SparseAttributes_t(), rowIndices, columnIndices, data) defer { SparseCleanup(A) } /// The values for _x_ in _y=Ax_. var xValues: [Float] = [10.0, -1.0, -1.0, 10.0] /// The values for _y_ in _y=Ax_. let yValues = [Float](unsafeUninitializedCapacity: xValues.count) { resultBuffer, count in xValues.withUnsafeMutableBufferPointer { xValuesPtr in /// The _x_ in _y=Ax_. let x = DenseVector_Float(count: 4, data: xValuesPtr.baseAddress!) /// The _y_ in _y=Ax_. let y = DenseVector_Float(count: 4, data: resultBuffer.baseAddress!) SparseMultiply(A, x, y) } count = xValues.count } /// On return, `yValues` contains: /// `[ 140.0, 0.0, 0.0, 200.0 ]` ``` -------------------------------- ### init(type:mem:apply:) Source: https://developer.apple.com/documentation/accelerate/sparseopaquepreconditioner_double/init%28type%3Amem%3Aapply%3A%29 Creates a new double-precision preconditioner. ```APIDOC ## init(type:mem:apply:) ### Description Creates a new double-precision preconditioner. ### Method Initializer ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ## Parameters `type` The preconditioner type. `mem` The unaltered memory pointer that passes as the first parameter of the `apply` function. `apply` A function that calculates _Y = PX_ , where _P_ is the preconditioner. ``` -------------------------------- ### Create vImageConstCVImageFormat and Get Channel Description Source: https://developer.apple.com/documentation/accelerate/vimagecvimageformat_getchanneldescription%28_%3A_%3A%29 This example demonstrates how to create a vImageConstCVImageFormat from a CVPixelBuffer and then use vImageCVImageFormat_GetChannelDescription to obtain the luminance channel description. ```swift let channelDescription = withUnsafeBytes(of: cvImageFormat) { bytes in let format = bytes.assumingMemoryBound( to: vImageConstCVImageFormat.self).first! return vImageCVImageFormat_GetChannelDescription(format, vImageBufferTypeCode(kvImageBufferTypeCode_Luminance)) } ``` -------------------------------- ### vDSP_DFT_zrop_CreateSetup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zrop_createsetup Returns a setup structure that contains precalculated data for forward and inverse, real, single-precision DFT functions. ```APIDOC ## vDSP_DFT_zrop_CreateSetup ### Description Returns a setup structure that contains precalculated data for forward and inverse, real, single-precision DFT functions. ### Method `vDSP_DFT_zrop_CreateSetup` ### Endpoint N/A (This is a function call, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - `__Previous` (vDSP_DFT_Setup) - Optional - An existing `vDSP_DFT_Setup` structure that shares memory with the returned setup structure. Pass `nil` to create an object with newly initialized and allocated memory. - `__Length` (vDSP_Length) - Required - The number of real elements to process. The supported values are _f_ * 2**_n_ , where _f_ is 1, 3, 5, or 15 and _n_ is at least 4. - `__Direction` (vDSP_DFT_Direction) - Required - A flag that specifies the transform direction. Pass `vDSP_DFT_Direction.FORWARD` to transform from the time domain to the frequency domain. Pass `vDSP_DFT_Direction.INVERSE` to transform from the frequency domain to the time domain. ### Request Example ```c vDSP_DFT_Setup setup = vDSP_DFT_zrop_CreateSetup(nil, length, vDSP_DFT_Direction.FORWARD); ``` ### Response #### Success Response (200) - `vDSP_DFT_Setup` (vDSP_DFT_Setup) - A setup object containing precalculated data for DFT functions. #### Response Example ```c vDSP_DFT_Setup setup; // setup is populated by the function call ``` ### Error Handling Returns `nil` if the function fails, either from insufficient memory or because `Length` doesn’t satisfy the requirements. ### Discussion Important: To prevent potential memory leaks, if the `Previous` parameter is not `nil`, the return value and the `Previous` value must be different variables. This function shares memory between data structures where possible. If you have an existing setup object, you should pass that object as `Previous`. By doing so, the returned setup object can share underlying data storage with that object. Note that this function may allocate memory; you can free any allocated memory by calling `vDSP_DFT_DestroySetup`. Using shared setup objects: If you’re using a shared setup object, the subsequent execute function requires that the input and output pointers are 64-byte aligned. The following code shows how to create the correctly aligned vectors: ```c float* reals = (float*)aligned_alloc(64, length*sizeof(float)); float* imaginaries = (float*)aligned_alloc(64, length*sizeof(float)); ``` ``` -------------------------------- ### Solve a sparse system with QR factorization Source: https://developer.apple.com/documentation/accelerate/sparsesolve%28_%3A_%3A_%3A%29-14nj Example demonstrating matrix creation, factorization, workspace allocation, and solving a system of linear equations. ```Swift /// Create the coefficient matrix _A_. let rowIndices: [Int32] = [ 0, 1, 1, 2] let columnIndices: [Int32] = [ 2, 0, 2, 1] let aValues: [Double] = [10, 20, 5, 50] let A = SparseConvertFromCoordinate(3, 3, 4, 1, SparseAttributes_t(), rowIndices, columnIndices, aValues) /// Factorize _A_. let factorization = SparseFactor(SparseFactorizationQR, A) defer { SparseCleanup(A) SparseCleanup(factorization) } /// Create the right-hand-side vector, _b_: var bValues: [Double] = [30, 35, 100] /// Create the workspace. let byteCount = factorization.solveWorkspaceRequiredStatic + factorization.solveWorkspaceRequiredPerRHS let workspace = UnsafeMutableRawPointer.allocate( byteCount: byteCount, alignment: MemoryLayout.alignment) defer { workspace.deallocate() } /// Solve the system. bValues.withUnsafeMutableBufferPointer { bPtr in let xb = DenseVector_Double(count: 3, data: bPtr.baseAddress!) SparseSolve(factorization, xb, workspace) } ``` -------------------------------- ### Get and Set sgdMomentumVariant - Accelerate Source: https://developer.apple.com/documentation/accelerate/bnns/sgdmomentumoptimizer/sgdmomentumvariant This property specifies the momentum variant for the SGD with Momentum optimizer. It is available on multiple Apple platforms starting from specific OS versions. ```swift var sgdMomentumVariant: BNNSOptimizerSGDMomentumVariant { get set } ``` -------------------------------- ### Solve Sparse System with QR Factorization Source: https://developer.apple.com/documentation/accelerate/sparsesolve%28_%3A_%3A_%3A_%3A%29-7aj3g Example demonstrating the creation of a sparse matrix, factorization, workspace allocation, and solving the system AX = B. ```Swift /// Create the coefficient matrix _A_. let rowIndices: [Int32] = [ 0, 1, 1, 2] let columnIndices: [Int32] = [ 2, 0, 2, 1] let aValues: [Double] = [10, 20, 5, 50] let A = SparseConvertFromCoordinate(3, 3, 4, 1, SparseAttributes_t(), rowIndices, columnIndices, aValues) /// Factorize _A_. let factorization = SparseFactor(SparseFactorizationQR, A) defer { SparseCleanup(A) SparseCleanup(factorization) } /// Create the workspace. let nrhs = Int(A.structure.columnCount) let byteCount = factorization.solveWorkspaceRequiredStatic + nrhs * factorization.solveWorkspaceRequiredPerRHS let workspace = UnsafeMutableRawPointer.allocate( byteCount: byteCount, alignment: MemoryLayout.alignment) defer { workspace.deallocate() } /// Create the right-hand-side matrix, _B_. var bValues: [Double] = [30, 35, 100, 300, 350, 1000] let n = bValues.count /// Solve the system. let xValues = [Double](unsafeUninitializedCapacity: n) { buffer, count in bValues.withUnsafeMutableBufferPointer { bPtr in let B = DenseMatrix_Double(rowCount: 3, columnCount: 2, columnStride: 3, attributes: SparseAttributes_t(), data: bPtr.baseAddress!) let X = DenseMatrix_Double(rowCount: 3, columnCount: 2, columnStride: 3, attributes: SparseAttributes_t(), data: buffer.baseAddress!) SparseSolve(factorization, B, X, workspace) count = n } ``` -------------------------------- ### Create and Get Conversion Matrix Pointer Source: https://developer.apple.com/documentation/accelerate/vimagecvimageformat_getconversionmatrix%28_%3A_%3A%29 This example demonstrates how to create a `vImageConstCVImageFormat` from a `vImageCVImageFormat` and then use `vImageCVImageFormat_GetConversionMatrix` to retrieve the conversion matrix pointer. This is useful when working with `CVPixelBuffer` objects. ```swift let conversionMatrixPointer = withUnsafeBytes(of: cvImageFormat) { bytes in var outType = UInt32() let format = bytes.assumingMemoryBound( to: vImageConstCVImageFormat.self).first! return vImageCVImageFormat_GetConversionMatrix(format, &outType) } ``` -------------------------------- ### vDSP_create_fftsetup Source: https://developer.apple.com/documentation/accelerate/vdsp_create_fftsetup Initializes a setup structure for single-precision FFT functions. ```APIDOC ## vDSP_create_fftsetup ### Description Returns a setup structure that contains precalculated data for single-precision FFT functions. ### Method Function Call ### Parameters #### Path Parameters - **__Log2n** (vDSP_Length) - Required - The base-two logarithm of the maximum number of elements the setup structure transforms. - **__Radix** (FFTRadix) - Required - Specifies radix options. This function only supports radix-2. ### Response #### Success Response - **FFTSetup** (structure) - Returns an FFTSetup structure for use with FFT functions. #### Error Response - **0** (integer) - Returns 0 on error. ``` -------------------------------- ### Allocate Aligned Memory for DFT Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zrop_createsetupd When using shared setup objects, input and output pointers must be 64-byte aligned. This example shows how to allocate correctly aligned memory for double-precision arrays. ```c double* reals = (double*)aligned_alloc(64, length*sizeof(double)); double* imaginaries = (double*)aligned_alloc(64, length*sizeof(double)); ``` -------------------------------- ### Capture and Restore Random Generator State Source: https://developer.apple.com/documentation/accelerate/bnnsrandomgeneratorgetstate%28_%3A_%3A_%3A%29 This example demonstrates how to capture the initial state of a random number generator using BNNSRandomGeneratorGetState, perform random number generation, and then restore the state using BNNSRandomGeneratorSetState. This ensures that subsequent random number generation will produce the same sequence as if it were started from the initial state. ```swift let data = UnsafeMutableBufferPointer.allocate(capacity: 8) var descriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0), layout: BNNSDataLayoutVector, size: (10, 0, 0, 0, 0, 0, 0, 0), stride: (0, 0, 0, 0, 0, 0, 0, 0), data: data.baseAddress!, data_type: BNNSDataType.int16, table_data: nil, table_data_type: BNNSDataType.int16, data_scale: 1, data_bias: 0) guard let randomNumberGenerator = BNNSCreateRandomGenerator(BNNSRandomGeneratorMethodAES_CTR, nil) else { return } // Allocate memory to store state. let stateSize = BNNSRandomGeneratorStateSize(randomNumberGenerator) let state = UnsafeMutableRawPointer.allocate(byteCount: stateSize, alignment: 0) // Store the random number generator's state. BNNSRandomGeneratorGetState(randomNumberGenerator, stateSize, state) BNNSRandomFillUniformInt(randomNumberGenerator, &descriptor, -10, 10) let a = Array(data) BNNSRandomFillUniformInt(randomNumberGenerator, &descriptor, -10, 10) let b = Array(data) // Set the random number generator's state to its initial state. BNNSRandomGeneratorSetState(randomNumberGenerator, stateSize, state) BNNSRandomFillUniformInt(randomNumberGenerator, &descriptor, -10, 10) let c = Array(data) print(a.elementsEqual(c)) // prints "true" data.deallocate() state.deallocate() BNNSDestroyRandomGenerator(randomNumberGenerator) ``` -------------------------------- ### Create a convolution layer with useClientPointer Source: https://developer.apple.com/documentation/accelerate/bnnsflags/useclientpointer Example demonstrating how to initialize a convolution layer using client-provided buffers for weights and bias. ```swift let weights: [Float] = [ ... ] let bias: [Float] = [ ... ] let convolutionLayer = weights.withUnsafeBufferPointer { weightsPtr -> BNNSFilter? in bias.withUnsafeMutableBufferPointer { biasPtr in let weightsDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0), layout: BNNSDataLayoutConvolutionWeightsOIHW, size: (3, 3, 1, 1, 0, 0, 0, 0), stride: (0, 0, 0, 0, 0, 0, 0, 0), data: UnsafeMutableRawPointer(mutating: weightsPtr.baseAddress!), data_type: .float, table_data: nil, table_data_type: .float, data_scale: 1, data_bias: 0) let biasDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0), layout: BNNSDataLayoutVector, size: (1, 0, 0, 1, 0, 0, 0, 0), stride: (0, 0, 0, 0, 0, 0, 0, 0), data: biasPtr.baseAddress, data_type: .float, table_data: nil, table_data_type: .float, data_scale: 1, data_bias: 0) var layerParameters = BNNSLayerParametersConvolution(i_desc: inDescriptor, w_desc: weightsDescriptor, o_desc: outDescriptor, bias: biasDescriptor, activation: .identity, x_stride: 1, y_stride: 1, x_dilation_stride: 0, y_dilation_stride: 0, x_padding: 0, y_padding: 0, groups: 1, pad: (0, 0, 0, 0)) var filterParameters = BNNSFilterParameters(flags: BNNSFlags.useClientPointer.rawValue, n_threads: 1, alloc_memory: nil, free_memory: nil) return BNNSFilterCreateLayerConvolution(&layerParameters, &filterParameters) } } ``` -------------------------------- ### Deallocate Single-Precision FFT Setup - Accelerate Source: https://developer.apple.com/documentation/accelerate/vdsp_destroy_fftsetup Frees existing setup data and releases any allocated memory for a single-precision FFT setup structure. Ensure the setup structure was previously created by `vDSP_create_fftsetup`. ```c extern void vDSP_destroy_fftsetup(FFTSetup __setup); ``` -------------------------------- ### Initializer: init(type:mem:apply:) Source: https://developer.apple.com/documentation/accelerate/sparseopaquepreconditioner_float/init%28type%3Amem%3Aapply%3A%29 Creates a new single-precision preconditioner. ```APIDOC ## init(type:mem:apply:) ### Description Creates a new single-precision preconditioner. ### Method Initializer ### Endpoint N/A (Initializer) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## Parameters `type` The preconditioner type. `mem` The unaltered memory pointer that passes as the first parameter of the `apply` function. `apply` A function that calculates _Y = PX_ , where _P_ is the preconditioner. ``` -------------------------------- ### Destroy FFT Setup Source: https://developer.apple.com/documentation/accelerate/vdsp_fouriertransformfunctions Frees the memory associated with an FFT setup object. Call this when the setup is no longer needed to prevent memory leaks. ```swift static func destroySetup(OpaquePointer) ``` -------------------------------- ### vDSP_DFT_zop_CreateSetup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_zop_createsetup Returns a setup structure that contains precalculated data for forward and inverse, complex, single-precision DFT functions. ```APIDOC ## vDSP_DFT_zop_CreateSetup ### Description Returns a setup structure that contains precalculated data for forward and inverse, complex, single-precision DFT functions. ### Method `vDSP_DFT_Setup vDSP_DFT_zop_CreateSetup(vDSP_DFT_Setup __Previous, vDSP_Length __Length, vDSP_DFT_Direction __Direction);` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters `__Previous` (vDSP_DFT_Setup) - An existing `vDSP_DFT_Setup` structure that shares memory with the returned setup structure. Pass `nil` to create an object with newly initialized and allocated memory. `__Length` (vDSP_Length) - The number of complex elements to process. The supported values are _f_ * 2**_n_ , where _f_ is 1, 3, 5, or 15 and _n_ is at least 3. `__Direction` (vDSP_DFT_Direction) - A flag that specifies the transform direction. Pass `vDSP_DFT_Direction.FORWARD` to transform from the time domain to the frequency domain. Pass `vDSP_DFT_Direction.INVERSE` to transform from the frequency domain to the time domain. ### Request Example None ### Response #### Success Response (200) `vDSP_DFT_Setup` - Returns a `vDSP_DFT_Setup` object. #### Response Example None ### Error Handling Returns `nil` if the function fails, either from insufficient memory or because `Length` doesn’t satisfy the requirements. ### Discussion Important: To prevent potential memory leaks, if the `Previous` parameter is not `nil`, the return value and the `Previous` value must be different variables. This function shares memory between data structures where possible. If you have an existing setup object, you should pass that object as `Previous`. By doing so, the returned setup object can share underlying data storage with that object. Note that this function may allocate memory; you can free any allocated memory by calling `vDSP_DFT_DestroySetup`. Using shared setup objects: If you’re using a shared setup object, the subsequent execute function requires that the input and output pointers are 64-byte aligned. The following code shows how to create the correctly aligned vectors: ``` -------------------------------- ### vDSP_DFT_Direction.INVERSE Case Example Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_direction/inverse Example of how the vDSP_DFT_Direction.INVERSE constant is declared. ```APIDOC ## Case Declaration ### Description Example Swift code showing the declaration of the `INVERSE` case within the `vDSP_DFT_Direction` enum. ### Method Enum Case ### Endpoint N/A ### Parameters N/A ### Request Example ```swift case INVERSE ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Destroy Single-Precision DFT Setup Source: https://developer.apple.com/documentation/accelerate/vdsp_dft_destroysetup Call this function to release the memory allocated for a single-precision DFT setup structure. It is safe to call this on setups that share data, as only unneeded memory is freed. ```c void vDSP_DFT_DestroySetup(vDSP_DFT_Setup __Setup); ``` -------------------------------- ### Tile a matrix using BNNSTile Source: https://developer.apple.com/documentation/accelerate/bnnstile%28_%3A_%3A_%3A%29 Example demonstrating how to tile a 2x3 matrix into a 6x6 matrix. ```Swift let values: [Float] = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] var inputDescriptor = BNNSNDArrayDescriptor.allocate( initializingFrom: values, shape: .matrixRowMajor(2, 3)) var outputDescriptor = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .matrixRowMajor(6, 6)) BNNSTile(&inputDescriptor, &outputDescriptor, nil) inputDescriptor.deallocate() outputDescriptor.deallocate() ``` -------------------------------- ### Destroy Biquad Setup Source: https://developer.apple.com/documentation/accelerate/vdsp_biquadfunctions/destroysetup%28channelcount%3Abiquadsetup%3A%29 Deallocates the memory used by a biquad filter setup. ```swift static func destroySetup( channelCount: UInt, biquadSetup: OpaquePointer ) ``` -------------------------------- ### destroySetup(_:) Source: https://developer.apple.com/documentation/accelerate/vdsp_splitcomplexdouble/destroysetup%28_%3A%29 Releases an FFT setup object. Available on iOS 13.0+, iPadOS 13.0+, macOS 10.15+, tvOS 13.0+, visionOS, and watchOS 6.0+. ```APIDOC ## destroySetup(_:) ### Description Releases an FFT setup object. ### Method `static func` ### Endpoint N/A (This is a method call, not a network endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift // Assuming 'setup' is an OpaquePointer representing an FFT setup destroySetup(setup) ``` ### Response #### Success Response (200) This method does not return a value. #### Response Example None ``` -------------------------------- ### init(_:) Source: https://developer.apple.com/documentation/accelerate/bnnsembeddingflags/init%28_%3A%29 Initializes a new BNNSEmbeddingFlags instance with a raw UInt32 value. ```APIDOC ## init(_:) ### Description Creates a new instance of BNNSEmbeddingFlags with the specified raw value. ### Parameters #### Parameters - **rawValue** (UInt32) - Required - The raw value used to initialize the BNNSEmbeddingFlags instance. ### Request Example ```swift let flags = BNNSEmbeddingFlags(rawValue: 1) ``` ```