Most of the functions have been ported from Pytools, which contains a good set of helpers that help implementing DSLs and scientific computing frameworks in general.