Caffe2 - C++ API
A deep learning, cross platform ML framework
python_variable.h
1 #pragma once
2 
3 #include <torch/csrc/python_headers.h>
4 #include <memory>
5 #include <ATen/ATen.h>
6 
7 #include <torch/csrc/autograd/variable.h>
8 #include <torch/csrc/THP_export.h>
9 
10 // Python object that backs torch.autograd.Variable
11 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
12 struct THPVariable {
13  PyObject_HEAD
14  // Payload
16  // Hooks to be run on backwards pass (corresponds to Python attr
17  // '_backwards_hooks', set by 'register_hook')
18  PyObject* backward_hooks = nullptr;
19 };
20 
21 THP_API PyObject *THPVariableClass;
22 
23 bool THPVariable_initModule(PyObject *module);
24 THP_API PyObject * THPVariable_Wrap(torch::autograd::Variable var);
25 
26 inline bool THPVariable_Check(PyObject *obj)
27 {
28  return THPVariableClass && PyObject_IsInstance(obj, THPVariableClass);
29 }
30 
31 inline torch::autograd::Variable& THPVariable_Unpack(PyObject* obj) {
32  auto var = (THPVariable*)obj;
33  return var->cdata;
34 }
35 
36 inline at::Tensor& THPVariable_UnpackData(PyObject* obj) {
37  auto var = (THPVariable*)obj;
38  return var->cdata.data();
39 }
Variable A Variable augments a Tensor with the ability to interact in our autograd machinery...
Definition: variable.h:85