#include <torch/csrc/Layout.h>
#include <torch/csrc/Exceptions.h>
#include <torch/csrc/utils/object_ptr.h>
#include <torch/csrc/utils/python_strings.h>
#include <torch/csrc/utils/refcount_contention.h>
#include <cstring>
#include <string>
PyObject* THPLayout_New(at::Layout layout, const std::string& name) {
auto type = &THPLayoutType;
auto self = THPObjectPtr{type->tp_alloc(type, 0)};
TORCH_CHECK_PYTHON(self);
auto self_ = reinterpret_cast<THPLayout*>(self.get());
self_->layout = layout;
std::strncpy(self_->name, name.c_str(), LAYOUT_NAME_LEN);
self_->name[LAYOUT_NAME_LEN] = '\0';
torch::utils::set_immortal_if_possible(self.get());
return self.release();
}
static PyObject* THPLayout_repr(THPLayout* self) {
return THPUtils_packString(self->name);
}
PyTypeObject THPLayoutType = {
PyVarObject_HEAD_INIT(nullptr, 0)
"torch.layout",
sizeof(THPLayout),
0,
nullptr,
0,
nullptr,
nullptr,
nullptr,
reinterpret_cast<reprfunc>(THPLayout_repr),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
Py_TPFLAGS_DEFAULT,
nullptr,
nullptr,
nullptr,
nullptr,
0,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
0,
nullptr,
nullptr,
nullptr,
};
void THPLayout_init(PyObject* module) {
TORCH_CHECK_PYTHON(PyModule_AddType(module, &THPLayoutType) >= 0);
}