
    h                         S SK r S SKrS SKrS rS rS rS r SS\S\S\S	\	S
\
S\
4S jjrS rS rS rS\R                  4S jrS rS rS rS\4S jrS rS rS rS rS rS rg)    Nc                 $    SnU  H  nX-  nM	     U$ )z6Compute the product of all elements in the input list.    )in_listres_s      O/home/james-whalen/.local/lib/python3.13/site-packages/thop/vision/calc_func.pyl_prodr
   	   s    
C J    c                     [        U 5      $ )z6Calculate the sum of all numerical elements in a list.sum)r   s    r	   l_sumr      s    w<r   c                 &    [        S U  5       5      $ )z`Calculate the total number of parameters in a list of tensors using the product of their shapes.c              3   l   #    U  H*  n[         R                  " UR                  5       /5      v   M,     g 7f)N)torchDoubleTensornelement).0ps     r	   	<genexpr>'calculate_parameters.<locals>.<genexpr>   s&     F:au!!1::<.11:s   24r   )
param_lists    r	   calculate_parametersr      s    F:FFFr   c                  0    [         R                  " S/5      $ )z?Initializes and returns a tensor with all elements set to zero.r   r   r   r   r   r	   calculate_zero_opsr      s    qc""r   
input_sizeoutput_sizekernel_sizegroupsbias	transposec                     U(       a$  US   n[        U 5      Xc-  -  [        USS 5      -  $ U S   n[        U5      Xs-  -  [        USS 5      -  $ )zdCalculate FLOPs for a Conv2D layer using input/output sizes, kernel size, groups, and the bias flag.r      N)r
   )r   r   r    r!   r"   r#   out_cin_cs           r	   calculate_conv2d_flopsr(       s]     Aj!U_5{128OOO!}k"dn5{128OOOr   c                 r    [         R                  " S5        [        R                  " X#U-  U-  U -   -  /5      $ )zgCalculate FLOPs for convolutional layers given bias, kernel size, output size, in_channels, and groups.zThis API is being deprecated.)warningswarnr   r   )r"   r    r   
in_channelgroups        r	   calculate_convr.   .   s6    MM12{5.@;.NQU.UVWXXr   c                 6    [         R                  " SU -  /5      $ )zACompute the L2 norm of a tensor or array based on its input size.r%   r   r   s    r	   calculate_normr1   4   s    q:~.//r   c                     g)z[Calculates the FLOPs for a ReLU activation function based on the input tensor's dimensions.r   r   r0   s    r	   calculate_relu_flopsr3   9   s    r   c                 n    [         R                  " S5        [        R                  " [	        U 5      /5      $ )zKConvert an input tensor to a DoubleTensor with the same value (deprecated).zThis API is being deprecated)r*   r+   r   r   intr0   s    r	   calculate_relur6   >   s'    MM01s:/00r   c                 h    UnUS-
  nUnXU-   U-   -  n[         R                  " [        U5      /5      $ )zJCompute FLOPs for a softmax activation given batch size and feature count.r   r   r   r5   )
batch_size	nfeatures	total_exp	total_add	total_div	total_opss         r	   calculate_softmaxr?   D   s?    IAII)3i?@Is9~.//r   c                 B    [         R                  " [        U 5      /5      $ )z<Calculate the average pooling size for a given input tensor.r8   r0   s    r	   calculate_avgpoolrA   M   s    s:/00r   c                 R    SnX-   n[         R                  " [        X1-  5      /5      $ )zOCalculate FLOPs for adaptive average pooling given kernel size and output size.r   r8   )r    r   r=   	kernel_ops       r	   calculate_adaptive_avgrD   R   s+    I'Is9#:;<==r   modec                     UnU S:X  a  US-  nO#U S:X  a  US-  nOU S:X  a  US-  nOU S:X  a  US-  n[         R                  " [        U5      /5      $ )	z]Calculate the operations required for various upsample methods based on mode and output size.bicubici  bilinear   linear   	trilinear   r8   )rE   r   r>   s      r	   calculate_upsamplerN   Y   se    IyX			R			Q			Z	s9~.//r   c                 F    [         R                  " [        X-  5      /5      $ )zTCalculate the linear operation count for given input feature and number of elements.r8   )
in_featurenum_elementss     r	   calculate_linearrR   g   s    s:#<=>??r   c                     [         R                  " U 5      n [         R                  " U5      n[         R                  " U 5      US   -  $ )z`Calculate the total number of operations for matrix multiplication given input and output sizes.)nparrayprod)r   r   s     r	   counter_matmulrX   l   s6    *%J((;'K77:R00r   c                     U $ )z^Calculate the total number of operations for element-wise multiplication given the input size.r   r0   s    r	   counter_mulrZ   s       r   c                     U $ )z\Computes the total scalar multiplications required for power operations based on input size.r   r0   s    r	   counter_powr]   x   r[   r   c                     U $ )ziCalculate the total number of scalar operations required for a square root operation given an input size.r   r0   s    r	   counter_sqrtr_   }   r[   r   c                     U $ )z]Calculate the total number of scalar operations for a division operation given an input size.r   r0   s    r	   counter_divra      r[   r   )FF)r*   numpyrU   r   r
   r   r   r   listr5   boolr(   r.   r1   r3   Tensorr6   r?   rA   rD   strrN   rR   rX   rZ   r]   r_   ra   r   r   r	   <module>rg      s      
G
# puPP#'P6:PDGPOSPhlPY0

1u|| 101
>0S 0@
1


r   