
    GJj                     r    d dl Z d dlmZ d dlmZ d dlmZ  G d de      Z G d de      Z	 G d d	e      Z
y)
    N)Union)Modulec                   \     e Zd ZdZ	 	 	 	 	 ddededededededed	ef fd
Zd Zd Z xZ	S )ConvTranspose1da  Applies a 1-dimensional transposed convolution over the multi-channel input sequence.

    The channels are expected to be last i.e. the input shape should be ``NLC`` where:

    * ``N`` is the batch dimension
    * ``L`` is the sequence length
    * ``C`` is the number of input channels

    Args:
        in_channels (int): The number of input channels
        out_channels (int): The number of output channels
        kernel_size (int): The size of the convolution filters
        stride (int, optional): The stride when applying the filter.
            Default: ``1``.
        padding (int, optional): How many positions to 0-pad the input with.
            Default: ``0``.
        dilation (int, optional): The dilation of the convolution.
        output_padding(int, optional): Additional size added to one side of the
            output shape. Default: ``0``.
        bias (bool, optional): If ``True`` add a learnable bias to the output.
            Default: ``True``
    in_channelsout_channelskernel_sizestridepaddingdilationoutput_paddingbiasc	                     t         
|           t        j                  d||z  z        }	t        j
                  j                  |	 |	|||f      | _        |rt	        j                  |f      | _	        || _
        || _        || _        || _        y )N   lowhighshape)super__init__mathsqrtmxrandomuniformweightzerosr   r   r   r
   r   selfr   r   r	   r
   r   r   r   r   scale	__class__s             m/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/mlx/nn/layers/convolution_transpose.pyr   zConvTranspose1d.__init__"   s     			!{[89:ii''k: ( 

 ,1DI ,    c                    | j                   j                  d    d| j                   j                  d    d| j                   j                  d    d| j                   d| j                   d| j                   d	| j
                   d
d| v  S )N, r   , kernel_size=r   	, stride=
, padding=, dilation=, output_padding=, bias=r   r   r   r
   r   r   r   r   s    r"   _extra_reprzConvTranspose1d._extra_repr=   s    {{  $%R(9(9!(<'= >;;,,Q/0	$++ G||nK ?"112 3dN#	%	
r#   c                     t        j                  || j                  | j                  | j                  | j
                  | j                        }d| v r|| j                  z   }|S Nr   )r   conv_transpose1dr   r
   r   r   r   r   r   xys      r"   __call__zConvTranspose1d.__call__F   U    KKKKLLMM
 T>DIIAr#   r   r   r   r   T)
__name__
__module____qualname____doc__intboolr   r/   r6   __classcell__r!   s   @r"   r   r   
   sv    8 -- - 	-
 - - - - -6
r#   r   c                        e Zd ZdZ	 	 	 	 	 ddededeeef   deeef   deeef   deeef   deeef   d	ef fd
Zd Z	d Z
 xZS )ConvTranspose2da7  Applies a 2-dimensional transposed convolution over the multi-channel input image.

    The channels are expected to be last i.e. the input shape should be ``NHWC`` where:

    * ``N`` is the batch dimension
    * ``H`` is the input image height
    * ``W`` is the input image width
    * ``C`` is the number of input channels

    Args:
        in_channels (int): The number of input channels.
        out_channels (int): The number of output channels.
        kernel_size (int or tuple): The size of the convolution filters.
        stride (int or tuple, optional): The size of the stride when
            applying the filter. Default: ``1``.
        padding (int or tuple, optional): How many positions to 0-pad
            the input with. Default: ``0``.
        dilation (int or tuple, optional): The dilation of the convolution.
        output_padding(int or tuple, optional): Additional size added to one
            side of the output shape. Default: ``0``.
        bias (bool, optional): If ``True`` add a learnable bias to the
            output. Default: ``True``
    r   r   r	   r
   r   r   r   r   c	                 d   t         
|           t        d ||||f      \  }}}}t        j                  d||d   z  |d   z  z        }	t
        j                  j                  |	 |	|g||      | _        |rt        j                  |f      | _
        || _        || _        || _        || _        y )Nc                 .    t        | t              r| | fS | S N
isinstancer=   r4   s    r"   <lambda>z*ConvTranspose2d.__init__.<locals>.<lambda>{   s    
1c 2q!f99r#   r   r   r   r   r   mapr   r   r   r   r   r   r   r   r   r
   r   r   r   s             r"   r   zConvTranspose2d.__init__m   s     	7:9&'>:8
4VWn 		!{[^;k!nLMNii'';+;{; ( 

 ,1DI ,r#   c                    | j                   j                  d    d| j                   j                  d    d| j                   j                  dd  d| j                   d| j                   d	| j                   d
| j
                   dd| v  S )Nr%   r&   r   r'   r      r(   r)   r*   r+   r,   r   r-   r.   s    r"   r/   zConvTranspose2d._extra_repr       {{  $%R(9(9!(<'= >;;,,Qq12)DKK= I||nK ?"112 3dN#	%	
r#   c                     t        j                  || j                  | j                  | j                  | j
                  | j                        }d| v r|| j                  z   }|S r1   )r   conv_transpose2dr   r
   r   r   r   r   r3   s      r"   r6   zConvTranspose2d.__call__   r7   r#   r8   r9   r:   r;   r<   r=   r   tupler>   r   r/   r6   r?   r@   s   @r"   rB   rB   T   s    : %&%&&',--- - 3:&	-
 c5j!- sEz"- U
#- c5j)- ->
r#   rB   c                        e Zd ZdZ	 	 	 	 	 ddededeeef   deeef   deeef   deeef   deeef   d	ef fd
Zd Z	d Z
 xZS )ConvTranspose3da]  Applies a 3-dimensional transposed convolution over the multi-channel input image.

    The channels are expected to be last i.e. the input shape should be ``NDHWC`` where:

    * ``N`` is the batch dimension
    * ``D`` is the input image depth
    * ``H`` is the input image height
    * ``W`` is the input image width
    * ``C`` is the number of input channels

    Args:
        in_channels (int): The number of input channels.
        out_channels (int): The number of output channels.
        kernel_size (int or tuple): The size of the convolution filters.
        stride (int or tuple, optional): The size of the stride when
            applying the filter. Default: ``1``.
        padding (int or tuple, optional): How many positions to 0-pad
            the input with. Default: ``0``.
        dilation (int or tuple, optional): The dilation of the convolution.
        output_padding(int or tuple, optional): Additional size added to one
            side of the output shape. Default: ``0``.
        bias (bool, optional): If ``True`` add a learnable bias to the
            output. Default: ``True``
    r   r   r	   r
   r   r   r   r   c	                 p   t         
|           t        d ||||f      \  }}}}t        j                  d||d   z  |d   z  |d   z  z        }	t
        j                  j                  |	 |	|g||      | _        |rt        j                  |f      | _
        || _        || _        || _        || _        y )Nc                 0    t        | t              r| | | fS | S rE   rF   rH   s    r"   rI   z*ConvTranspose3d.__init__.<locals>.<lambda>   s    :a#5q!Qi<1<r#   r   r   rM   r   rJ   r   s             r"   r   zConvTranspose3d.__init__   s     	7:<&'>:8
4VWn 		{1~-A>QOP
 ii'';+;{; ( 

 ,1DI ,r#   c                    | j                   j                  d    d| j                   j                  d    d| j                   j                  dd  d| j                   d| j                   d	| j                   d
| j
                   dd| v  S )Nr%   r&   r   r'   r      r(   r)   r*   r+   r,   r   r-   r.   s    r"   r/   zConvTranspose3d._extra_repr   rN   r#   c                     t        j                  || j                  | j                  | j                  | j
                  | j                        }d| v r|| j                  z   }|S r1   )r   conv_transpose3dr   r
   r   r   r   r   r3   s      r"   r6   zConvTranspose3d.__call__   r7   r#   r8   rQ   r@   s   @r"   rT   rT      s    < %&%&&',--- - 3:&	-
 c5j!- sEz"- U
#- c5j)- -B
r#   rT   )r   typingr   mlx.corecorer   mlx.nn.layers.baser   r   rB   rT    r#   r"   <module>r`      s?       %Gf GTLf L^Of Or#   