tch-rs
tch-rs copied to clipboard
Allow interop between CModule and TrainableCModule
Currently it's a bit difficult to create an interface that operates on CModule
. You may also want to accept TrainableCModule
since they implement most of the same methods, but there isn't actually an easy way to make that work. It seems to me like this would be a relatively simple ergonomic change:
Option 1: Implement Deref
Since TrainableCModule
is basically a wrapper around CModule
, it seems sensible that it could implement Deref<Target=CModule>
. This (plus DerefMut
) could replace the existing wrapper methods and would allow a TrainableCModule
to be passed to a function like:
fn foo(module: &CModule) {
...
}
Option 2: Implement From
Instead of or in addition to option 1, it would be nice for CModule
to implement From<TrainableCModule>
or to have a method such as TrainableCModule::into_inner(self) -> CModule
.
If there's interest in any of this, I'd be happy to put in a PR.