Note from glebm@:
Back-ported from e0d5e4b0ff
Identical except for the changes to `MatrixTemplate`, which does not
exist in 3.6
Note from glebm@:
Back-ported from e0d5e4b0ff
Identical except for the changes to `MatrixTemplate`, which does not
exist in 3.6