Similar Symmetric matrix / type stability

question
#1

hi! I have another short newbie question. Why does the wrapper Symmetric() disappears, when one creates an uninitialised Symmetric matrix using a function similar()? This happens if dimensions are changed, see the matrix b2.

a1=randn(3,3)
a1=Symmetric(a1+a1')
b1=similar(a1)
typeof(b1)


a2=randn(3,3)
a2=Symmetric(a2+a2')
b2=similar(a2,2,2)
typeof(b2)

Does that have an effect on type-stability?

e=randn(2,2)
e=Symmetric(e+e')
b2.=e

Thanks

0 Likes

#2

similar(a2, 2, 2) falls back to the generic method (you can see this with eg @edit similar(a2, 2, 2).

Type stability means that output types can be calculated from input types. This should hold, as similar(a2, 2, 2) and similar(a2) are different calls.

1 Like