
    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
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      S/var/www/html/eduruby.in/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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!Uf_5{128OOO!}k"dfn5{12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    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_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'    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   r4   )
batch_size	nfeatures	total_exp	total_add	total_div	total_opss         r	   calculate_softmaxr>   D   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.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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   r7   )rD   r   r=   s      r	   calculate_upsamplerM   Y   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.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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_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

1u|| 101
>0S 0@
1


r   