Implementation of cached matrix inverse.