An offline robot-estimation notebook may factor one matrix and reuse the result for several right-hand sides. Before treating that result as an ordinary dense matrix, inspect its storage contract. A factorization packet can contain meaningful entries in one triangle while the other triangle belongs to storage the solver does not use as the factor.

This distinction matters when a developer adds a reconstruction check, exports the packet, or replaces a factor-aware solver with a general matrix multiplication. The correct factor may be present even when multiplying the entire returned array by its transpose produces a different matrix. The original example below makes that discrepancy numerical and keeps the relevant SciPy options explicit.

Read the current option-specific contract

The SciPy 1.18.0 cho_factor documentation says that overwrite_a=False zeros the unused triangle, while enabling overwrite_a can leave other data there. Its lower flag identifies which triangle contains the factor [1]. Therefore, a blanket claim that every current default result contains nonfactor entries would be inaccurate. This article specifically exercises overwrite_a=True on an expendable input copy.

The companion cho_solve interface accepts the pair consisting of the factor array and that triangle flag, together with a right-hand side [2]. Keeping the pair intact is a clearer cache contract than storing a bare square array and relying on each later caller to remember its interpretation.

Construct an original positive-definite matrix

Choose the real lower-triangular matrix L with rows [3,0,0], [1,2,0], and [-1,1,2]. Define A=L@L.T. Its rows are [9,3,-3], [3,5,1], and [-3,1,6]. This construction provides a known reference factor and a symmetric positive-definite matrix for the experiment.

To see why the definiteness condition holds, take any nonzero real vector z. The quadratic form z.T@A@z equals the squared norm of L.T@z. Since L has nonzero diagonal entries, it is invertible, so that norm cannot vanish for nonzero z. This is a property of the constructed example, not a validation result for a measured covariance matrix.

Choose a known solution x=[2,-1,3]. Multiplying A by that vector gives b=[6,4,11]. The fixture can now check reconstruction against A and the solved result against x without taking either result on trust.

import numpy as np

from scipy.linalg import cho_factor, cho_solve

L = np.array([[3., 0., 0.],

[1., 2., 0.],

[-1., 1., 2.]])

A = L @ L.T

expected = np.array([2., -1., 3.])

b = A @ expected

working = np.array(A, order='F', copy=True)

c, lower = cho_factor(

working, lower=True, overwrite_a=True)

Keep A separate from working. Permitting overwrite means the working input should not be reused as an unchanged reference. The example does not depend on a universal guarantee that every dtype and memory layout will actually be overwritten in place.

Inspect the returned array without overgeneralizing

The local SciPy 1.18.1 run returned c with rows [3,3,-3], [1,2,1], and [-1,1,2], along with lower=True. The lower triangle reproduces L. The upper entries 3,-3,1 are present in this particular result but are not entries of the lower-triangular factor.

Using the entire array, c@c.T produced rows [27,6,-6], [6,6,3], and [-6,3,6]. Its largest absolute entrywise difference from A was 18. For example, the first diagonal entry sums 3 squared, 3 squared, and -3 squared, giving 27 instead of 9.

This failure does not show that the Cholesky decomposition was wrong. The multiplication included additional upper-triangle numbers that the lower-factor representation does not assign to L. Nor should a future test insist that those unused entries always equal the original input's upper triangle. Their particular observed values are evidence about this execution, not a portable data contract.

Reconstruct from the selected triangle

factor = np.tril(c)

np.testing.assert_allclose(factor @ factor.T, A)

solved = cho_solve((c, lower), b)

np.testing.assert_allclose(solved, expected)

np.testing.assert_allclose(A @ solved, b)

All three comparisons passed. The triangular reconstruction had zero maximum entrywise difference in the executed fixture, and the solved vector was [2,-1,3]. The run used SciPy 1.18.1, NumPy 2.5.2, and Python 3.14.7. The official pages consulted were labeled 1.18.0.

For an upper-triangular real factor U, the corresponding reconstruction uses U.T@U, rather than U@U.T. A complex-valued extension requires conjugate transpose as well. This article's executed matrices are real, so the displayed transpose operations are sufficient for the stated example.

Test what the solver actually uses

As a separate control, copy c and replace only its strict upper-triangle entries with the finite numbers 13,17,19. Keep the diagonal and lower triangle unchanged. Passing that altered array with lower=True to cho_solve returned the same solution in this fixture.

This control isolates the selected-triangle interpretation. It is not permission to put arbitrary invalid data in a factor packet: the test uses finite entries and leaves the normal finiteness check enabled. It also does not suggest that a triangle flag can be guessed from whichever half looks more plausible.

A second control used overwrite_a=False. As described by the current documentation, the returned array had zeros above its lower triangle, and multiplying that complete array by its transpose reconstructed A. This contrast explains why a reconstruction check can pass under one option and fail after a later change to an overwrite-enabled path.

Carry representation metadata through the cache

An inspection-friendly cache should identify the source matrix, its shape and dtype, the triangle flag, and the factorization options. If exporting a clean triangular matrix instead, label that representation explicitly and preserve the multiplication convention used to interpret it. Those records help distinguish a source-matrix change from a storage-format change.

Before reusing the factor for a new right-hand side, establish that it still belongs to the intended A. For this example, both reconstruction and the residual A@solved-b are available checks. They do not certify an estimator, a physical model, or the conditioning of an unrelated matrix.

The practical lesson is concrete: retain the factor array together with its triangle flag, and extract the selected triangle when a dense reconstruction is required. A square shape alone does not tell a later consumer which entries constitute the mathematical factor.

Sources

[1] SciPy, cho_factor: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.cho_factor.html

[2] SciPy, cho_solve: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.cho_solve.html