1 #include "python_nn_functions.h" 5 #include "torch/csrc/Device.h" 6 #include "torch/csrc/DynamicTypes.h" 7 #include "torch/csrc/Exceptions.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/python_arg_parser.h" 12 #include "torch/csrc/utils/structseq.h" 14 #include "python_nn_functions_dispatch.h" 20 namespace torch {
namespace autograd {
22 static PyObject * THPVariable__parse_to(PyObject* module, PyObject* args, PyObject* kwargs)
25 auto parsed = parse_to_conversion(args, kwargs,
false);
26 auto& device = std::get<0>(parsed);
27 auto& scalarType = std::get<1>(parsed);
28 auto non_blocking = std::get<2>(parsed);
32 PyTuple_SET_ITEM(tuple.get(), 0, THPDevice_New(*device));
35 PyTuple_SET_ITEM(tuple.get(), 0, Py_None);
38 PyTuple_SET_ITEM(tuple.get(), 1, torch::autograd::utils::wrap(torch::getDtype(*scalarType)));
41 PyTuple_SET_ITEM(tuple.get(), 1, Py_None);
43 PyTuple_SET_ITEM(tuple.get(), 2, torch::autograd::utils::wrap(non_blocking));
44 return tuple.release();
50 static PyMethodDef nn_functions[] = {
51 {
"_parse_to", (PyCFunction)THPVariable__parse_to, METH_VARARGS | METH_KEYWORDS,
nullptr},
56 void initNNFunctions(PyObject* module) {
57 #if PY_MAJOR_VERSION == 2 58 PyObject* nn = Py_InitModule(
"torch._C._nn", nn_functions);
61 static struct PyModuleDef def = {
62 PyModuleDef_HEAD_INIT,
68 PyObject* nn = PyModule_Create(&def);
74 if (PyModule_AddObject(module,
"_nn", nn) != 0) {
Scalar represents a 0-dimensional tensor which contains a single element.