mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Setter for real and imag tensor attributes (#39860)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39860 Test Plan: Imported from OSS Reviewed By: mruberry Differential Revision: D22163234 Pulled By: anjali411 fbshipit-source-id: 35b4aa16499341edff1a4be4076539ac7c74f5be
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fd90e4b309
commit
11a74a58c8
@ -542,6 +542,26 @@ PyObject *THPVariable_get_imag(THPVariable* self, void *unused)
|
||||
END_HANDLE_TH_ERRORS
|
||||
}
|
||||
|
||||
int THPVariable_set_real(THPVariable *self, THPVariable *real, void *unused)
|
||||
{
|
||||
HANDLE_TH_ERRORS
|
||||
auto& self_ = self->cdata;
|
||||
auto self_real = at::real(self_);
|
||||
self_real.copy_(real->cdata);
|
||||
return 0;
|
||||
END_HANDLE_TH_ERRORS_RET(-1)
|
||||
}
|
||||
|
||||
int THPVariable_set_imag(THPVariable* self, THPVariable *imag, void *unused)
|
||||
{
|
||||
HANDLE_TH_ERRORS
|
||||
auto& self_ = self->cdata;
|
||||
auto self_imag = at::imag(self_);
|
||||
self_imag.copy_(imag->cdata);
|
||||
return 0;
|
||||
END_HANDLE_TH_ERRORS_RET(-1)
|
||||
}
|
||||
|
||||
// properties are registered here because we are currently only able to bind them
|
||||
// manually. TODO: make declarable in native_functions
|
||||
static struct PyGetSetDef THPVariable_properties[] = {
|
||||
@ -572,8 +592,8 @@ static struct PyGetSetDef THPVariable_properties[] = {
|
||||
{"device", (getter)THPVariable_device, nullptr, nullptr, nullptr},
|
||||
{"ndim", (getter)THPVariable_get_ndim, nullptr, nullptr, nullptr},
|
||||
{"names", (getter)THPVariable_get_names, (setter)THPVariable_set_names, nullptr, nullptr},
|
||||
{"real", (getter)THPVariable_get_real, nullptr, nullptr, nullptr},
|
||||
{"imag", (getter)THPVariable_get_imag, nullptr, nullptr, nullptr},
|
||||
{"real", (getter)THPVariable_get_real, (setter)THPVariable_set_real, nullptr, nullptr},
|
||||
{"imag", (getter)THPVariable_get_imag, (setter)THPVariable_set_imag, nullptr, nullptr},
|
||||
{nullptr}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user