The implementation of `Matrix` and its `rrule` share quite a bit of code. We should consider how to factor some of it out into a shared implementation.