Inverse matrix calculation.

Implementation of the inverse matrix calculation and its cache
functionality.