Revert "Revert "cache the inverse of the matrix""

This reverts commit 3439fea6514fcf6469722df3bdde9a86cbc12901.