Fixed _out variants of linear algebra functions (#51560)
Summary:
This PR modifies the behavior of `_out` variants to match the description here https://github.com/pytorch/pytorch/wiki/Developer-FAQ#how-does-out-work-in-pytorch
With this PR result and input tensors must be on the same device and have the same "type kind".
I skipped `qr` and `eig` in this process as they require a bit more work.
Functions that can use the provided storage directly do so. If `result` is not empty and not in the batched column-major format or does not have the same type as input then we have to allocate a temporary tensor and copy it.
TODO:
- [x] Add more tests for same device and valid safe dtype
- [x] Move inv and solve changes to separate PRs https://github.com/pytorch/pytorch/pull/51968, https://github.com/pytorch/pytorch/pull/51977
Ref. https://github.com/pytorch/pytorch/issues/42666
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51560
Reviewed By: albanD
Differential Revision: D26400734
Pulled By: heitorschueroff
fbshipit-source-id: a6201ed7e919c1670c6ff3ef60217d1dbfb72e67