
    %Vji.                       d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z	m
Z
 erddlmZmZmZmZmZmZ d Zd	 Zed2d
dd3d            Ze	 	 d4d
dd5d            Ze	 	 d4d
dd5d            Ze	 	 	 d6ddd7d            Ze	 	 	 d6ddd7d            Ze	 	 	 	 	 d8d9d            ZeZe	 	 	 	 	 d8d9d            ZeZe	 	 	 d6d5d            Ze	 	 	 	 	 	 d:d;d"            Ze	 	 	 	 	 	 d:d;d#            ZeZ e	 	 	 	 d<ddd=d$            Z!e	 	 	 	 	 d>ddd=d%            Z"e	 	 	 	 	 d>ddd=d&            Z#	 	 	 d?d@d'Z$	 	 	 d?d@d(Z%e%Z&	 	 	 d6d
ddAd*Z'	 	 	 	 	 dBdd,dCd/Z(	 	 	 	 	 dBdd,dCd0Z)	 	 	 	 dDdEd1Z*dS )FzImplementation of reduction operations, to be wrapped into arrays, dtypes etc
in the 'public' layer.

Anything here only deals with torch objects, e.g. "dtype" is a torch.dtype instance etc
    )annotationsN)OptionalTYPE_CHECKING   )_dtypes_impl_util)	ArrayLikeAxisLike	DTypeLikeKeepDimsNotImplementedTypeOutArrayc                H     t          j                   d fd	            }|S )z
    Generically handle axis arguments in reductions.
    axis is *always* the 2nd arg in the function so no need to have a look at its signature
    Nc                    |t          j        || j                  }|dk    r2t          j        | j        d          }|                     |          } d} | |g|R i |S )N r   axisr   )r   normalize_axis_tuplendimexpand_shapeshapereshape)ar   argskwdsnewshapefuncs        W/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/_numpy/_reductions_impl.pywrappedz"_deco_axis_expand.<locals>.wrapped$   sw    -dAF;;D2:: )!':::H		(##ADtAt+d+++d+++    N)	functoolswraps)r   r    s   ` r   _deco_axis_expandr%      s?     _T, , , , , , Nr!   c                Z    | |} | j         s| j        st          j                    j        S | S )a$  Return a dtype that is real or complex floating-point.

    For inputs that are boolean or integer dtypes, this returns the default
    float dtype; inputs that are complex get converted to the default complex
    dtype; real floating-point dtypes (`float*`) get passed through unchanged
    )is_floating_point
is_complexr   default_dtypesfloat_dtype)dtypeother_dtypes     r   _atleast_floatr-   5   s:     }# 9u'7 9*,,88Lr!   F)keepdimsr   r	   r   r
   r.   r   c               ,    |                      |          S r"   )count_nonzero)r   r   r.   s      r   r0   r0   C   s    ??4   r!   outOptional[OutArray]c                  |                                  rt          d| j         d          t          j        |          }| j        t
          j        k    r|                     t
          j                  } t          j	        | |          S )Nzargmax with dtype=.)
r(   NotImplementedErrorr+   r   allow_only_single_axistorchbooltouint8argmaxr   r   r1   r.   s       r   r;   r;   H   u     	||~~ C!"Aqw"A"A"ABBB'--Dw%*DD<4   r!   c                  |                                  rt          d| j         d          t          j        |          }| j        t
          j        k    r|                     t
          j                  } t          j	        | |          S )Nzargmin with dtype=r4   )
r(   r5   r+   r   r6   r7   r8   r9   r:   argminr<   s       r   r?   r?   \   r=   r!   )wherer@   r   c               ^    t          j        |          }|i nd|i}t          j        | fi |S Ndim)r   r6   r7   anyr   r   r1   r.   r@   axis_kws         r   rD   rD   p   =     '--DLbbudmG9Q""'"""r!   c               ^    t          j        |          }|i nd|i}t          j        | fi |S rB   )r   r6   r7   allrE   s         r   rI   rI   ~   rG   r!   initialc                    |                                  rt          d| j                   |                     |          S )Nzamax with dtype=)r(   r5   r+   amaxr   r   r1   r.   rJ   r@   s         r   rL   rL      >     	||~~ @!">QW">">???66$<<r!   c                    |                                  rt          d| j                   |                     |          S )Nzamin with dtype=)r(   r5   r+   aminrM   s         r   rP   rP      rN   r!   c                X    |                      |          |                     |          z
  S r"   )rL   rP   r<   s       r   ptprR      s#     66$<<!&&,,&&r!   r+   Optional[DTypeLike]c                    |t          |t          j                  sJ |t          j        k    rt	          j                    j        }|i nd|i} | j        dd|i|S NrC   r+   r   )
isinstancer7   r+   r8   r   r)   	int_dtypesumr   r   r+   r1   r.   rJ   r@   rF   s           r   rX   rX      sj     =Juek::==:
+--7LbbudmG15((u((((r!   c                    t          j        |          }|t          j        k    rt	          j                    j        }|i nd|i} | j        dd|i|S rU   )r   r6   r7   r8   r   r)   rW   prodrY   s           r   r[   r[      s`     '--D
+--7LbbudmG16))))))r!   c               ^    t          || j                  }|i nd|i} | j        dd|i|}|S rU   )r-   r+   mean)r   r   r+   r1   r.   r@   rF   results           r   r]   r]      sG     5!'**ELbbudmGQV++%+7++FMr!   c                   |}t          || j                  }t          j        | |          }|                    ||          }	t          j        |	|          S N)rC   
correction)r-   r+   r   cast_if_neededstd
r   r   r+   r1   ddofr.   r@   in_dtypetensorr^   s
             r   rc   rc      T     H5!'**E!!U++FZZDTZ22F111r!   c                   |}t          || j                  }t          j        | |          }|                    ||          }	t          j        |	|          S r`   )r-   r+   r   rb   varrd   s
             r   rj   rj     rh   r!   c                    |t           j        k    rt          j                    j        }|| j        }t          j        | |          \  \  } }t          j        || j	                  }| 
                    ||          S Nr   )r   r+   )r7   r8   r   r)   rW   r+   r   axis_none_flattennormalize_axis_indexr   cumsumr   r   r+   r1   s       r   ro   ro     ss     
+--7}(666JDQ$%dAF33D88U8+++r!   c                    |t           j        k    rt          j                    j        }|| j        }t          j        | |          \  \  } }t          j        || j	                  }| 
                    ||          S rl   )r7   r8   r   r)   rW   r+   r   rm   rn   r   cumprodrp   s       r   rr   rr   /  ss     
+--7}(666JDQ$%dAF33D99$e9,,,r!   weightsc               |   |Ut          | |          }t          j        |                                 |                                z  |j                  }n| j        j        s|                                 } | j        |j        k    r|t          d          |j	        dk    rt          d          |j        d         | j        |         k    rt          d          t          j        || j	        dz
  dz  |j        z             }|                    d	|          }t          j        | |          }t          | |z  ||          }t          |||          }||z  }|rt!          j        ||| j	                  }|r@|j        |j        k    r,t          j        ||j                                                  }||fS |S )
Nr   )r+   z;Axis must be specified when shapes of a and weights differ.r   z81D weights expected when shapes of a and weights differ.r   z5Length of weights not compatible with specified axis.)r   )r]   r7   	as_tensornumelr+   r'   doubler   	TypeErrorr   
ValueErrorbroadcast_toswapaxesr   result_type_implrX   r   apply_keepdimsclone)	r   r   rs   returnedr.   r^   wsumresult_dtype	numerators	            r   averager   C  s    ad###qwwyy6<<>>9NNNw( 	

A 7gm##|Q   |q  N   }Q174=00 K  
 (16A:2E2UVVG&&r400G $4Q@@GT>>>	7D555T!  <%fdAF;; :%%%dFL99??AADt|r!   linear)interpolationqr   c                  |r	 | j         j        s-t          j                    j        }|                     |          } | j         t          j        k    r|                     t          j                  } |+| 	                                } |	                                }d}nt          j        || j                  }t          j        |          }t          j        || j                   }t          j        | |||          S )Nr   )r   r   )r+   r'   r   r)   r*   r9   r7   float16float32flattenr   r   r   r6   rb   quantile)	r   r   r   r1   overwrite_inputmethodr.   r   r+   s	            r   r   r   x  s      
 	7$ +--9DDKK 	w%-DD|IIKKIIKK)$77
 '--DQ((A>!QT@@@@r!   c          	         t          j        |j                  t          k    r+|                    t          j                    j                  }|dz  }t          | ||||||          S )Ng      Y@)r   r   r   r.   r   )r   python_type_for_torchr+   intr9   r)   r*   r   )	r   r   r   r1   r   r   r.   r   qqs	            r   
percentiler     sn     )!'22c99DD,..:;;	
UB	
'#   r!   c                P    t          | t          j        d          ||||          S )Ng      ?)r   r   r1   r.   )r   r7   rv   )r   r   r1   r   r.   s        r   medianr     s7     	'   r!   r"   )r   r	   r   r
   r.   r   )NN)r   r	   r   r
   r1   r2   r.   r   )NNF)
r   r	   r   r
   r1   r2   r.   r   r@   r   )NNFNN)r   r	   r   r
   r1   r2   r.   r   rJ   r   r@   r   )NNNFNN)r   r	   r   r
   r+   rS   r1   r2   r.   r   rJ   r   r@   r   )NNNF)r   r	   r   r
   r+   rS   r1   r2   r.   r   r@   r   )NNNr   F)NNN)r   r	   r   r
   r+   rS   r1   r2   )r   r	   rs   r	   )NNFr   F)r   r	   r   r	   r   r
   r1   r2   r.   r   r   r   )NNFF)r   r	   r1   r2   r.   r   )+__doc__
__future__r   r#   typingr   r   r7    r   r   _normalizationsr	   r
   r   r   r   r   r%   r-   r0   r;   r?   rD   rI   rL   maxrP   minrR   rX   r[   productr]   rc   rj   ro   rr   
cumproductr   r   r   r   r   r!   r   <module>r      s1    # " " " " "     * * * * * * * *  ! ! ! ! ! ! ! !                   .   !u ! ! ! ! ! !  "!
 ! ! ! ! ! !&  "!
 ! ! ! ! ! !&  "	
# !%
# 
# 
# 
# 
# 
#  "	
# !%
# 
# 
# 
# 
# 
#  ""& $       ""& $       "	' ' ' ' '  !%""& $) ) ) ) )$  !%""& $* * * * *$   !%" !%     "  !%"	
2 !%2 2 2 2 2 2"  !%"	
2 !%2 2 2 2 2 20 !%"	, , , , ,& !%"	- - - - -" 

 
	1 1 1 1 1 1 1p "(A )-(A (A (A (A (A (A\ " )-     : 
"      r!   