<!--
{
  "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(_:_:_:)-797fl",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@SparseFactor#$@SA@SparseOpaqueSymbolicFactorization#$@SA@SparseMatrix_Float#$@SA@SparseNumericFactorOptions#"
  },
  "title" : "SparseFactor(_:_:_:)"
}
-->

# SparseFactor(_:_:_:)

Returns the factorization of a sparse matrix of single-precision values that corresponds to the supplied symbolic factorization using specified options.

```
func SparseFactor(_ SymbolicFactor: SparseOpaqueSymbolicFactorization, _ Matrix: SparseMatrix_Float, _ nfoptions: SparseNumericFactorOptions) -> SparseOpaqueFactorization_Float
```

## Parameters

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

## Return Value

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

## Discussion

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

The following figure shows two systems of equations where the coefficient matrix is sparse:

![A mathematical equation that has two stacked sets of three simultaneous equations on the left. Each equation has three unknowns. The same sets of simultaneous equations appear on the right as two matrix equations, A x equals B. Each 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-3703903@2x.png)

The following code solves these two systems by calling [`SparseFactor(_:_:)`](/documentation/Accelerate/SparseFactor(_:_:)-58oq8) and [`SparseFactor(_:_:)`](/documentation/Accelerate/SparseFactor(_:_:)-1p6im):

```swift
/// Define the sparsity pattern of matrices `A0` and `A1`.
let rowIndices: [Int32] =    [ 0, 1, 1, 2]
let columnIndices: [Int32] = [ 2, 0, 2, 1]

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

/// Create the double-precision coefficient matrix _A1_.
let a1Values: [Double] = [5, 10, 2.5, 25]
let A1 = SparseConvertFromCoordinate(3, 3,
                                     4, 1,
                                     SparseAttributes_t(),
                                     rowIndices, columnIndices,
                                     a1Values)

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

/// Factorize _A0_ using the symbolic factorization.
let factorization0 = SparseFactor(symbolicFactorization, A0)

/// Solve _A0 · x = b0_ in place.
var b0Values: [Float] = [30, 35, 100]
b0Values.withUnsafeMutableBufferPointer { bPtr in
    let xb = DenseVector_Float(count: 3,
                               data: bPtr.baseAddress!)
    
    SparseSolve(factorization0, xb)
}

/// Factorize _A1_ using the symbolic factorization.
let factorization1 = SparseFactor(symbolicFactorization, A1)

/// Solve _A1 · x = b1_ in place.
var b1Values: [Double] = [60, 70, 200]
b1Values.withUnsafeMutableBufferPointer { bPtr in
    let xb = DenseVector_Double(count: 3,
                               data: bPtr.baseAddress!)
    
    SparseSolve(factorization1, xb)
}

SparseCleanup(A0)
SparseCleanup(A1)
SparseCleanup(factorization0)
SparseCleanup(factorization1)
```

On return, `b0Values` contains the values `[1.0, 2.0, 3.0]`, and `b1Values` contains the values `[4.0, 8.0, 12.0]`.

## See Also

[`func SparseFactor(SparseFactorization_t, SparseMatrixStructure) -> SparseOpaqueSymbolicFactorization`](/documentation/Accelerate/SparseFactor(_:_:)-3697o)

Returns a symbolic factorization of the requested type for a specified sparsity structure.



---

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)