mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/62187 This file can take 3 minutes on its own to compile, and after python_functions.cpp is the second limiting factor for compile time of `libtorch_python` on a 32-core threadripper. This splits it into 3 files that take around 1 minute each to compile. Test Plan: Imported from OSS Reviewed By: H-Huang Differential Revision: D29962048 Pulled By: albanD fbshipit-source-id: 99016d75912bff483fe21b130cef43a6882f8c0e
26 lines
671 B
C++
26 lines
671 B
C++
#include <Python.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
namespace torch { namespace autograd {
|
|
|
|
extern PyObject* THPVariableFunctionsModule;
|
|
|
|
// Wrapper converts a raised TypeError into returning NotImplemented
|
|
// Used to implement binary arithmetic operators
|
|
template <PyObject* (*Func)(PyObject*, PyObject*, PyObject*)>
|
|
inline PyObject * TypeError_to_NotImplemented_(PyObject* self, PyObject* args, PyObject* kwargs) {
|
|
PyObject* ret = Func(self, args, kwargs);
|
|
if (!ret && PyErr_ExceptionMatches(PyExc_TypeError)) {
|
|
PyErr_Clear();
|
|
Py_INCREF(Py_NotImplemented);
|
|
ret = Py_NotImplemented;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void initTorchFunctions();
|
|
|
|
}} // namespace torch::autograd
|