Shortcuts

Class ParameterDictImpl

Inheritance Relationships

Base Type

Class Documentation

class torch::nn::ParameterDictImpl : public torch::nn::Cloneable<ParameterDictImpl>

Public Types

using Iterator = OrderedDict<std::string, Tensor>::Iterator
using ConstIterator = OrderedDict<std::string, Tensor>::ConstIterator

Public Functions

ParameterDictImpl() = default
ParameterDictImpl(const torch::OrderedDict<std::string, torch::Tensor> &params)
void reset() override

reset() is empty for ParameterDict, since it does not have parameters of its own.

void pretty_print(std::ostream &stream) const override

Pretty prints the ParameterDict module into the given stream.

Tensor &insert(std::string key, Tensor param)

Insert the parameter along with the key into ParameterDict The parameter is set to be require grad by default.

Tensor pop(const std::string &key)

Remove key from the ParameterDict and return its value, throw exception if the key is not contained.

Please check contains(key) before for a non-throwing access.

::std::vector<std::string> keys() const

Return the keys in the dict.

::std::vector<torch::Tensor> values() const

Return the Values in the dict.

Iterator begin()

Return an iterator to the start of ParameterDict.

ConstIterator begin() const

Return a const iterator to the start of ParameterDict.

Iterator end()

Return an iterator to the end of ParameterDict.

ConstIterator end() const

Return a const iterator to the end of ParameterDict.

size_t size() const noexcept

Return the number of items currently stored in the ParameterDict.

bool empty() const noexcept

Return true if the ParameterDict is empty, otherwise return false.

template<typename Container>
void update(const Container &container)

Update the ParameterDict with the key-value pairs from another ParameterDict, overwriting existing key.

void clear()

Remove all parameters in the ParameterDict.

bool contains(const std::string &key) const noexcept

Check if the centain parameter with the key in the ParameterDict.

const Tensor &get(const std::string &key) const

Returns the value associated with the given key.

Throws an exception if no such key is stored in the ParameterDict. Check contains(key) before for a non-throwing way of access

Tensor &get(const std::string &key)

Returns the value associated with the given key.

Throws an exception if no such key is stored in the ParameterDict. Check contains(key) before for a non-throwing way of access

Tensor &operator[](const std::string &key)

Returns the value associated with the given key.

Throws an exception if no such key is stored in the ParameterDict. Check contains(key) before for a non-throwing way of access

const Tensor &operator[](const std::string &key) const

Returns the value associated with the given key.

Throws an exception if no such key is stored in the ParameterDict. Check contains(key) before for a non-throwing way of access

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