Prevent moving "gpu_from_host" outside of scan

Detect if the inner replacement would have a different type,
so that a new gpu_from_host is not inserted in the inner graph
in replacement of the one that was just pushed out.
Same change in sequence optimization
Merge pull request #1383 from lamblin/fix_scan_gpu_loop

Fix scan gpu loop