Can you do:
g_out.zeros_like()

this would make it work for sparse variable too.