Add sparse matrix support for CachedFunction.