My code for caching matrix assignment