Re-writing Torch.inverse for mobile Conversion support

Hi Matt!

I won’t comment on the correctness of your code, but let me note:

You are applying recursion to the Laplace expansion (also called
the minor or cofactor expansion) to calculate your determinant.
This algorithm is elegant, but numerically impractical for all but the
smallest matrices. For an n x n matrix, its computational cost (in
time) scales as n! – worse than exponential.

(Without using that “one weird trick,” the computational cost of things
like matrix multiplication, matrix inversion, and calculating determinants
is n^3.)

There is much discussion in the numerical literature about inverting
matrices and calculating determinants (and linear algebra, in general).
You should be using some form of Gaussian elimination.

(Also, it’s more efficient – and in my mind more straightforward – to
invert a matrix directly using Gaussian elimination, rather than by
forming the adjoint (adjugate) matrix. Lastly, if you want to solve a
set of linear equations for a single “right hand side,” you’re also better
off just applying Gaussian elimination directly to the problem, rather
than computing the full inverse matrix.)

Best.

K. Frank