o
    eiF	                     @   sD   d Z ddlZddlmZ ddlmZ eeZG dd dejjZ	dS )zbLibrary implementing linear transformation.

Authors
 * Mirco Ravanelli 2020
 * Davide Borra 2021
    N)
get_loggerc                       s4   e Zd ZdZ					d	 fdd	Zdd Z  ZS )
Lineara  Computes a linear transformation y = wx + b.

    Arguments
    ---------
    n_neurons : int
        It is the number of output neurons (i.e, the dimensionality of the
        output).
    input_shape : tuple
        It is the shape of the input tensor.
    input_size : int
        Size of the input tensor.
    bias : bool
        If True, the additive bias b is adopted.
    max_norm : float
        weight max-norm.
    combine_dims : bool
        If True and the input is 4D, combine 3rd and 4th dimensions of input.

    Example
    -------
    >>> inputs = torch.rand(10, 50, 40)
    >>> lin_t = Linear(input_shape=(10, 50, 40), n_neurons=100)
    >>> output = lin_t(inputs)
    >>> output.shape
    torch.Size([10, 50, 100])
    NTFc                    sv   t    || _|| _|d u r|d u rtd|d u r0|d }t|dkr0| jr0|d |d  }tj|||d| _d S )Nz)Expected one of input_shape or input_size         )bias)	super__init__max_normcombine_dims
ValueErrorlennnr   w)self	n_neuronsinput_shape
input_sizer   r   r   	__class__ U/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/speechbrain/nnet/linear.pyr
   ,   s   
	zLinear.__init__c                 C   sr   |j dkr| jr||jd |jd |jd |jd  }| jdur2tj| jjj	dd| jd| jj_	| |}|S )a  Returns the linear transformation of input tensor.

        Arguments
        ---------
        x : torch.Tensor
            Input to transform linearly.

        Returns
        -------
        wx : torch.Tensor
            The linearly transformed outputs.
        r   r      r   r   N)pdimmaxnorm)
ndimr   reshapeshaper   torchrenormr   weightdata)r   xwxr   r   r   forwardD   s   *

zLinear.forward)NNTNF)__name__
__module____qualname____doc__r
   r&   __classcell__r   r   r   r   r      s    r   )
r*   r    torch.nnr   speechbrain.utils.loggerr   r'   loggerModuler   r   r   r   r   <module>   s    