Ë
    Dêñi²  ã                   óÌ   — d dl Z d dlZd dlZd„ Zd„ Zd„ Zd„ Z	 ddededed	e	d
e
de
fd„Zd„ Zd„ Zd„ Zdej                  fd„Zd„ Zd„ Zd„ Zdefd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)é    Nc                 ó"   — d}| D ]  }||z  }Œ	 |S )z6Compute the product of all elements in the input list.é   © )Úin_listÚresÚ_s      úW/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/thop/vision/calc_func.pyÚl_prodr
   	   s$   € à
€CØò ˆØˆq‰‰ðà€Jó    c                 ó   — t        | «      S )z6Calculate the sum of all numerical elements in a list.©Úsum)r   s    r	   Úl_sumr      s   € äˆw‹<Ðr   c                 ó&   — t        d„ | D «       «      S )z`Calculate the total number of parameters in a list of tensors using the product of their shapes.c              3   ód   K  — | ](  }t        j                  |j                  «       g«      –— Œ* y ­w)N)ÚtorchÚDoubleTensorÚnelement)Ú.0Úps     r	   ú	<genexpr>z'calculate_parameters.<locals>.<genexpr>   s#   è ø€ ÒF°aŒu×!Ñ! 1§:¡:£< .×1ÑFùs   ‚.0r   )Ú
param_lists    r	   Úcalculate_parametersr      s   € äÑF¸:ÔFÓFÐFr   c                  ó.   — t        j                  dg«      S )z?Initializes and returns a tensor with all elements set to zero.r   ©r   r   r   r   r	   Úcalculate_zero_opsr      s   € ä×Ñ˜q˜cÓ"Ð"r   Ú
input_sizeÚoutput_sizeÚkernel_sizeÚgroupsÚbiasÚ	transposec                 óš   — |r%|d   }t        | «      ||z  z  t        |dd «      z  S | d   }t        |«      ||z  z  t        |dd «      z  S )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'       sa   € ñ Ø˜A‘ˆÜ�jÓ! U¨f¡_Ñ5¼¸{È1È2¸Ó8OÑOÐOà˜!‰}ˆÜ�kÓ" d¨f¡nÑ5¼¸{È1È2¸Ó8OÑOÐOr   c                 óp   — t        j                  d«       t        j                  |||z  |z  | z   z  g«      S )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-   .   s8   € ä‡M�MÐ1Ô2Ü×Ñ˜{¨j¸5Ñ.@À;Ñ.NÐQUÑ.UÑVÐWÓXÐXr   c                 ó4   — t        j                  d| z  g«      S )zACompute the L2 norm of a tensor or array based on its input size.r$   r   ©r   s    r	   Úcalculate_normr0   4   s   € ä×Ñ˜q :™~Ð.Ó/Ð/r   c                  ó   — y)z[Calculates the FLOPs for a ReLU activation function based on the input tensor's dimensions.r   r   r/   s    r	   Úcalculate_relu_flopsr2   9   s   € àr   c                 ój   — t        j                  d«       t        j                  t	        | «      g«      S )zKConvert an input tensor to a DoubleTensor with the same value (deprecated).zThis API is being deprecated)r)   r*   r   r   Úintr/   s    r	   Úcalculate_relur5   >   s'   € ä‡M�MÐ0Ô1Ü×Ñœs :›Ð/Ó0Ð0r   c                 óh   — |}|dz
  }|}| ||z   |z   z  }t        j                  t        |«      g«      S )zJCompute FLOPs for a softmax activation given batch size and feature count.r   ©r   r   r4   )Ú
batch_sizeÚ	nfeaturesÚ	total_expÚ	total_addÚ	total_divÚ	total_opss         r	   Úcalculate_softmaxr>   D   sA   € à€IØ˜A‘€IØ€IØ˜i¨)Ñ3°iÑ?Ñ@€IÜ×Ñœs 9›~Ð.Ó/Ð/r   c                 ó@   — t        j                  t        | «      g«      S )z<Calculate the average pooling size for a given input tensor.r7   r/   s    r	   Úcalculate_avgpoolr@   M   s   € ä×Ñœs :›Ð/Ó0Ð0r   c                 óT   — d}| |z   }t        j                  t        ||z  «      g«      S )zOCalculate FLOPs for adaptive average pooling given kernel size and output size.r   r7   )r   r   r<   Ú	kernel_ops       r	   Úcalculate_adaptive_avgrC   R   s/   € à€IØ˜iÑ'€IÜ×Ñœs 9¨{Ñ#:Ó;Ð<Ó=Ð=r   Úmodec                 óš   — |}| dk(  r|dz  }n | dk(  r|dz  }n| dk(  r|dz  }n
| dk(  r|dz  }t        j                  t        |«      g«      S )	z]Calculate the operations required for various upsample methods based on mode and output size.Úbicubici  Úbilinearé   Úlinearé   Ú	trilinearé   r7   )rD   r   r=   s      r	   Úcalculate_upsamplerM   Y   se   € à€IØˆyÒØ�XÑ‰	Ø	�Ò	Ø�R‰‰	Ø	�Ò	Ø�Q‰‰	Ø	�Ò	Ø�ZÑˆ	Ü×Ñœs 9›~Ð.Ó/Ð/r   c                 óF   — t        j                  t        | |z  «      g«      S )zTCalculate the linear operation count for given input feature and number of elements.r7   )Ú
in_featureÚnum_elementss     r	   Úcalculate_linearrQ   g   s    € ä×Ñœs :°Ñ#<Ó=Ð>Ó?Ð?r   c                 óŒ   — t        j                  | «      } t        j                  |«      }t        j                  | «      |d   z  S )z`Calculate the total number of operations for matrix multiplication given input and output sizes.éÿÿÿÿ)ÚnpÚarrayÚprod)r   r   s     r	   Úcounter_matmulrW   l   s6   € ä—‘˜*Ó%€JÜ—(‘(˜;Ó'€KÜ�7‰7�:Ó ¨R¡Ñ0Ð0r   c                 ó   — | S )z^Calculate the total number of operations for element-wise multiplication given the input size.r   r/   s    r	   Úcounter_mulrY   s   ó   € àÐr   c                 ó   — | S )z\Computes the total scalar multiplications required for power operations based on input size.r   r/   s    r	   Úcounter_powr\   x   rZ   r   c                 ó   — | S )ziCalculate the total number of scalar operations required for a square root operation given an input size.r   r/   s    r	   Úcounter_sqrtr^   }   rZ   r   c                 ó   — | S )z]Calculate the total number of scalar operations for a division operation given an input size.r   r/   s    r	   Úcounter_divr`   ‚   rZ   r   )FF)r)   ÚnumpyrT   r   r
   r   r   r   Úlistr4   Úboolr'   r-   r0   r2   ÚTensorr5   r>   r@   rC   ÚstrrM   rQ   rW   rY   r\   r^   r`   r   r   r	   ú<module>rf      sÂ   ðó ã Û òòò
Gò
#ð puñPØðPØ#'ðPØ6:ðPØDGðPØOSðPØhlóPòYò0ò
ð
1˜uŸ|™|ó 1ò0ò1ò
>ð0˜Só 0ò@ò
1òò
ò
ó
r   