
    +h	                         S SK r S SKJr  S SKJ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	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-array   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/james-whalen/.local/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Sr\\S'   \R                  r
\R                  \S'   \R                  S 5       rSrg)	FlaxTimestepEmbeddingD   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.
    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__R   sX    xx++4::JOPTUwwt}xx++4::JOPTUr&    N)__name__
__module____qualname____firstlineno____doc__r+   int__annotations__r   r   r   r0   compactr5   __static_attributes__r7   r&   r$   r(   r(   D   s;     NC{{E399"ZZ r&   r(   c                   h    \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\\S'   \R                  S	 5       rS
rg)FlaxTimestepsZ   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   c                 T    [        XR                  U R                  U R                  S9$ )N)r   r   r   )r%   rD   r   r   )r3   r   s     r$   r5   FlaxTimesteps.__call__k   s'    (XXt?S?S`d`o`o
 	
r&   r7   N)r8   r9   r:   r;   r<   rD   r=   r>   r   boolr   r   r0   r?   r5   r@   r7   r&   r$   rB   rB   Z   s<    
 CM!OT!JZZ
 
r&   rB   )r   r   g     @Fg      ?)r   
flax.linenlinenr0   	jax.numpynumpyr   ndarrayr=   r   rG   r%   Moduler(   rB   r7   r&   r$   <module>rN      s        !-{{-- - 	-
 - - - 	[[-`BII ,
BII 
r&   