check shapes of gradients
added input index to error message
Merge pull request #1443 from nouiz/goodfeli-master

Rebase gh-1368