
    
3j                        S SK r S SKJr  S SKJr  SSKJr  \R                  " \
5      r     SS\R                  S\S\S\S\S	\S
\S\R                  4S jjr " S S\R"                  5      r " S S\R"                  5      rg)    N   )logging	timestepsembedding_dim
freq_shiftmin_timescalemax_timescaleflip_sin_to_cosscalereturnc                     U R                   S:X  d   S5       eUS-  S:X  d   SU S35       e[        US-  5      n[        R                  " XC-  5      Xr-
  -  nU[        R
                  " [        R                  " U[        R                  S9U* -  5      -  n	[        R                  " U S5      [        R                  " U	S5      -  n
Xj-  nU(       a@  [        R                  " [        R                  " U5      [        R                  " U5      /SS9nO?[        R                  " [        R                  " U5      [        R                  " U5      /SS9n[        R                  " U[        R                  " U 5      S   U/5      nU$ )	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                Z/home/wildlama/miniconda3/lib/python3.13/site-packages/diffusers/models/embeddings_flax.pyget_sinusoidal_embeddingsr&      s6   < >>Q@ @@1!X%9-#XX!=A-.N"hh}'DEIde"SWWSZZckk-Z^u]u-u%vvN
//)Q
'#//.!*L
LC +K#''+"68L!MTUV#''+"68L!MTUV[[#))I"6q"9=!IJFM    c                       \ rS rSr% Sr\R                  S5        Sr\\	S'   \
R                  r\
R                  \	S'   \R                  S 5       rSrg	)
FlaxTimestepEmbeddingI   a!  
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                     [         R                  " U R                  U R                  SS9" U5      n[         R                  " U5      n[         R                  " U R                  U R                  SS9" U5      nU$ )Nlinear_1)r   namelinear_2)nnDenser-   r   silu)selftembs     r%   __call__FlaxTimestepEmbedding.__call__\   sX    xx++4::JOPTUwwt}xx++4::JOPTUr'    N)__name__
__module____qualname____firstlineno____doc__loggerwarningr-   int__annotations__r   r   r   r2   compactr7   __static_attributes__r9   r'   r%   r)   r)   I   sO     NN	W
 NC{{E399"ZZ r'   r)   c                       \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\\S'   \R                  S	5        \R                  S
 5       rSrg)FlaxTimestepsd   a  
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    [        XR                  U R                  U R                  S9$ )N)r   r
   r   )r&   rH   r
   r   )r5   r   s     r%   r7   FlaxTimesteps.__call__z   s'    (XXt?S?S`d`o`o
 	
r'   r9   N)r:   r;   r<   r=   r>   rH   rA   rB   r
   boolr   r   r?   r@   r2   rC   r7   rD   r9   r'   r%   rF   rF   d   sP    
 CM!OT!J
NN	W
 ZZ
 
r'   rF   )r   r   g     @Fg      ?)r   
flax.linenlinenr2   	jax.numpynumpyr   utilsr   
get_loggerr:   r?   ndarrayrA   r   rK   r&   Moduler)   rF   r9   r'   r%   <module>rT      s        
		H	%  !-{{-- - 	-
 - - - 	[[-`BII 6
BII 
r'   