Update check for non-available gradient.
Add test case.
Merge pull request #1534 from lamblin/fix_disconnected_sum

Update check for non-available gradient.