Files
pytorch/torch/csrc/jit/python/python_ir.h
Richard Barnes ed327876f5 [codemod] c10:optional -> std::optional (#126135)
Generated by running the following from PyTorch root:
```
find . -regex ".*\.\(cpp\|h\|cu\|hpp\|cc\|cxx\)$" | grep -v "build/" | xargs -n 50 -P 4 perl -pi -e 's/c10::optional/std::optional/'
```

`c10::optional` is just an alias for `std::optional`. This removes usages of that alias in preparation for eliminating it entirely.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/126135
Approved by: https://github.com/Skylion007, https://github.com/malfet, https://github.com/albanD, https://github.com/aaronenyeshi
2024-05-14 19:35:51 +00:00

51 lines
1.7 KiB
C++

#pragma once
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/utils/object_ptr.h>
namespace torch::jit {
void initPythonIRBindings(PyObject* module);
// execute a Python function, used for Ops we can't optimize but that we want to
// optimize around
struct ConcretePythonOp : public PythonOp {
static Symbol Kind;
ConcretePythonOp(Graph* graph) : PythonOp(graph, ::c10::prim::PythonOp) {}
ConcretePythonOp* init(
THPObjectPtr&& pyobj,
const std::string& cconv,
pyobj_list&& scalar_args) {
this->pyobj = std::move(pyobj);
this->scalar_args = std::move(scalar_args);
this->cconv = cconv;
return this;
}
// The Python object which contains the implementation of this function.
// This is either a class (non-legacy) or an object (legacy). See
// TraceInterpreterState for execution semantics.
THPObjectPtr pyobj;
// The calling convention for the Python function.
// 'c' -- constant argument
// 'd' -- dynamic argument
std::string cconv;
// Scalar arguments to the Python function. Not necessarily passed to
// the function in this order; see cconv for the correct order.
std::vector<THPObjectPtr> scalar_args;
std::string name() const override;
void cloneFrom(Node* other_) override;
Node* allocNewInstance(Graph* g) override {
return new ConcretePythonOp(g);
}
// recover the autograd.Function instance, if this PythonOp's function
// was originally SomeFunction.apply
// used in ONNX for discovering symbolics
std::optional<THPObjectPtr> autogradFunction() const override;
void writeScalars(std::ostream& out) const override;
void lint_python() const override;
};
} // namespace torch::jit