<!--
{
  "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/SparseRefactor(_:_:_:)-2dqt8",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@SparseRefactor#$@SA@SparseMatrix_Float#*$@SA@SparseOpaqueFactorization_Float#*v#"
  },
  "title" : "SparseRefactor(_:_:_:)"
}
-->

# SparseRefactor(_:_:_:)

Computes a factorization of the specified single-precision matrix using an existing factorization’s storage, without internal memory allocation.

```
func SparseRefactor(_ Matrix: SparseMatrix_Float, _ Factored: UnsafeMutablePointer<SparseOpaqueFactorization_Float>, _ workspace: UnsafeMutableRawPointer)
```

## Parameters

`Matrix`

The matrix that contains numerical data to recompute.

`Factored`

The factorization to recompute.

`workspace`

A pointer to a workspace of size at least `symbolicFactorization.workspaceSize_Float` bytes.

## Discussion

Use this function to calculate the factorization of a sparse matrix to pass to the direct solve functions using an existing factorization’s storage. The specified matrix must have the same sparsity structure as the matrix of the original factorization. In cases where your code calls the function frequently, create and manage the workspace that the Sparse Solvers library uses and reuse it across function calls. Reusing a workspace prevents the Sparse Solvers library from allocating the temporary storage with each call.

This function provides behavior similar to [`SparseFactor(_:_:_:_:_:)`](/documentation/Accelerate/SparseFactor(_:_:_:_:_:)-68hki) by reusing explicit storage that you supply to [`SparseFactor(_:_:_:_:_:)`](/documentation/Accelerate/SparseFactor(_:_:_:_:_:)-68hki) as the argument `factorStorage`. However, in addition to providing a simplified call sequence, this call can also reuse any additional storage that you allocate to accommodate delayed pivots.

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-3703907@2x.png)

The following code solves these two systems with refactoring. After factorizing and solving for the coefficient matrix *A0*, the code refactors and solves for matrix *A1*:

```objc
// Define the sparsity pattern of matrices `A0` and `A1`.
int rowIndices[]    = {0, 1, 1, 2};
int columnIndices[] = {2, 0, 2, 1};

// Create the single-precision coefficient matrix `A0` from coordinate (COO) arrays.
float a0Values[] = {10, 20, 5, 50};
SparseMatrix_Float A0 = SparseConvertFromCoordinate(3, 3,
                                                    4, 1,
                                                    (SparseAttributes_t){0},
                                                    rowIndices, columnIndices,
                                                    a0Values);

// Compute the factors of `A0`.
SparseOpaqueFactorization_Float factorization = SparseFactor(SparseFactorizationQR, A0);

// Solve `A0 · x = b0` in place.
float b0Values[] = {30, 35, 100};
DenseVector_Float xb0 = {
    .count = 3,
    .data  = b0Values
};
SparseSolve(factorization, xb0);

// Prints "[1, 2, 3]".
printf("[%g, %g, %g]\n", b0Values[0], b0Values[1], b0Values[2]);

// Create the single-precision coefficient matrix `A1` from coordinate (COO) arrays.
float a1Values[] = {5, 10, 2.5, 25};
SparseMatrix_Float A1 = SparseConvertFromCoordinate(3, 3,
                                                    4, 1,
                                                    (SparseAttributes_t){0},
                                                    rowIndices, columnIndices,
                                                    a1Values);

// Allocate the workspace.
long byteCount = factorization.symbolicFactorization.workspaceSize_Float;
void *workspace = malloc(byteCount);

// Refactor `A1` into the existing factorization.
SparseRefactor(A1, &factorization, workspace);

// Solve `A1 · x = b1` in place.
float b1Values[] = {60, 70, 200};
DenseVector_Float xb1 = {
    .count = 3,
    .data  = b1Values
};
SparseSolve(factorization, xb1);

// Prints "[4, 8, 12]".
printf("[%g, %g, %g]\n", b1Values[0], b1Values[1], b1Values[2]);

free(workspace);
SparseCleanup(A0);
SparseCleanup(A1);
SparseCleanup(factorization);
```

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

---

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)