# Symmetric vs symmetric

**URL:** <https://discourse.julialang.org/t/symmetric-vs-symmetric/52743>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [January 2, 2021, 6:14pm UTC](https://discourse.julialang.org/t/symmetric-vs-symmetric/52743 "2021-01-02T18:14:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)\
**Post date:** [January 2, 2021, 6:14pm UTC](https://discourse.julialang.org/t/symmetric-vs-symmetric/52743/1 "2021-01-02T18:14:10Z")

</div>

At present we have the `Symmetric` type in `LinearAlgebra` which wraps an `AbstractMatrix`. This seems like a sensible strategy when dealing with dense `Matrix`s, and things like that. However, (to pick a single example) wrapping a `Diagonal` matrix in a `Symmetric` seems somewhat redundant and, at present, we don’t have functionality that says “give me a symmetric version of a matrix `x`, and do it in whatever way the author of the type of `x` deems best”.

Is there a particular reason that we _don’t_ have a function like this, that mirrors e.g. `permutedims` vs `PermutedDimsArray`? There appears to be a `symmetric` function in `LinearAlgebra`, but it’s not exported, so presumably it’s not intended for use in general.

n.b. I’ve assumed here that if one writes `Type(args...)` that you should always expect to in fact receive an output of type `Type`, so it would be incorrect for `Symmetric(x)` to return anything that isn’t a `Symmetric`.

edit: I’ve also assumed that array authors are free to implement `permutedims` in whatever way they deem most suitable for their and, in particular, that they needn’t return a `PermutedDimsArray` if they choose not to. If this assumption is incorrect, I would appreciate being told about it!

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [January 2, 2021, 6:25pm UTC](https://discourse.julialang.org/t/symmetric-vs-symmetric/52743/2 "2021-01-02T18:25:41Z")

</div>

Perhaps a better analogy is `transpose`, where `transpose(Diagonal(1:3))` doesn’t do anything.

I’m not sure `permutedims` ever returns a `PermutedDimsArray`, although that’s another similar question – why isn’t there lower-case counterpart to `PermutedDimsArray`, too? Which could, for instance, unwrap this wrapper and return an Array, without violating the `T(a) isa T` rule.

If this `symmetric` existed, what would `symmetric(reshape(1:9,3,3))` return? Would it symmetrise, or merely ignore the lower half like the `Symmetric` wrapper?

---

<div class="post-metadata">

**Author:** ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)\
**Post date:** [January 2, 2021, 6:51pm UTC](https://discourse.julialang.org/t/symmetric-vs-symmetric/52743/3 "2021-01-02T18:51:54Z")

</div>

🤦‍♂️ you’re completely correct about `permutedims` – I just assumed that was what it did haha. I agree that `transpose` is a better analogy.

> If this `symmetric` existed, what would `symmetric(reshape(1:9,3,3))` return? Would it symmetrise, or merely ignore the lower half like the `Symmetric` wrapper?

Unclear to me, but my first inclination would be to say that the `Symmetric` wrapper seems like a good choice here because you continue to defer instantiating anything, which seems like a desirable outcome but as I say. Maybe a good fallback implementation would be to return a `Symmetric`?

edit: I think you probably do want to stick with `Symmetric` the vast majority of the time, because knowing that a matrix is `Symmetric` based on the type is quite helpful information generally. I could certainly be persuaded that you would really only want to return something other than a `Symmetric` if the matrix type in question only admits symmetric matrices anyway, so wrapping it in a `Symmetric` tells you nothing new.

edit 2: `Diagonal` and `UniformScaling` seem like prime candidates for this in `LinearAlgebra` (`symmetric` could be made to work for `UniformScaling` where `Symmetric` fails), while things in `PDMats.jl` seem like good candidates in the wild.
