Rate this Page

Class LinearImpl#

Inheritance Relationships#

Base Type#

Class Documentation#

class LinearImpl : public torch::nn::Cloneable<LinearImpl>#

Applies a linear transformation with optional bias.

See https://pytorch.org/docs/main/generated/torch.nn.Linear.html to learn about the exact behavior of this module.

See the documentation for torch::nn::LinearOptions class to learn what constructor arguments are supported for this module.

Example:

Linear model(LinearOptions(5, 2).bias(false));

Public Functions

inline LinearImpl(int64_t in_features, int64_t out_features)#
explicit LinearImpl(const LinearOptions &options_)#
virtual void reset() override#

reset() must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.

void reset_parameters()#
virtual void pretty_print(std::ostream &stream) const override#

Pretty prints the Linear module into the given stream.

Tensor forward(const Tensor &input)#

Transforms the input tensor by multiplying with the weight and optionally adding the bias, if with_bias is true in the options.

Public Members

LinearOptions options#

The options used to configure this module.

Tensor weight#

The learned weight.

Tensor bias#

The learned bias.

If bias is false in the options, this tensor is undefined.