# Package for dealing with symmetric matrices efficiently

**URL:** https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413
**Category:** General Usage
**Tags:** matrices
**Created:** [July 2, 2025, 3:40pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413 "2025-07-02T15:40:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 2, 2025, 3:40pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/1 "2025-07-02T15:40:45Z")

</div>

The Julia Symmetric Matrix type stores the full matrix. I’m looking for a package that offers a way to store and to index into a symmetric matrix directly but only stores one triangle, but that is performant, operates as a matrix, and also allows me to change off-diagonal elements at will, e.g. setting X[2,3] = 4 is an acceptable operation.

What is my best bet here?

Background: storing Hessians for large-dimensional optimization problems.

Thanks!!

---

<div class="post-metadata">

### Author: ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)
#### Post date: [July 2, 2025, 3:51pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/2 "2025-07-02T15:51:32Z")

</div>

Google serves up StandardPacked.jl and RectangularFullPacked.jl. Note, as mentioned in the READMEs, that the memory savings come at the cost of some extra overhead and a slight loss of floating-point accuracy in many calculations.

---

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 2, 2025, 4:26pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/3 "2025-07-02T16:26:29Z")

</div>

Thanks a bunch @danielwe . I’ll have a look at these too. There’s a whole bunch of them, many dormant, now incompatible, or restrictive.

---

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 2, 2025, 9:03pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/4 "2025-07-02T21:03:16Z")

</div>

@danielwe Do you have a recommendation?

---

<div class="post-metadata">

### Author: ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)
#### Post date: [July 2, 2025, 10:00pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/5 "2025-07-02T22:00:07Z")

</div>

Nope, never used any of these.

---

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 2, 2025, 10:13pm UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/6 "2025-07-02T22:13:27Z")

</div>

Thanks. Guess I should have phrased my original question differently. I’m looking for which package to use out of the umpteen different ones that claim to do this.

---

<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: [July 3, 2025, 1:42am UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/7 "2025-07-03T01:42:53Z")

</div>

I think the conventional wisdom here is that the factor-of-two savings of a packed format aren’t usually worth the performance hit that this incurs. Is a factor of two in memory really the difference between solvable and unsolvable for you?

> [@Joris\_Pinkse](#):
>
> Background: storing Hessians for large-dimensional optimization problems.

Have you considered ways to avoid explicit storage of the whole n \times n Hessian? Note that you can compute Hessian–vector products _much_ more efficiently without storing the matrix — in fact, you can save a factor of roughly n by forward-over-reverse-mode computation of Hessian–vector products (see section 8.4.1 of our [matrix-calculus course notes](https://arxiv.org/abs/2501.14787))!

Given a fast Hessian–vector product, you can construct a low-rank approximation of the Hessian using e.g. [randomized sketching methods in LowRankApprox.jl](https://github.com/JuliaLinearAlgebra/LowRankApprox.jl). (And L-BFGS optimization algorithms estimate low-rank Hessian approximations by a different method.)

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 3, 2025, 5:43am UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/8 "2025-07-03T05:43:13Z")

</div>

In another direction, is it possible that your Hessian matrix is sparse?

---

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 4, 2025, 2:06am UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/9 "2025-07-04T02:06:56Z")

</div>

Thanks @stevengj . That’s helpful. No, it isn’t: waste not want not and all. 😉 In fact, storing is what I’ll do since I suspect that they are not large by your standards.

I’m aware of the LBFGS algorithms with low-rank Hessians. I’m using Newton with Trust Regions which appears to be better behaved for the type of problem I’m working on.

---

<div class="post-metadata">

### Author: ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)
#### Post date: [July 4, 2025, 2:07am UTC](https://discourse.julialang.org/t/package-for-dealing-with-symmetric-matrices-efficiently/130413/10 "2025-07-04T02:07:16Z")

</div>

No, but thanks.
