Make Variable.is_sparse an attribute (#4308)

This matches Tensor.is_sparse, which makes it easier to replace Tensor
with Variable.
This commit is contained in:
Sam Gross
2017-12-22 12:46:28 -05:00
committed by GitHub
parent 7f6ca8efa5
commit de28e754b2
3 changed files with 19 additions and 1 deletions

View File

@ -437,6 +437,14 @@ PyObject *THPVariable_is_cuda(THPVariable *self)
END_HANDLE_TH_ERRORS
}
PyObject *THPVariable_is_sparse(THPVariable *self)
{
HANDLE_TH_ERRORS
auto& self_ = self->cdata;
return torch::autograd::utils::wrap(self_.is_sparse());
END_HANDLE_TH_ERRORS
}
static struct PyGetSetDef THPVariable_properties[] = {
{"_cdata", (getter)THPVariable_get_cdata, NULL, NULL, NULL},
{"_version", (getter)THPVariable_get_version, NULL, NULL, NULL},
@ -454,6 +462,7 @@ static struct PyGetSetDef THPVariable_properties[] = {
{"name", (getter)THPVariable_get_name, NULL, NULL, NULL},
{"shape", (getter)THPVariable_get_shape, NULL, NULL, NULL},
{"is_cuda", (getter)THPVariable_is_cuda, NULL, NULL, NULL},
{"is_sparse", (getter)THPVariable_is_sparse, NULL, NULL, NULL},
{NULL}
};