sum dim using meta-programming