xref: /aosp_15_r20/external/pytorch/tools/autograd/templates/python_sparse_functions.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #define TORCH_ASSERT_ONLY_METHOD_OPERATORS
2 // ${generated_comment}
3 
4 #include "torch/csrc/Device.h"
5 #include "torch/csrc/DynamicTypes.h"
6 #include "torch/csrc/Exceptions.h"
7 #include "torch/csrc/autograd/python_sparse_functions.h"
8 #include "torch/csrc/autograd/python_variable.h"
9 #include "torch/csrc/autograd/utils/wrap_outputs.h"
10 #include "torch/csrc/autograd/utils/python_arg_parsing.h"
11 #include "torch/csrc/utils/pycfunction_helpers.h"
12 #include "torch/csrc/utils/python_arg_parser.h"
13 #include "torch/csrc/utils/structseq.h"
14 
15 #ifndef AT_PER_OPERATOR_HEADERS
16 #include <ATen/Functions.h>
17 #else
18 $ops_headers
19 #endif
20 
21 using at::Tensor;
22 using at::Scalar;
23 using at::ScalarType;
24 using at::MemoryFormat;
25 using at::Generator;
26 using at::IntArrayRef;
27 using at::TensorList;
28 
29 using namespace torch::autograd::utils;
30 
31 namespace torch::autograd {
32 
33 // generated forward declarations start here
34 
35 ${py_forwards}
36 
37 static PyMethodDef sparse_functions[] = {
38   ${py_method_defs}
39   {NULL}
40 };
41 
42 static PyObject* THPSparseVariableFunctionsModule = NULL;
43 
initSparseFunctions(PyObject * module)44 void initSparseFunctions(PyObject* module) {
45   static struct PyModuleDef def = {
46      PyModuleDef_HEAD_INIT,
47      "torch._C._sparse",
48      NULL,
49      -1,
50      sparse_functions
51   };
52   PyObject* sparse = PyModule_Create(&def);
53   THPSparseVariableFunctionsModule = sparse;
54   if (!sparse) {
55     throw python_error();
56   }
57   // steals a reference to sparse
58   if (PyModule_AddObject(module, "_sparse", sparse) != 0) {
59     throw python_error();
60   }
61 }
62 
63 // generated methods start here
64 
65 ${py_methods}
66 
67 } // namespace torch::autograd
68