cachematrix.R implementation