<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/SparseFactor(_:_:_:_:_:)-8afz",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@SparseFactor#$@SA@SparseOpaqueSymbolicFactorization#$@SA@SparseMatrix_Float#$@SA@SparseNumericFactorOptions#*v#S3_#"
  },
  "title" : "SparseFactor(_:_:_:_:_:)"
}
-->

# SparseFactor(_:_:_:_:_:)

Returns the factorization of a sparse matrix of single-precision values that corresponds to the supplied symbolic factorization using user-defined workspace and factor storage.

```
func SparseFactor(_ symbolicFactor: SparseOpaqueSymbolicFactorization, _ Matrix: SparseMatrix_Float, _ nfoptions: SparseNumericFactorOptions, _ factorStorage: UnsafeMutableRawPointer?, _ workspace: UnsafeMutableRawPointer?) -> SparseOpaqueFactorization_Float
```

## Return Value

A [`SparseOpaqueFactorization_Float`](/documentation/Accelerate/SparseOpaqueFactorization_Float) structure that represents the matrix factorization.

## Discussion

- symbolicFactor: A symbolic factorization that returns by calling [`SparseFactor(_:_:_:_:_:)`](/documentation/Accelerate/SparseFactor(_:_:_:_:_:)-8afz).
- Matrix: The matrix to factorize.
- nfoptions: The numeric factor options, such as pivoting parameters.
- factorStorage: A pointer to space for storing the factorization of size at least [`factorSize_Float`](/documentation/Accelerate/SparseOpaqueSymbolicFactorization/factorSize_Float) bytes. Don’t alter this storage during the lifetime of the return value.
- workspace: A pointer to a workspace of size at least [`workspaceSize_Float`](/documentation/Accelerate/SparseOpaqueSymbolicFactorization/workspaceSize_Float) bytes. You can reuse or deallocate the workspace storage after the function returns.

## Discussion

Use this function to solve a system of linear equations using a symbolic factorization that [`SparseFactor(_:_:)`](/documentation/Accelerate/SparseFactor(_:_:)-3697o) creates.

![A mathematical equation that has one set of three simultaneous equations on the left. Each equation has three unknowns. The same set of simultaneous equations appears on the right as a single matrix equation, A x equals B. The single matrix equation consists of a three-by-three matrix multiplied by a three-element column matrix that equals a three-element column matrix.](images/com.apple.accelerate/media-3703947@2x.png)

The following code creates the workspace and factor storage that this function requires, and solves this system with a QR factorization of the coefficient matrix:

```swift
/// Define the sparsity pattern of the coefficient matrix.
let rowIndices: [Int32] =    [ 0, 1, 1, 2]
let columnIndices: [Int32] = [ 2, 0, 2, 1]

/// Create the single-precision coefficient matrix _A_.
let aValues: [Float] = [10, 20, 5, 50]
let A = SparseConvertFromCoordinate(3, 3,
                                    4, 1,
                                    SparseAttributes_t(),
                                    rowIndices, columnIndices,
                                    aValues)

/// Compute the symbolic factorization from the structure of either the matrix.
let structure = A.structure
let symbolicFactorization = SparseFactor(SparseFactorizationQR,
                                         structure)

/// Create the workspace.
let workspace = UnsafeMutableRawPointer.allocate(
    byteCount: symbolicFactorization.workspaceSize_Float,
    alignment: MemoryLayout<Float>.alignment)
defer {
    workspace.deallocate()
}

/// Create the factor storage.
let factorStorage = UnsafeMutableRawPointer.allocate(
    byteCount: symbolicFactorization.factorSize_Float,
    alignment: MemoryLayout<Float>.alignment)
defer {
    factorStorage.deallocate()
}

/// Factorize _A_ using the symbolic factorization.
let factorization = SparseFactor(symbolicFactorization, A,
                                 SparseNumericFactorOptions(),
                                 factorStorage, workspace)

/// Solve _Ax = b_ in place.
var b0Values: [Float] = [30, 35, 100]
b0Values.withUnsafeMutableBufferPointer { bPtr in
    let xb = DenseVector_Float(count: 3,
                               data: bPtr.baseAddress!)
    
    SparseSolve(factorization, xb)
}

SparseCleanup(A)
SparseCleanup(factorization)
```

On return, `bValues` contains the values `[1.0, 2.0, 3.0].`

Note that internal memory allocations may occur in the case of pivoted factorizations that result in delayed pivots. If you require closer control over memory allocations, supply a [`malloc`](/documentation/Accelerate/SparseSymbolicFactorOptions/malloc) function that implements the required behavior, or use an alternative that nonpivoted factorization returns. Note that if [`malloc`](/documentation/Accelerate/SparseSymbolicFactorOptions/malloc) returns `NULL`, the factorization aborts immediately.

---

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)