A ModuleHolder
is essentially a wrapper around std::shared_ptr<M>
where M
is an nn::Module
subclass, with convenient constructors defined for the kind of constructions we want to allow for our modules.
More...
#include <pimpl.h>
|
using | ContainedType = Contained |
|
|
| ModuleHolder () |
| Default constructs the contained module if if has a default constructor, else produces a static error. More...
|
|
| ModuleHolder (std::nullptr_t) |
| Constructs the ModuleHolder with an empty contained value. More...
|
|
template<typename Head , typename... Tail, typename = typename std::enable_if< !(torch::detail::is_module_holder_of<Head, ContainedType>::value && (sizeof...(Tail) == 0))>::type> |
| ModuleHolder (Head &&head, Tail &&...tail) |
| Constructs the ModuleHolder with a contained module, forwarding all arguments to its constructor. More...
|
|
| ModuleHolder (std::shared_ptr< Contained > module) |
| Constructs the ModuleHolder from a pointer to the contained type. More...
|
|
| operator bool () const noexcept |
| Returns true if the ModuleHolder contains a module, or false if it is nullptr . More...
|
|
Contained * | operator-> () |
| Forwards to the contained module.
|
|
const Contained * | operator-> () const |
| Forwards to the contained module.
|
|
Contained & | operator* () |
| Returns a reference to the contained module.
|
|
const Contained & | operator* () const |
| Returns a const reference to the contained module.
|
|
const std::shared_ptr< Contained > & | ptr () const |
| Returns a shared pointer to the underlying module.
|
|
Contained * | get () |
| Returns a pointer to the underlying module.
|
|
const Contained * | get () const |
| Returns a const pointer to the underlying module.
|
|
template<typename... Args> |
auto | operator() (Args &&...args) -> torch::detail::return_type_of_forward_t< Contained, Args... > |
| Calls the forward() method of the contained module.
|
|
template<typename Arg > |
auto | operator[] (Arg &&arg) -> decltype((*impl_)[::std::forward< Arg >(arg)]) |
| Forwards to the subscript operator of the contained module. More...
|
|
bool | is_empty () const noexcept |
| Returns true if the ModuleHolder does not contain a module.
|
|
|
std::shared_ptr< Contained > | impl_ |
| The module pointer this class wraps. More...
|
|
template<typename Contained>
class torch::nn::ModuleHolder< Contained >
A ModuleHolder
is essentially a wrapper around std::shared_ptr<M>
where M
is an nn::Module
subclass, with convenient constructors defined for the kind of constructions we want to allow for our modules.
Definition at line 26 of file pimpl.h.
template<typename Contained>
Default constructs the contained module if if has a default constructor, else produces a static error.
NOTE: This uses the behavior of template classes in C++ that constructors (or any methods) are only compiled when actually used.
Definition at line 42 of file pimpl.h.
template<typename Contained>
Constructs the ModuleHolder
with an empty contained value.
Access to the underlying module is not permitted and will throw an exception, until a value is assigned.
Definition at line 53 of file pimpl.h.
template<typename Contained>
template<typename Head , typename... Tail, typename = typename std::enable_if< !(torch::detail::is_module_holder_of<Head, ContainedType>::value && (sizeof...(Tail) == 0))>::type>
Constructs the ModuleHolder
with a contained module, forwarding all arguments to its constructor.
Definition at line 63 of file pimpl.h.
template<typename Contained>
Constructs the ModuleHolder
from a pointer to the contained type.
Example: Linear(std::make_shared<LinearImpl>(...))
.
Definition at line 70 of file pimpl.h.
template<typename Contained>
Returns true if the ModuleHolder
contains a module, or false if it is nullptr
.
Definition at line 75 of file pimpl.h.
template<typename Contained>
template<typename Arg >
Forwards to the subscript operator of the contained module.
NOTE: std::forward is qualified to prevent VS2017 emitting error C2872: 'std': ambiguous symbol
Definition at line 132 of file pimpl.h.
template<typename Contained>
The module pointer this class wraps.
NOTE: Must be placed at the top of the class so that we can use it with trailing return types below.
Definition at line 31 of file pimpl.h.
The documentation for this class was generated from the following file:
- torch/csrc/api/include/torch/nn/pimpl.h