Most of the functions have been ported from Pytools, which contains helpers for implementing DSLs and scientific computing frameworks in general.