microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Better lifetime management for pybind ks calls #849

Closed dcrc2 closed 3 years ago

dcrc2 commented 3 years ago

Alternative to #846, stashing the torch.Tensor object inside the pybind ks wrapper class.

I'd have liked to encapsulate this inside declare_tensor_N; this is probably possible but I didn't see an obvious way to do it. Instead, this implementation creates a Tensor_N_Float object as before, but then assigns the Tensor to an attribute of that object. This requires adding py::dynamic_attr() to the pybind class definition.