Matrix inversions with caching.