12 ref_.unsafeReleaseTensorImpl();
16 : ref_(
Tensor::unsafe_borrow_t{}, src) {
21 : ref_(
Tensor::unsafe_borrow_t{}, rhs.ref_) {}
24 std::swap(ref_, rhs.ref_);
29 return ref_.defined();
44 operator bool()
const {
56 static_assert(std::is_same<
decltype(hook(
Tensor())),
void>::value,
57 "Expected hook to return void");
58 return _register_hook([fn=std::forward<T>(hook)](
const TensorBase& grad_base) {
67 return _register_hook([fn=std::forward<T>(hook)](
const TensorBase& grad_base) {
#define TORCH_INTERNAL_ASSERT_DEBUG_ONLY(...)
Definition: Exception.h:534
~OptionalTensorRef()
Definition: Tensor.h:11
const Tensor & getTensorRef() const &
Definition: Tensor.h:32
bool has_value() const
Definition: Tensor.h:28
OptionalTensorRef(const OptionalTensorRef &rhs)
Definition: Tensor.h:20
OptionalTensorRef & operator=(OptionalTensorRef rhs)
Definition: Tensor.h:23
const Tensor * operator->() const &
Definition: Tensor.h:40
const Tensor & operator*() const &
Definition: Tensor.h:36
OptionalTensorRef()=default
OptionalTensorRef(const TensorBase &src)
Definition: Tensor.h:15
Definition: TensorBase.h:79
bool defined() const
Definition: TensorBase.h:198
Definition: TensorBody.h:90
hook_return_void_t< T > register_hook(T &&hook) const
Registers a backward hook.
std::enable_if_t< std::is_same< typename c10::invoke_result_t< T &, Tensor >, Tensor >::value, unsigned > hook_return_var_t
Definition: TensorBody.h:1391
std::enable_if_t< std::is_void< typename c10::invoke_result_t< T &, Tensor > >::value, unsigned > hook_return_void_t
Definition: TensorBody.h:1389
Definition: TensorBase.h:34