This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because we want to allow people to transfert their NumpyModule to a TorchModule so they can get access to TorchScript (see issue #42) we need to change the way how we do the inheritance. Before it was Module (reference to torch.nn.Module or our BaseModule) --> CustomModule (e.g. Ridge) But that means when loading the library there is just one class CustomModule that even inherits from torch.nn.Module or BaseModule depending if torch is available on the machine. With one inheritance, it is hard switch between the classes. Changing the base class is very hacky, so this is not a good approach. There we create both classes when torch is present (note BaseModule wase renamed to NumpyModule) def factory_custom_module(base): class _CustomModule(base): ... # change name ... return _CustomModule CustomNumpyModule = factory_custom_module(NumpyModule) CustomTorchModule = factory_custom_module(torch.nn.Module) if HAS_TORCH: CustomModule = CustomTorchModule else: CustomModule = CustomNumpyModule
- Loading branch information
1 parent
727f9b0
commit 8385523
Showing
1 changed file
with
176 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters