return z directly:
return tensor.sum(x...)

everywhere too.