added util fn for gradient generation