MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / PackTensorTuple

Function PackTensorTuple

oneflow/api/python/autograd/autograd_function.cpp:62–70  ·  view source on GitHub ↗

Return single Tensor when TensorTuple's size is one, otherwise py::tuple

Source from the content-addressed store, hash-verified

60
61// Return single Tensor when TensorTuple's size is one, otherwise py::tuple
62py::object PackTensorTuple(const one::TensorTuple& tp) {
63 if (tp.size() == 1) {
64 return py::cast(tp.at(0));
65 } else {
66 py::tuple out = py::tuple(tp.size());
67 for (int i = 0; i < tp.size(); ++i) { out[i] = tp.at(i); }
68 return py::cast<py::object>(out);
69 }
70}
71
72// wrap PyFunction, unpack the inputs from TensorTuple and pack outputs to TensorTuple
73one::AutogradFunctionBase::FType PackPyFunctionToFType(const py::function& func) {

Callers 1

Calls 4

castFunction · 0.85
tupleClass · 0.85
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected