BugFix: R->R should take real part of gradient even if outdtype is real.
Created by: PhilipVinc
Addresses a problem that arose in #420.
Also replaces my custom implementation of single dispatch for sum_inplace
with python's single dispatch
that I just discovered exists.