:github_url: https://github.com/pytorch/pytorch .. _program_listing_file_torch_csrc_api_include_torch_nn_functional_linear.h: Program Listing for File linear.h ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``torch/csrc/api/include/torch/nn/functional/linear.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include namespace torch::nn::functional { inline Tensor bilinear( const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias = Tensor()) { return torch::bilinear(input1, input2, weight, bias); } // ============================================================================ inline Tensor linear( const Tensor& input, const Tensor& weight, const Tensor& bias = {}) { if (input.dim() == 2 && bias.defined()) { // fused op is marginally faster return torch::addmm(bias, input, weight.t()); } else { auto output = input.matmul(weight.t()); if (bias.defined()) { output += bias; } return output; } } } // namespace torch::nn::functional