Use safe_new(x) instead of x.type() in scan grad.

This copies the test_value, making possible to use a test value
for sequences. Add test.
Merge pull request #1310 from lamblin/fix_scan_grad_testval

Use safe_new(x) instead of x.type() in scan grad.