expose return_types in Python (#66614)
Summary:
https://github.com/facebookresearch/functorch/issues/87
TODO:
* [x] Add comments
* [x] Add test
* [x] Fix XLA
<details>
<summary>Generated python_return_types.cpp</summary>
```cpp
#include <Python.h>
#include <vector>
#include <map>
#include <string>
#include "torch/csrc/autograd/python_return_types.h"
#include "torch/csrc/utils/structseq.h"
#include "torch/csrc/Exceptions.h"
namespace {
PyTypeObject* get__det_lu_based_helper_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"det", ""}, {"lu", ""}, {"pivs", ""}, {nullptr} };
static PyTypeObject _det_lu_based_helperNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types._det_lu_based_helper", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&_det_lu_based_helperNamedTuple, &desc);
_det_lu_based_helperNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &_det_lu_based_helperNamedTuple;
}
PyTypeObject* get__fake_quantize_per_tensor_affine_cachemask_tensor_qparams_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"output", ""}, {"mask", ""}, {nullptr} };
static PyTypeObject _fake_quantize_per_tensor_affine_cachemask_tensor_qparamsNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types._fake_quantize_per_tensor_affine_cachemask_tensor_qparams", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&_fake_quantize_per_tensor_affine_cachemask_tensor_qparamsNamedTuple, &desc);
_fake_quantize_per_tensor_affine_cachemask_tensor_qparamsNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &_fake_quantize_per_tensor_affine_cachemask_tensor_qparamsNamedTuple;
}
PyTypeObject* get__fused_moving_avg_obs_fq_helper_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"output", ""}, {"mask", ""}, {nullptr} };
static PyTypeObject _fused_moving_avg_obs_fq_helperNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types._fused_moving_avg_obs_fq_helper", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&_fused_moving_avg_obs_fq_helperNamedTuple, &desc);
_fused_moving_avg_obs_fq_helperNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &_fused_moving_avg_obs_fq_helperNamedTuple;
}
PyTypeObject* get__lu_with_info_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"LU", ""}, {"pivots", ""}, {"info", ""}, {nullptr} };
static PyTypeObject _lu_with_infoNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types._lu_with_info", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&_lu_with_infoNamedTuple, &desc);
_lu_with_infoNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &_lu_with_infoNamedTuple;
}
PyTypeObject* get__unpack_dual_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"primal", ""}, {"tangent", ""}, {nullptr} };
static PyTypeObject _unpack_dualNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types._unpack_dual", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&_unpack_dualNamedTuple, &desc);
_unpack_dualNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &_unpack_dualNamedTuple;
}
PyTypeObject* get_aminmax_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"min", ""}, {"max", ""}, {nullptr} };
static PyTypeObject aminmaxNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.aminmax", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&aminmaxNamedTuple, &desc);
aminmaxNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &aminmaxNamedTuple;
}
PyTypeObject* get_aminmax_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"min", ""}, {"max", ""}, {nullptr} };
static PyTypeObject aminmax_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.aminmax_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&aminmax_outNamedTuple1, &desc);
aminmax_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &aminmax_outNamedTuple1;
}
PyTypeObject* get_cummax_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject cummaxNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.cummax", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&cummaxNamedTuple, &desc);
cummaxNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &cummaxNamedTuple;
}
PyTypeObject* get_cummax_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject cummax_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.cummax_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&cummax_outNamedTuple1, &desc);
cummax_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &cummax_outNamedTuple1;
}
PyTypeObject* get_cummin_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject cumminNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.cummin", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&cumminNamedTuple, &desc);
cumminNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &cumminNamedTuple;
}
PyTypeObject* get_cummin_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject cummin_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.cummin_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&cummin_outNamedTuple1, &desc);
cummin_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &cummin_outNamedTuple1;
}
PyTypeObject* get_eig_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject eig_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.eig_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&eig_outNamedTuple, &desc);
eig_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &eig_outNamedTuple;
}
PyTypeObject* get_eig_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject eigNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.eig", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&eigNamedTuple1, &desc);
eigNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &eigNamedTuple1;
}
PyTypeObject* get_frexp_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"mantissa", ""}, {"exponent", ""}, {nullptr} };
static PyTypeObject frexpNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.frexp", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&frexpNamedTuple, &desc);
frexpNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &frexpNamedTuple;
}
PyTypeObject* get_frexp_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"mantissa", ""}, {"exponent", ""}, {nullptr} };
static PyTypeObject frexp_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.frexp_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&frexp_outNamedTuple1, &desc);
frexp_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &frexp_outNamedTuple1;
}
PyTypeObject* get_geqrf_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"a", ""}, {"tau", ""}, {nullptr} };
static PyTypeObject geqrf_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.geqrf_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&geqrf_outNamedTuple, &desc);
geqrf_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &geqrf_outNamedTuple;
}
PyTypeObject* get_geqrf_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"a", ""}, {"tau", ""}, {nullptr} };
static PyTypeObject geqrfNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.geqrf", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&geqrfNamedTuple1, &desc);
geqrfNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &geqrfNamedTuple1;
}
PyTypeObject* get_histogram_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"hist", ""}, {"bin_edges", ""}, {nullptr} };
static PyTypeObject histogram_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.histogram_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&histogram_outNamedTuple, &desc);
histogram_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &histogram_outNamedTuple;
}
PyTypeObject* get_histogram_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"hist", ""}, {"bin_edges", ""}, {nullptr} };
static PyTypeObject histogramNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.histogram", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&histogramNamedTuple1, &desc);
histogramNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &histogramNamedTuple1;
}
PyTypeObject* get_kthvalue_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject kthvalueNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.kthvalue", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&kthvalueNamedTuple, &desc);
kthvalueNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &kthvalueNamedTuple;
}
PyTypeObject* get_kthvalue_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject kthvalue_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.kthvalue_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&kthvalue_outNamedTuple1, &desc);
kthvalue_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &kthvalue_outNamedTuple1;
}
PyTypeObject* get_linalg_cholesky_ex_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"L", ""}, {"info", ""}, {nullptr} };
static PyTypeObject linalg_cholesky_exNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_cholesky_ex", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_cholesky_exNamedTuple, &desc);
linalg_cholesky_exNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_cholesky_exNamedTuple;
}
PyTypeObject* get_linalg_cholesky_ex_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"L", ""}, {"info", ""}, {nullptr} };
static PyTypeObject linalg_cholesky_ex_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_cholesky_ex_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_cholesky_ex_outNamedTuple1, &desc);
linalg_cholesky_ex_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_cholesky_ex_outNamedTuple1;
}
PyTypeObject* get_linalg_eig_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject linalg_eigNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_eig", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_eigNamedTuple, &desc);
linalg_eigNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_eigNamedTuple;
}
PyTypeObject* get_linalg_eig_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject linalg_eig_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_eig_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_eig_outNamedTuple1, &desc);
linalg_eig_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_eig_outNamedTuple1;
}
PyTypeObject* get_linalg_eigh_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject linalg_eighNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_eigh", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_eighNamedTuple, &desc);
linalg_eighNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_eighNamedTuple;
}
PyTypeObject* get_linalg_eigh_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject linalg_eigh_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_eigh_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_eigh_outNamedTuple1, &desc);
linalg_eigh_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_eigh_outNamedTuple1;
}
PyTypeObject* get_linalg_inv_ex_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"inverse", ""}, {"info", ""}, {nullptr} };
static PyTypeObject linalg_inv_exNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_inv_ex", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_inv_exNamedTuple, &desc);
linalg_inv_exNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_inv_exNamedTuple;
}
PyTypeObject* get_linalg_inv_ex_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"inverse", ""}, {"info", ""}, {nullptr} };
static PyTypeObject linalg_inv_ex_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_inv_ex_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_inv_ex_outNamedTuple1, &desc);
linalg_inv_ex_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_inv_ex_outNamedTuple1;
}
PyTypeObject* get_linalg_lstsq_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"residuals", ""}, {"rank", ""}, {"singular_values", ""}, {nullptr} };
static PyTypeObject linalg_lstsqNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_lstsq", nullptr, NamedTuple_fields, 4 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_lstsqNamedTuple, &desc);
linalg_lstsqNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_lstsqNamedTuple;
}
PyTypeObject* get_linalg_lstsq_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"residuals", ""}, {"rank", ""}, {"singular_values", ""}, {nullptr} };
static PyTypeObject linalg_lstsq_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_lstsq_out", nullptr, NamedTuple_fields, 4 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_lstsq_outNamedTuple1, &desc);
linalg_lstsq_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_lstsq_outNamedTuple1;
}
PyTypeObject* get_linalg_qr_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"Q", ""}, {"R", ""}, {nullptr} };
static PyTypeObject linalg_qrNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_qr", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_qrNamedTuple, &desc);
linalg_qrNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_qrNamedTuple;
}
PyTypeObject* get_linalg_qr_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"Q", ""}, {"R", ""}, {nullptr} };
static PyTypeObject linalg_qr_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_qr_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_qr_outNamedTuple1, &desc);
linalg_qr_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_qr_outNamedTuple1;
}
PyTypeObject* get_linalg_slogdet_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"sign", ""}, {"logabsdet", ""}, {nullptr} };
static PyTypeObject linalg_slogdetNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_slogdet", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_slogdetNamedTuple, &desc);
linalg_slogdetNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_slogdetNamedTuple;
}
PyTypeObject* get_linalg_slogdet_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"sign", ""}, {"logabsdet", ""}, {nullptr} };
static PyTypeObject linalg_slogdet_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_slogdet_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_slogdet_outNamedTuple1, &desc);
linalg_slogdet_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_slogdet_outNamedTuple1;
}
PyTypeObject* get_linalg_svd_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"U", ""}, {"S", ""}, {"Vh", ""}, {nullptr} };
static PyTypeObject linalg_svd_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_svd_out", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_svd_outNamedTuple, &desc);
linalg_svd_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_svd_outNamedTuple;
}
PyTypeObject* get_linalg_svd_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"U", ""}, {"S", ""}, {"Vh", ""}, {nullptr} };
static PyTypeObject linalg_svdNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.linalg_svd", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&linalg_svdNamedTuple1, &desc);
linalg_svdNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &linalg_svdNamedTuple1;
}
PyTypeObject* get_lstsq_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"QR", ""}, {nullptr} };
static PyTypeObject lstsq_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.lstsq_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&lstsq_outNamedTuple, &desc);
lstsq_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &lstsq_outNamedTuple;
}
PyTypeObject* get_lstsq_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"QR", ""}, {nullptr} };
static PyTypeObject lstsqNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.lstsq", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&lstsqNamedTuple1, &desc);
lstsqNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &lstsqNamedTuple1;
}
PyTypeObject* get_lu_unpack_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"P", ""}, {"L", ""}, {"U", ""}, {nullptr} };
static PyTypeObject lu_unpackNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.lu_unpack", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&lu_unpackNamedTuple, &desc);
lu_unpackNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &lu_unpackNamedTuple;
}
PyTypeObject* get_lu_unpack_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"P", ""}, {"L", ""}, {"U", ""}, {nullptr} };
static PyTypeObject lu_unpack_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.lu_unpack_out", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&lu_unpack_outNamedTuple1, &desc);
lu_unpack_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &lu_unpack_outNamedTuple1;
}
PyTypeObject* get_max_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject maxNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.max", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&maxNamedTuple, &desc);
maxNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &maxNamedTuple;
}
PyTypeObject* get_max_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject max_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.max_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&max_outNamedTuple1, &desc);
max_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &max_outNamedTuple1;
}
PyTypeObject* get_median_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject medianNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.median", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&medianNamedTuple, &desc);
medianNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &medianNamedTuple;
}
PyTypeObject* get_median_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject median_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.median_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&median_outNamedTuple1, &desc);
median_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &median_outNamedTuple1;
}
PyTypeObject* get_min_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject minNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.min", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&minNamedTuple, &desc);
minNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &minNamedTuple;
}
PyTypeObject* get_min_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject min_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.min_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&min_outNamedTuple1, &desc);
min_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &min_outNamedTuple1;
}
PyTypeObject* get_mode_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject modeNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.mode", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&modeNamedTuple, &desc);
modeNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &modeNamedTuple;
}
PyTypeObject* get_mode_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject mode_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.mode_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&mode_outNamedTuple1, &desc);
mode_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &mode_outNamedTuple1;
}
PyTypeObject* get_nanmedian_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject nanmedianNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.nanmedian", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&nanmedianNamedTuple, &desc);
nanmedianNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &nanmedianNamedTuple;
}
PyTypeObject* get_nanmedian_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject nanmedian_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.nanmedian_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&nanmedian_outNamedTuple1, &desc);
nanmedian_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &nanmedian_outNamedTuple1;
}
PyTypeObject* get_qr_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"Q", ""}, {"R", ""}, {nullptr} };
static PyTypeObject qr_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.qr_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&qr_outNamedTuple, &desc);
qr_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &qr_outNamedTuple;
}
PyTypeObject* get_qr_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"Q", ""}, {"R", ""}, {nullptr} };
static PyTypeObject qrNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.qr", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&qrNamedTuple1, &desc);
qrNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &qrNamedTuple1;
}
PyTypeObject* get_slogdet_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"sign", ""}, {"logabsdet", ""}, {nullptr} };
static PyTypeObject slogdetNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.slogdet", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&slogdetNamedTuple, &desc);
slogdetNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &slogdetNamedTuple;
}
PyTypeObject* get_solve_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"LU", ""}, {nullptr} };
static PyTypeObject solveNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.solve", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&solveNamedTuple, &desc);
solveNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &solveNamedTuple;
}
PyTypeObject* get_solve_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"LU", ""}, {nullptr} };
static PyTypeObject solve_outNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.solve_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&solve_outNamedTuple1, &desc);
solve_outNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &solve_outNamedTuple1;
}
PyTypeObject* get_sort_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject sort_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.sort_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&sort_outNamedTuple, &desc);
sort_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &sort_outNamedTuple;
}
PyTypeObject* get_sort_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject sortNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.sort", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&sortNamedTuple1, &desc);
sortNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &sortNamedTuple1;
}
PyTypeObject* get_svd_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"U", ""}, {"S", ""}, {"V", ""}, {nullptr} };
static PyTypeObject svd_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.svd_out", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&svd_outNamedTuple, &desc);
svd_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &svd_outNamedTuple;
}
PyTypeObject* get_svd_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"U", ""}, {"S", ""}, {"V", ""}, {nullptr} };
static PyTypeObject svdNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.svd", nullptr, NamedTuple_fields, 3 };
if (!is_initialized) {
PyStructSequence_InitType(&svdNamedTuple1, &desc);
svdNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &svdNamedTuple1;
}
PyTypeObject* get_symeig_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject symeig_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.symeig_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&symeig_outNamedTuple, &desc);
symeig_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &symeig_outNamedTuple;
}
PyTypeObject* get_symeig_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"eigenvalues", ""}, {"eigenvectors", ""}, {nullptr} };
static PyTypeObject symeigNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.symeig", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&symeigNamedTuple1, &desc);
symeigNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &symeigNamedTuple1;
}
PyTypeObject* get_topk_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject topk_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.topk_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&topk_outNamedTuple, &desc);
topk_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &topk_outNamedTuple;
}
PyTypeObject* get_topk_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"values", ""}, {"indices", ""}, {nullptr} };
static PyTypeObject topkNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.topk", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&topkNamedTuple1, &desc);
topkNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &topkNamedTuple1;
}
PyTypeObject* get_triangular_solve_out_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"cloned_coefficient", ""}, {nullptr} };
static PyTypeObject triangular_solve_outNamedTuple;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.triangular_solve_out", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&triangular_solve_outNamedTuple, &desc);
triangular_solve_outNamedTuple.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &triangular_solve_outNamedTuple;
}
PyTypeObject* get_triangular_solve_namedtuple() {
static PyStructSequence_Field NamedTuple_fields[] = { {"solution", ""}, {"cloned_coefficient", ""}, {nullptr} };
static PyTypeObject triangular_solveNamedTuple1;
static bool is_initialized = false;
static PyStructSequence_Desc desc = { "torch.return_types.triangular_solve", nullptr, NamedTuple_fields, 2 };
if (!is_initialized) {
PyStructSequence_InitType(&triangular_solveNamedTuple1, &desc);
triangular_solveNamedTuple1.tp_repr = (reprfunc)torch::utils::returned_structseq_repr;
is_initialized = true;
}
return &triangular_solveNamedTuple1;
}
}
namespace torch {
namespace autograd {
std::map<std::string, PyTypeObject*>& get_namedtuple_types_map() {
// [NOTE] Non-global map
// This map calls Python functions during its initialization.
// If it is a global static variable and in case it is loaded
// before Python interpreter is ready, then the calls it makes during
// initialization will SEGFAULT.
// To avoid this we make it function static variable so that it is
// initialized only after the Python interpreter is ready.
static std::map<std::string, PyTypeObject*> namedtuple_types_map = {
{"_det_lu_based_helper", get__det_lu_based_helper_namedtuple()},
{"_fake_quantize_per_tensor_affine_cachemask_tensor_qparams", get__fake_quantize_per_tensor_affine_cachemask_tensor_qparams_namedtuple()},
{"_fused_moving_avg_obs_fq_helper", get__fused_moving_avg_obs_fq_helper_namedtuple()},
{"_lu_with_info", get__lu_with_info_namedtuple()},
{"_unpack_dual", get__unpack_dual_namedtuple()},
{"aminmax", get_aminmax_namedtuple()},
{"aminmax_out", get_aminmax_out_namedtuple()},
{"cummax", get_cummax_namedtuple()},
{"cummax_out", get_cummax_out_namedtuple()},
{"cummin", get_cummin_namedtuple()},
{"cummin_out", get_cummin_out_namedtuple()},
{"eig_out", get_eig_out_namedtuple()},
{"eig", get_eig_namedtuple()},
{"frexp", get_frexp_namedtuple()},
{"frexp_out", get_frexp_out_namedtuple()},
{"geqrf_out", get_geqrf_out_namedtuple()},
{"geqrf", get_geqrf_namedtuple()},
{"histogram_out", get_histogram_out_namedtuple()},
{"histogram", get_histogram_namedtuple()},
{"kthvalue", get_kthvalue_namedtuple()},
{"kthvalue_out", get_kthvalue_out_namedtuple()},
{"linalg_cholesky_ex", get_linalg_cholesky_ex_namedtuple()},
{"linalg_cholesky_ex_out", get_linalg_cholesky_ex_out_namedtuple()},
{"linalg_eig", get_linalg_eig_namedtuple()},
{"linalg_eig_out", get_linalg_eig_out_namedtuple()},
{"linalg_eigh", get_linalg_eigh_namedtuple()},
{"linalg_eigh_out", get_linalg_eigh_out_namedtuple()},
{"linalg_inv_ex", get_linalg_inv_ex_namedtuple()},
{"linalg_inv_ex_out", get_linalg_inv_ex_out_namedtuple()},
{"linalg_lstsq", get_linalg_lstsq_namedtuple()},
{"linalg_lstsq_out", get_linalg_lstsq_out_namedtuple()},
{"linalg_qr", get_linalg_qr_namedtuple()},
{"linalg_qr_out", get_linalg_qr_out_namedtuple()},
{"linalg_slogdet", get_linalg_slogdet_namedtuple()},
{"linalg_slogdet_out", get_linalg_slogdet_out_namedtuple()},
{"linalg_svd_out", get_linalg_svd_out_namedtuple()},
{"linalg_svd", get_linalg_svd_namedtuple()},
{"lstsq_out", get_lstsq_out_namedtuple()},
{"lstsq", get_lstsq_namedtuple()},
{"lu_unpack", get_lu_unpack_namedtuple()},
{"lu_unpack_out", get_lu_unpack_out_namedtuple()},
{"max", get_max_namedtuple()},
{"max_out", get_max_out_namedtuple()},
{"median", get_median_namedtuple()},
{"median_out", get_median_out_namedtuple()},
{"min", get_min_namedtuple()},
{"min_out", get_min_out_namedtuple()},
{"mode", get_mode_namedtuple()},
{"mode_out", get_mode_out_namedtuple()},
{"nanmedian", get_nanmedian_namedtuple()},
{"nanmedian_out", get_nanmedian_out_namedtuple()},
{"qr_out", get_qr_out_namedtuple()},
{"qr", get_qr_namedtuple()},
{"slogdet", get_slogdet_namedtuple()},
{"solve", get_solve_namedtuple()},
{"solve_out", get_solve_out_namedtuple()},
{"sort_out", get_sort_out_namedtuple()},
{"sort", get_sort_namedtuple()},
{"svd_out", get_svd_out_namedtuple()},
{"svd", get_svd_namedtuple()},
{"symeig_out", get_symeig_out_namedtuple()},
{"symeig", get_symeig_namedtuple()},
{"topk_out", get_topk_out_namedtuple()},
{"topk", get_topk_namedtuple()},
{"triangular_solve_out", get_triangular_solve_out_namedtuple()},
{"triangular_solve", get_triangular_solve_namedtuple()},
};
return namedtuple_types_map;
}
PyTypeObject* get_namedtuple(std::string name) {
static auto& namedtuple_types_map = get_namedtuple_types_map();
return namedtuple_types_map[name];
}
void initReturnTypes(PyObject* module) {
static struct PyModuleDef def = {
PyModuleDef_HEAD_INIT, "torch._C._return_types", nullptr, -1, {}};
PyObject* return_types_module = PyModule_Create(&def);
if (!return_types_module) {
throw python_error();
}
for (const auto& return_type_pair : get_namedtuple_types_map()) {
// hold onto the TypeObject for the unlikely case of user
// deleting or overriding it.
Py_INCREF(return_type_pair.second);
if (PyModule_AddObject(
return_types_module,
return_type_pair.first.c_str(),
(PyObject*)return_type_pair.second) != 0) {
Py_DECREF((PyObject*)return_type_pair.second);
throw python_error();
}
}
// steals a reference to return_types on success
if (PyModule_AddObject(module, "_return_types", return_types_module) != 0) {
Py_DECREF(return_types_module);
throw python_error();
}
}
} // namespace autograd
} // namespace torch
```
</details>
<details>
<summary>Eg. updated call in other python_*_functions</summary>
```cpp
// linalg_cholesky_ex
static PyObject * THPVariable_linalg_cholesky_ex(PyObject* self_, PyObject* args, PyObject* kwargs)
{
HANDLE_TH_ERRORS
static PyTypeObject* NamedTuple = get_namedtuple("linalg_cholesky_ex");
static PyTypeObject* NamedTuple1 = get_namedtuple("linalg_cholesky_ex_out");
static PythonArgParser parser({
"linalg_cholesky_ex(Tensor input, *, bool upper=False, bool check_errors=False, TensorList[2] out=None)",
}, /*traceable=*/true);
ParsedArgs<4> parsed_args;
auto _r = parser.parse(nullptr, args, kwargs, parsed_args);
if(_r.has_torch_function()) {
return handle_torch_function(_r, nullptr, args, kwargs, THPLinalgVariableFunctionsModule, "torch.linalg");
}
if (_r.isNone(3)) {
// aten::linalg_cholesky_ex(Tensor self, *, bool upper=False, bool check_errors=False) -> (Tensor L, Tensor info)
auto dispatch_linalg_cholesky_ex = [](const at::Tensor & self, bool upper, bool check_errors) -> ::std::tuple<at::Tensor,at::Tensor> {
pybind11::gil_scoped_release no_gil;
return at::linalg_cholesky_ex(self, upper, check_errors);
};
return wrap(NamedTuple, dispatch_linalg_cholesky_ex(_r.tensor(0), _r.toBool(1), _r.toBool(2)));
} else {
// aten::linalg_cholesky_ex.L(Tensor self, *, bool upper=False, bool check_errors=False, Tensor(a!) L, Tensor(b!) info) -> (Tensor(a!) L, Tensor(b!) info)
auto out = _r.tensorlist_n<2>(3);
auto dispatch_linalg_cholesky_ex_out = [](at::Tensor & L, at::Tensor & info, const at::Tensor & self, bool upper, bool check_errors) -> ::std::tuple<at::Tensor,at::Tensor> {
pybind11::gil_scoped_release no_gil;
return at::linalg_cholesky_ex_out(L, info, self, upper, check_errors);
};
return wrap(NamedTuple1, dispatch_linalg_cholesky_ex_out(out[0], out[1], _r.tensor(0), _r.toBool(1), _r.toBool(2)));
}
Py_RETURN_NONE;
END_HANDLE_TH_ERRORS
}
```
</details>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66614
Reviewed By: H-Huang
Differential Revision: D32741134
Pulled By: zou3519
fbshipit-source-id: 27bada30d20e66333ca1be1775608d9f0cbf9f59