Do not return None in scalar op's grad, add tests

This should solve gh-1512.