
    |h
                         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
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      T/var/www/html/test/engine/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#     Fau!!1::<.1Fs   .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    qc""r   
input_sizeoutput_sizekernel_sizegroupsbiasc                 P    | 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!   in_cgs          r	   calculate_conv2d_flopsr&       s6     a=DA+$!),vk!"o/FFFr   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    MM12{j5.@;.NQU.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_normr/   /   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_flopsr1   4   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_relur4   9   s'    MM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   r3   )
batch_size	nfeatures	total_exp	total_add	total_div	total_opss         r	   calculate_softmaxr=   ?   sA    IAIIi)3i?@Is9~.//r   c                 @    t        j                  t        |       g      S )z<Calculate the average pooling size for a given input tensor.r6   r.   s    r	   calculate_avgpoolr?   H   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   r6   )r   r   r;   	kernel_ops       r	   calculate_adaptive_avgrB   M   s/    Ii'Is9{#:;<==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   r6   )rC   r   r<   s      r	   calculate_upsamplerL   T   se    IyX			R			Q			Z	s9~.//r   c                 F    t        j                  t        | |z        g      S )zTCalculate the linear operation count for given input feature and number of elements.r6   )
in_featurenum_elementss     r	   calculate_linearrP   b   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_matmulrV   g   s6    *%J((;'K77: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_mulrX   n       r   c                     | S )z\Computes the total scalar multiplications required for power operations based on input size.r   r.   s    r	   counter_powr[   s   rY   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]   x   rY   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_   }   rY   r   )F)r(   numpyrS   r   r
   r   r   r   listr3   boolr&   r,   r/   r1   Tensorr4   r=   r?   rB   strrL   rP   rV   rX   r[   r]   r_   r   r   r	   <module>re      s      
G
#
Gt G$ GT G[^ Gfj GY0

1u|| 101
>0S 0@
1


r   