(self,
                   input: Tensor,
                   c0: Optional[Tensor],
                   mask_pad: Optional[Tensor])
return U, V
SRU performs grouped matrix multiplication to transform the
        input (length, batch_size, input_size) into a tensor U of size
        (length * batch_size, output_size * num_matrices).

        When a custom module `custom_m` is given, U will be computed by
        the given module. In addition, the module can return an
        additional tensor V (length, batch_size, output_size * 2) that
        will be added to the hidden-to-hidden coefficient terms in
        sigmoid gates, i.e., (V[t, b, d] + weight_c[d]) * c[t-1].
SRU performs grouped matrix multiplication to transform the
        input (length, batch_size, input_size) into a tensor U of size
        (length * batch_size, output_size * num_matrices).
SRU performs grouped matrix multiplication to transform the input ( length batch_size input_size ) into a tensor U of size ( length * batch_size output_size * num_matrices ) .
def compute_UV(self,
                   input: Tensor,
                   c0: Optional[Tensor],
                   mask_pad: Optional[Tensor]) -> Tuple[Tensor, Tensor]:
        """
        SRU performs grouped matrix multiplication to transform the
        input (length, batch_size, input_size) into a tensor U of size
        (length * batch_size, output_size * num_matrices).

        When a custom module `custom_m` is given, U will be computed by
        the given module. In addition, the module can return an
        additional tensor V (length, batch_size, output_size * 2) that
        will be added to the hidden-to-hidden coefficient terms in
        sigmoid gates, i.e., (V[t, b, d] + weight_c[d]) * c[t-1].

        """
        if self.custom_m is None:
            U = self.compute_U(input)
            V = self.weight_c
        else:
            ret = self.custom_m(input)
            if isinstance(ret, tuple) or isinstance(ret, list):
                if len(ret) > 2:
                    raise Exception("Custom module must return 1 or 2 tensors but got {}.".format(
                        len(ret)
                    ))
                U, V = ret[0], ret[1] + self.weight_c
            else:
                U, V = ret, self.weight_c

            if U.size(-1) != self.output_size * self.num_matrices:
                raise ValueError("U must have a last dimension of {} but got {}.".format(
                    self.output_size * self.num_matrices,
                    U.size(-1)
                ))
            if V.size(-1) != self.output_size * 2:
                raise ValueError("V must have a last dimension of {} but got {}.".format(
                    self.output_size * 2,
                    V.size(-1)
                ))
        return U, V
def compute_UV ( self , input : Tensor , c0 : Optional [ Tensor ] , mask_pad : Optional [ Tensor ] ) -> Tuple [ Tensor , Tensor ] : if self . custom_m is None : U = self . compute_U ( input ) V = self . weight_c else : ret = self . custom_m ( input ) if isinstance ( ret , tuple ) or isinstance ( ret , list ) : if len ( ret ) > 2 : raise Exception ( "Custom module must return 1 or 2 tensors but got {}." . format ( len ( ret ) ) ) U , V = ret [ 0 ] , ret [ 1 ] + self . weight_c else : U , V = ret , self . weight_c if U . size ( - 1 ) != self . output_size * self . num_matrices : raise ValueError ( "U must have a last dimension of {} but got {}." . format ( self . output_size * self . num_matrices , U . size ( - 1 ) ) ) if V . size ( - 1 ) != self . output_size * 2 : raise ValueError ( "V must have a last dimension of {} but got {}." . format ( self . output_size * 2 , V . size ( - 1 ) ) ) return U , V