Shortcuts

Template Function torch::make_custom_class

Function Documentation

template<typename CurClass, typename ...CtorArgs>
c10::IValue torch::make_custom_class(CtorArgs&&... args)

make_custom_class() is a convenient way to create an instance of a registered custom class and wrap it in an IValue, for example when you want to pass the object to TorchScript.

Its syntax is equivalent to APIs like std::make_shared<> or c10::make_intrusive<>.

For example, if you have a custom C++ class that can be constructed from an int and std::string, you might use this API like so:

IValue custom_class_iv = torch::make_custom_class<MyClass>(3,
"foobarbaz");

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources