avoid redundant isCustomClassRegistered() checks (#42852)

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/42852

Test Plan: Imported from OSS

Reviewed By: smessmer

Differential Revision: D23048381

Pulled By: bhosmer

fbshipit-source-id: 40b71670a84cb6f7e5a03279f58ce227d676aa03
This commit is contained in:
Basil Hosmer
2020-08-11 21:51:41 -07:00
committed by Facebook GitHub Bot
parent bee174dc3f
commit 38c7b9a168
3 changed files with 17 additions and 20 deletions

View File

@ -261,11 +261,6 @@ class class_ {
/// IValue custom_class_iv = torch::make_custom_class<MyClass>(3, "foobarbaz");
template <typename CurClass, typename... CtorArgs>
c10::IValue make_custom_class(CtorArgs&&... args) {
if (!c10::isCustomClassRegistered<c10::intrusive_ptr<CurClass>>()) {
throw c10::Error(
"Trying to instantiate a class that isn't a registered custom class.",
"");
}
auto userClassInstance = c10::make_intrusive<CurClass>(std::forward<CtorArgs>(args)...);
return c10::IValue(std::move(userClassInstance));
}