I’m defining a function
f(m) that operates on a big matrix
m that may be or not be symmetric. If it is symmetric, the algorithm can by optimized by only working on the upper triangle.
I know that the symmetry of
m can be checked with
issymmetric(m), but for big matrices this also has some cost, and in some cases I already know that
m is symmetric, because it has been created by another function
g that always produces symmetric matrices.
I guess that there must be something that I could do with types, in order to apply the efficient algorithm for symmetric matrices when suitable (without using
issymmetric), but I’m failing to find the correct solution.
I have tried with a special function
f(x::Symmetric) that implements the efficient algorithm, and calling
m=Symmetric(m) in the last line of the function
g that produces the symmetric matrix. But the conversion to
Symmetric also takes time, and performance can be even worse.
Now I was trying to create a subtype of
AbstractMatrix, ad hoc for the output of
g, which I cold use in the signature of
f instead of
Symmetric. But I don’t know how to declare such type.
https://docs.julialang.org/en/stable/manual/types/ tells how to define subtypes of scalars, composite types, etc., but not how to define a subtype of vectors, matrices, etc. Doing it as for scalars, with
abstract type, I get an error of invalid subtyping.