Ë
    (täiØ  ã                   ó  — d dl Z d dlmZ d dlmZ ddlmZ  ej                  e
«      Z	 	 	 	 	 ddej                  dedededed	ed
edej                  fd„Z G d„ dej"                  «      Z G d„ dej"                  «      Zy)é    Né   )ÚloggingÚ	timestepsÚembedding_dimÚ
freq_shiftÚmin_timescaleÚmax_timescaleÚflip_sin_to_cosÚscaleÚreturnc                 óð  — | j                   dk(  sJ d«       ‚|dz  dk(  sJ d|› d�«       ‚t        |dz  «      }t        j                  ||z  «      ||z
  z  }|t	        j
                  t	        j                  |t        j                  ¬«      | z  «      z  }	t	        j                  | d«      t	        j                  |	d«      z  }
||
z  }|r@t	        j                  t	        j                  |«      t	        j                  |«      gd¬«      }n?t	        j                  t	        j                  |«      t	        j                  |«      gd¬«      }t	        j                  |t	        j                  | «      d   |g«      }|S )	a  Returns the positional encoding (same as Tensor2Tensor).

    Args:
        timesteps (`jnp.ndarray` of shape `(N,)`):
            A 1-D array of N indices, one per batch element. These may be fractional.
        embedding_dim (`int`):
            The number of output channels.
        freq_shift (`float`, *optional*, defaults to `1`):
            Shift applied to the frequency scaling of the embeddings.
        min_timescale (`float`, *optional*, defaults to `1`):
            The smallest time unit used in the sinusoidal calculation (should probably be 0.0).
        max_timescale (`float`, *optional*, defaults to `1.0e4`):
            The largest time unit used in the sinusoidal calculation.
        flip_sin_to_cos (`bool`, *optional*, defaults to `False`):
            Whether to flip the order of sinusoidal components to cosine first.
        scale (`float`, *optional*, defaults to `1.0`):
            A scaling factor applied to the positional embeddings.

    Returns:
        a Tensor of timing signals [N, num_channels]
    é   zTimesteps should be a 1d-arrayr   r   zEmbedding dimension z should be even)Údtype)Úaxis)ÚndimÚfloatÚmathÚlogÚjnpÚexpÚarangeÚfloat32Úexpand_dimsÚconcatenateÚcosÚsinÚreshapeÚshape)r   r   r   r   r	   r
   r   Únum_timescalesÚlog_timescale_incrementÚinv_timescalesÚembÚscaled_timeÚsignals                úo/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/diffusers/models/embeddings_flax.pyÚget_sinusoidal_embeddingsr&      s=  € ð< �>‰>˜QÒÐ@Ð @Ó@ÐØ˜1Ñ Ò!ÐXÐ%9¸-¸ÈÐ#XÓXÐ!Ü˜=¨AÑ-Ó.€NÜ"Ÿh™h }°}Ñ'DÓEÈÐZdÑIdÑeÐØ"¤S§W¡W¬S¯Z©Z¸ÌcÏkÉkÔ-ZÐ^uÐ]uÑ-uÓ%vÑv€NÜ
�/‰/˜) QÓ
'¬#¯/©/¸.È!Ó*LÑ
L€Cð ˜#‘+€KáÜ—‘¤#§'¡'¨+Ó"6¼¿¹ÀÓ8LÐ!MÐTUÔV‰ä—‘¤#§'¡'¨+Ó"6¼¿¹ÀÓ8LÐ!MÐTUÔVˆÜ�[‰[˜¤#§)¡)¨IÓ"6°qÑ"9¸=Ð!IÓJ€FØ€Mó    c                   óœ   — e Zd ZU dZej                  d«       dZeed<   e	j                  Ze	j                  ed<   ej                  d„ «       Zy)ÚFlaxTimestepEmbeddinga=  
    Time step Embedding Module. Learns embeddings for input time steps.

    Args:
        time_embed_dim (`int`, *optional*, defaults to `32`):
            Time step embedding dimension.
        dtype (`jnp.dtype`, *optional*, defaults to `jnp.float32`):
            The data type for the embedding parameters.
    ú”Flax classes are deprecated and will be removed in Diffusers v1.0.0. We recommend migrating to PyTorch classes or pinning your version of Diffusers.é    Útime_embed_dimr   c                 óø   —  t        j                  | j                  | j                  d¬«      |«      }t        j                  |«      } t        j                  | j                  | j                  d¬«      |«      }|S )NÚlinear_1)r   ÚnameÚlinear_2)ÚnnÚDenser,   r   Úsilu)ÚselfÚtembs     r%   Ú__call__zFlaxTimestepEmbedding.__call__\   s\   € àOŒr�x‰x˜×+Ñ+°4·:±:ÀJÔOÐPTÓUˆÜ�w‰w�t‹}ˆØOŒr�x‰x˜×+Ñ+°4·:±:ÀJÔOÐPTÓUˆØˆr'   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚloggerÚwarningr,   ÚintÚ__annotations__r   r   r   r1   Úcompactr6   © r'   r%   r)   r)   I   sO   … ñð ‡N�Nð	Wôð
 €N�CÓØ—{‘{€Eˆ3�9‰9Ó"à‡Z�Zñó ñr'   r)   c                   ó‚   — e Zd ZU dZdZeed<   dZeed<   dZ	e
ed<   ej                  d«       ej                  d	„ «       Zy
)ÚFlaxTimestepsaç  
    Wrapper Module for sinusoidal Time step Embeddings as described in https://huggingface.co/papers/2006.11239

    Args:
        dim (`int`, *optional*, defaults to `32`):
            Time step embedding dimension.
        flip_sin_to_cos (`bool`, *optional*, defaults to `False`):
            Whether to flip the sinusoidal function from sine to cosine.
        freq_shift (`float`, *optional*, defaults to `1`):
            Frequency shift applied to the sinusoidal embeddings.
    r+   ÚdimFr
   r   r   r*   c                 ó\   — t        || j                  | j                  | j                  ¬«      S )N)r   r
   r   )r&   rC   r
   r   )r4   r   s     r%   r6   zFlaxTimesteps.__call__z   s)   € ä(Ø T§X¡X¸t×?SÑ?SÐ`d×`oÑ`oô
ð 	
r'   N)r7   r8   r9   r:   rC   r=   r>   r
   Úboolr   r   r;   r<   r1   r?   r6   r@   r'   r%   rB   rB   d   sP   … ñ
ð €CˆƒMØ!€O�TÓ!Ø€J�Óà
‡N�Nð	Wôð
 ‡Z�Zñ
ó ñ
r'   rB   )r   r   g     ˆÃ@Fg      ð?)r   Ú
flax.linenÚlinenr1   Ú	jax.numpyÚnumpyr   Úutilsr   Ú
get_loggerr7   r;   Úndarrayr=   r   rE   r&   ÚModuler)   rB   r@   r'   r%   Ú<module>rN      s²   ðó å Ý å ð 
ˆ×	Ñ	˜HÓ	%€ð ØØ Ø!Øñ-Ø�{‰{ð-àð-ð ð-ð ð	-ð
 ð-ð ð-ð ð-ð 	‡[�[ó-ô`˜BŸI™Iô ô6
�B—I‘Iõ 
r'   