I'd like to understand the cost that is being mitigated by this
proposal. The changes that are required would impose a significant
burden on maintainers* in both code mutation and in review because of
the broad impact of the change, and would have an impact on performance
in cases where the transpose can be elided and the matrix type is aware
of that since for code to be generically usable the matrix consumer
would have to assume that all matrix types need to be actively
transposed if any do for an algorithm. I'd argue (more subjectively)
that it will make mat code harder to read — this is a position that I
held previously and which hasn't changed over the 3 years since that
issue was discussed.
* This is at a point where there are fewer of us and those of us who
are here are less able to spend time on the project.
Also, it's worth pointing out that there is a fourth option that I
think (though haven't experimented to confirm) addresses the concerns
here without the legibility or potential performance costs (though
still with a maintainer burden and some, though less, user-breaking
costs). This is to implement the mat API on Go type-parameterised
methods so that mat.Matrix is something like
type Matrix[T any] interface {
At(i, j int) float64
Dims() (r, c int)
T() T
}
(possibly with a further type differentiation so that we have element
type specification, though this requires some additions to the language
to make it work in the general case see
https://go.dev/issue/45049)
type Float interface {
~float64 | ~float32
}
type Ater[E Float] interface {
At(i, j int) E
}
type Matrix[T Ater[E], E Float] interface {
At(i, j int) E
Dims() (r, c int)
T() T
}
I have not thought fully through the implications of this, and I feel
that there are likely to be some subtleties in how instantiated types
interact with each other in ways that are difficult (e.g. how does
T1.Mul(T2, T3) work). So some initial experimentation would be
required, but given that we can't make this generally available before
go1.19 is release and we drop go1.17, we have some time.
This all obviously still has a significant maintainer cost in the
changes required and the review of those changes, but brings the
advantages of a reduced API surface (T<Type> methods go away among
other things) and users no longer need to import mat (though I have to
say it's unclear to me why they would implement mat.Matrix and not
import that package in some way).
Dan