mat: Banded interfaces should require satisfying other matrix interfaces
Created by: btracey
For example any type that implements SymBanded
should also be required to implement Symmetric
, and similarly, any type that implements Diagonal
should also implement Symmetric
.
The argument for this is to allow the same flexibility that the Matrix
interface allows. Symmetric
matrices also implement Matrix
by requirement, which allows them to be used anywhere that accepts a Matrix
as an argument. As of right now, that flexibility is limited to Matrix
, it doesn't extend to the other (sub) types. This means, for example, you cannot use a Diagonal
as a Symmetric
, only DiagDense
.
An example of a useful algorithm is the following, pretending that mat.SymDense
has the method DiagView() Diagonal
(which is the natural design).
// ProductGaussian returns a product-distribution from the given Gaussian
// where all of the components are independent.
func ProductGaussian(norm *distmv.Normal) {
mu := norm.Mean(nil)
cov := norm.Covariance(nil)
n, _ := distmv.NewNormal(mu, cov.DiagView(), nil)
return n
}
This function would not compile, because Diagonal
does not implement Symmetric
, even though all Diagonal
matrices are symmetric. I don't think this requirement comes with significant cost, just a few extra methods for alternative implementations.