This is not correct if out is a sparse variable.
What happens if the output has no shape (for instance, a RandomStateType)?