Skip to content

Commit a4daa89

Browse files
angelayipytorchmergebot
authored andcommitted
Serialize memory_format (pytorch#81332)
Pull Request resolved: pytorch#81332 Approved by: https://github.com/qihqi
1 parent 0b3ed9d commit a4daa89

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

torch/csrc/MemoryFormat.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ PyObject* THPMemoryFormat_repr(THPMemoryFormat* self) {
2828
return THPUtils_packString(self->name);
2929
}
3030

31+
PyObject* THPMemoryFormat_reduce(PyObject* _self, PyObject* noargs) {
32+
auto* self = (THPMemoryFormat*)_self;
33+
return THPUtils_packString(self->name);
34+
}
35+
36+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-non-const-global-variables,modernize-avoid-c-arrays)
37+
static PyMethodDef THPMemoryFormat_methods[] = {
38+
{"__reduce__", THPMemoryFormat_reduce, METH_NOARGS, nullptr},
39+
{nullptr} /* Sentinel */
40+
};
41+
3142
PyTypeObject THPMemoryFormatType = {
3243
PyVarObject_HEAD_INIT(nullptr, 0) "torch.memory_format", /* tp_name */
3344
sizeof(THPMemoryFormat), /* tp_basicsize */
@@ -55,7 +66,7 @@ PyTypeObject THPMemoryFormatType = {
5566
0, /* tp_weaklistoffset */
5667
nullptr, /* tp_iter */
5768
nullptr, /* tp_iternext */
58-
nullptr, /* tp_methods */
69+
THPMemoryFormat_methods, /* tp_methods */
5970
nullptr, /* tp_members */
6071
nullptr, /* tp_getset */
6172
nullptr, /* tp_base */

0 commit comments

Comments
 (0)