# Sparse Cholesky of Gram Matrix (SuiteSparse?)

**URL:** https://discourse.julialang.org/t/sparse-cholesky-of-gram-matrix-suitesparse/37303
**Category:** Numerics
**Tags:** question, linearalgebra
**Created:** [April 9, 2020, 10:48pm UTC](https://discourse.julialang.org/t/sparse-cholesky-of-gram-matrix-suitesparse/37303 "2020-04-09T22:48:27Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [April 10, 2020, 12:48am UTC](https://discourse.julialang.org/t/sparse-cholesky-of-gram-matrix-suitesparse/37303/6 "2020-04-10T00:48:27Z")

</div>

In most circumstances, you should try to avoid computing the Gram matrix A^T A at all, as it squares the condition number of A. See also my [explanation in another thread on least-squares problems](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/33).

> I need a sparse factorization of A^T A which would be used in solving a system of the form (A^T A)^{-1}b for many possible vectors b.

Are you solving least-square problems? That is, are you actually solving (A^T A)^{-1} A^T b? In that case what you want is to use the A=QR factorization and solve R^{-1} (Q^\* b), which is equivalent but avoids squaring the condition number (or multiplying large matrices together). In fact, the QR factorization object in Julia will do this for you:

```julia
QR = qr(A) # QR factorization (sparse if A is sparse)
x = QR \ b # least-square solution

```

Is there some other reason why you want to factorize the Gram matrix?

---

_[View the full topic](https://discourse.julialang.org/t/sparse-cholesky-of-gram-matrix-suitesparse/37303)._
