
    3j                         S r SSKJrJrJr  SSKrSSKJr  SSK	J
r
Jr  SSKJr  Sr " S	 S
\
\5      r " S S\\5      r " S S\\5      rg)aj  
Comment about tensorflow layers:
unfortunately instructions on creation of TF layers change constantly,
and changed way too many times at this point to remember what-compatible-where.

Layers in einops==0.7.0 (and several prior versions)
 are compatible with TF 2.13

Layers in einops==0.8.0 were re-implemented
 according to official instructions for TF 2.16

    )DictOptionalcastN)Layer   )RearrangeMixinReduceMixin)_EinmixMixinzAlex Rogozhnikovc                   &    \ rS rSrS rS rS rSrg)	Rearrange   c                     g N selfinput_shapes     R/home/wildlama/miniconda3/lib/python3.13/site-packages/einops/layers/tensorflow.pybuildRearrange.build           c                 $    U R                  U5      $ r   _apply_reciper   inputss     r   callRearrange.call       !!&))r   c                 6    SU R                   0U R                  E$ )Npattern)r"   axes_lengthsr   s    r   
get_configRearrange.get_config    s    4<<=4+<+<==r   r   N__name__
__module____qualname____firstlineno__r   r   r%   __static_attributes__r   r   r   r   r      s    *>r   r   c                   &    \ rS rSrS rS rS rSrg)Reduce$   c                     g r   r   r   s     r   r   Reduce.build%   r   r   c                 $    U R                  U5      $ r   r   r   s     r   r   Reduce.call(   r    r   c                 L    U R                   U R                  S.U R                  E$ )N)r"   	reduction)r"   r5   r#   r$   s    r   r%   Reduce.get_config+   s     <<dnnZHYHYZZr   r   Nr'   r   r   r   r.   r.   $   s    *[r   r.   c            	       ^    \ rS rSrS rS\\   S\\   S\\   S\\   4S jrS r	S	 r
S
 rSrg)EinMix/   c                     XX4/U l         g r   )_params)r   weight_shapeweight_bound
bias_shape
bias_bounds        r   _create_parametersEinMix._create_parameters0   s     %JKr   pre_reshape_patternpre_reshape_lengthspost_reshape_patternpost_reshape_lengthsc                     S U l         Ub  [        U40 [        [        U5      D6U l         S U l        Ub   [        U40 [        [        U5      D6U l        g g r   )pre_rearranger   r   dictpost_rearrange)r   rB   rC   rD   rE   s        r   _create_rearrange_layersEinMix._create_rearrange_layers5   s[     "*!*+>!b$tM`Ba!bD"+"+,@"eDOcDd"eD ,r   c                     U R                   u  p#pEU R                  U[        R                  " U* U5      SS9U l        Ub-  U R                  U[        R                  " U* U5      SS9U l        g S U l        g )NT)shapeinitializer	trainable)r;   
add_weighttfrandom_uniform_initializerweightbias)r   r   r<   r=   r>   r?   s         r   r   EinMix.buildD   s{    ?C||<Zoo55|m\R & 
 ! 99:+zR ( DI DIr   c                 
   U R                   b  U R                  U5      n[        R                  " U R                  XR                  5      nU R
                  b  X R
                  -   nU R                  b  U R                  U5      nU$ r   )rG   rQ   einsumeinsum_patternrS   rT   rI   )r   r   results      r   r   EinMix.callU   so    )''/F4..D99 ii'F*((0Fr   c                 b    U R                   U R                  U R                  S.U R                  E$ )N)r"   r<   r>   )r"   r<   r>   r#   r$   s    r   r%   EinMix.get_config_   s3    || --//
 	
 	
r   )r;   rT   rI   rG   rS   N)r(   r)   r*   r+   r@   r   strr   rJ   r   r   r%   r,   r   r   r   r8   r8   /   sW    L
f%c]f &d^f 'sm	f
 'tnf"
r   r8   )__doc__typingr   r   r   
tensorflowrQ   tensorflow.keras.layersr    r   r	   _einmixr
   
__author__r   r.   r8   r   r   r   <module>re      sO    ( '  ) ) !
> >[[% [6
\5 6
r   