Compiling NHP templates to basic operation arrays