Attempts to downcast a matrix to its specific subclass, accepting both inner wrapped types and outer types. Requires the TOuter constructor to be passed in because reified generics don't support ctor calls. If the passed mat cannot be cast, instead copies the data manually into a newly allocated matrix of the correct type.
mat - The matrix we want to cast or copy-- can either be a Matrix or
the output of getBaseMatrix for a backend (inner wrapped type).
makeOuter - A function that takes in an inner type and produces the
outer matrix type that we are trying to cast or copy to
outerFac - The factory for the outer type we are trying to cast or