
    sg\Q                    3   U d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZmZmZ d dlZd dlmZ d dlZd dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 ejn                  jq                  dd      Z9ejn                  jq                  ddd      Z:ejn                  jq                  ddd      Z;ejn                  jq                  ddd      Z<ejn                  jq                  ddd      Z=g dZ>	 d|dddddde	ee$ej(                  f      de	e&   de	e'   de	ej~                     de	eej                  eAf      f
dZBdddd d!eAd"ee%ee%d#f   f   d$ed%ed&eAd'e	e
ej                        d(eDd)eDfd*ZE G d+ d,e      ZFdd-d.eFd/e	ee)d#f      d0e.fd1ZGd2 ZHd3eAd.eFfd4ZId3eAd.eFfd5ZJd6 ZK eId7ej                  d8eFj                  9      ZL eId:ej                  d8eFj                  9      ZN eId;ej                  d8eFj                  9      ZP eId<ej                  d8eFj                  9      ZQ eId=ej                  d8eFj                  9      ZR eId>ej                  d8eFj                  9      ZS eId?ej                  d8eFj                  9      ZT eId@ej                  d8eFj                  9      ZU eIdAej                  d8eFj                  9      ZV eIdBej                  j                  d8eFj                  9      ZX eIdCej                  j                  d8eFj                  9      ZY eIdDej                  d8eFj                  9      Z[ eIdEej                  j                  d8eFj                  9      Z] eIdFej                  j                  d8eFj                  9      Z_ eIdGej                  j                  d8eFj                  9      Za eIdHej                  d8eFj                  9      ZbdIej(                  d0efdJZc eIdKecd8eFj                  9      Zd eIdLej                  d8eFj                  9      ZedMe)d0e)fdNZf eEdOefej                  dPe%j                  Q      Ziej                  dRdMe)dSej                  d0e)fdTZl eEdUelej                  dVe%j                  dWX      Zm eIdYej                  d8eFj                  9      Zn eIdZej                  d8eFj                  9      Zo eId[ej                  j                  d8eFj                  9      Zq eId\ej                  j                  d8eFj                  9      Zr eId]ej                  j                  d8eFj                  9      Zs eId^ej                  d8eFj                  9      Zt eId_ej                  j                  d8eFj                  9      Zu eId`ej                  j                  d8eFj                  9      ZvdIe)dae$d0e)fdbZw eEdce%j                  ewej                  d8d      Zx eIdeej                  d8eFj                  9      Zy eEdf eeHeFj                  g      e%j                  ej                  d8h      Z{ eIdiej                  d8eFj                  9      Z| eIdjej                  d8eFj                  9      Z~ eIdkej                  d8eFj                  9      Z eIdlej                   d8eFj                  9      Z eIdmej                  d8eFj                  9      Z eIdnej                  d8eFj                  9      Z eEdo eeHeFj                  g      e%j                  ej                  d8h      Z eIdpej                  d8eFj                  9      Z eIdqej                  j
                  d8eFj                  9      Z eIdrej                  d8eFj                  9      Z eIdsej                  d8eFj                  9      Z eIdtej                  d8eFj                  9      Z eIduej                  d8eFj                  9      Z eIdvej                  d8eFj                  9      Z eIdwej                  d8eFj                  9      Z eIdxej                  d8eFj                  9      Z eIdyej                  j                  d8eFj                  9      Z eIdzej                  d8eFj                  9      Z eId{ej                  d8eFj                  9      Z eId|ej                   d8eFj                  9      Z eId}ej"                  d8eFj                  9      Z eJd~ej$                  d8eFj                        Z eJdej&                  d8eFj                        Z eJdej(                  d8eFj                  9      Z eJdej*                  d8eFj                  9      Z eJdej,                  d8eFj                  9      Zd Z eJded8eFj                  9      Z eJdej2                  d8eFj                  9      Z eJdej4                  d8eFj                  9      Z eJdej6                  d8eFj                  9      Z eJdej8                  d8eFj                  9      Z eJdej:                  d8eFj                  9      Z eJdej<                  d8eFj                  9      Z eJdej>                  d8eFj                  9      Z eJdej@                  d8eFj                  9      Z eJdej                  jB                  d8eFj                  9      Z eJdej                  jF                  d8eFj                  9      Z eJdejJ                  d8eFj                  9      Z eJdejL                  d8eFj                  9      ZdIee)e$f   dee)e$f   d0e)fdZ eJded8eFj                  9      ZdIee)e$f   dee)e$f   d0e)fdZ eJded8eFj                  9      Z eJdejV                  d8eFj                  9      Z eJdejX                  d8eFj                  9      Z eJdejZ                  d8eFj                  9      Z eJdej\                  d8eFj                  9      Z eJdej^                  d8eFj                  9      Z eJdej`                  d8eFj                  9      Z eJdejd                  d8eFj                  9      ZeKZ eJdejj                  d8eFj                  9      Z eJdej                  jl                  d8eFj                  9      ZdIe)de&de'ded0e)f
dZdIede&de'ded0ef
dZdZ eEdeee%j                  e      ZdIe)de&de
e   fdZd ZdZ eEdeee%j                  e      ZdIededed0dfdZde&deded0eed#f   fdZdIe)deded0ee	e&   e	e'   f   fdZdIe)deded0e)fdZdIededed0efdZdZ eEdeee%j                  eŬ      ZdIe)d0e)fdZdZ eEdeej                  e%j                  eȬ      Z	 d|dIe)de d0e)fdZeZee   ed<   	 d|dIe)de de de	e'   d0e)f
dZ	 d|dIede de de	e'   d0ef
dZdZ eEdeee%j                  eЬ      Z	 	 d}dIe)dedededed0e)fdńZ	 	 d}dIededededed0efdƄZdZ eEdeee%j                  eӬ      ZdIe)deded0e)fd˄ZdIededed0efd̄ZdZ eEdeee%j                  e׬      ZdIe)de
d0e)fdτZdZ eEdeej                  e%j                  eڬ      ZdIe)de d0e)fdӄZdIede d0efdԄZdZ eEdeee%j                  eެ      ZdIe)d0e)fdׄZdIed0efd؄ZdZ eEdeee%j                  e⬧      ZdIe)dej~                  d0e)fdۄZdIedej~                  d0efd܄ZdZ eEdeee%j                  e欧      ZdMe)de)de&de'ded0e)fdZdZ eEdeej                  e%j                  e鬧      ZdIededed0efdZdIededed0efdZdZ eEdeee%j                  e      Zde
e)   ded0e)fdZdeeed#f   ee   f   ded0efdZdZ eEdeee%j                  e񬧫      ZdIe)de&fdZdIede&d0efdZdZ eEdeee%j                  e      ZdIe)de d0e)fdZdZ eEdeej                  e%j                  e      Zde)dIe)de)d0e)fdZdZ eEdeej                  e%j                  e      ZdIe)dej~                  d0e)fdZdIedej~                  d0efdZdZ  eEdeee%j                  e ej                  j                  f      ZdIe)deeAej                  f   d0e)fdZdIedeeAej                  f   d0efdZdZ eEd eee%j                  e      ZdIe)d0e.fdZdZ eEdeej(                  j                  e%j                  e      Z	dej~                  d0e.fdZ
dej~                  fdZdZ eEde
ee%j                  e      Zdej~                  d0e.fdZdej~                  fd	Zd
Z eEdeee%j                  e      ZdIe)de)fdZdIeded0efdZdZ eEdeee%j*                  edW      ZdIe)de&fdZdIede&d0efdZdZ eEdeee%j                  e      ZdIe)de&fdZdIede&d0efdZdZ eEdeee%j*                  e      ZdddZd Z dZ!dZ"dZ#dZ$d Z%d!Z&d3eAfd"Z'd3eAfd#Z( e'd$ejR                  e!%      Z)dd&d'e)de	e    de	ej~                     d0efd(Z* e'd)e*e"%      Z+dd&d'e)de	e    de	ej~                     d0efd*Z, e'd+e,e#%      Z-d~d,Z. e(d-e.e&%      Z/ e'd.ej`                  e$%      Z0 e'd/ejb                  e%%      Z1d0Z2d1eded2edej~                  dej                  d3eDd0e)fd4Z3d1eded2edej~                  dej                  d3eDd0e)fd5Z4 eEd6e%j                  e3e4e2d      Z5de&dej~                  dej                  d3eDd0e)f
d7Z6de&dej~                  dej                  d3eDd0ef
d8Z7d9Z8 eEd:e6e7e%j                  e8      Z9de&de'dej~                  dej                  d3eDd0e)fd;Z:d<Z; eEd=e%j                  e:ejx                  e;d      Z<de&d>e dej~                  dej                  d3eDd0e)fd?Z=d@Z> eEdAe%j                  e=ej~                  e>d      Z?de&dBe$dej~                  dej                  d3eDd0e)fdCZ@de&dBe$dej~                  dej                  d3eDd0efdDZAdEZB eEdFe@eAe%j                  eB      ZCdIe)dBe$dej~                  dej                  d3eDd0e)fdGZDdIedBe$dej~                  dej                  d3eDd0efdHZEdIZF eEdJeDeEe%j                  eF      ZGdKe$dej~                  dej                  d0e)fdLZHdKe$dej~                  dej                  d0efdMZIdNZJ eEdOeHeIe%j                  eJ      ZKdPe)dQeDd0ee)e)e)f   fdRZLdPe)dQeDd0eeeef   fdSZMdTZN eEdUeLeMe%j                  e%j                  e%j                  feN      ZOddVde&dWeePeQf   dXePdej~                  dej                  d3eDdYe	ej                     d0e)fdZZSddVde&dWeePeQf   dXePdej~                  dej                  d3eDdYe	ej                     d0efd[ZTd\ZU eEd]e%j                  eSeTeUd      ZVddVde&d^ePd_ePdej~                  dej                  dYe	ej                     d0e)fd`ZWddVde&d^ePd_ePdej~                  dej                  dYe	ej                     d0efdaZXdbZY eEdce%j                  eWeXeYd      ZZdMe(de ddeDd0e)fdeZ[dMe(de ddeDd0e)fdfZ\dgZ] eEdhe[e\e%j                  e]      Z^dMe(de dieDd0e)fdjZ_dMe(de dieDd0e)fdkZ`dlZa eEdme_e`e%j                  ea      ZbdMe(de dned0e)fdoZcdMe(de dned0e)fdpZddqZe eEdrecede%j                  ee      Zfdse)d0ee)e)f   fdtZg eEduege%j                  e%j                  fej                  d8h      Zhd0e)fdvZi eEdweie%j                  eidxh      ZjddyZk eEdzeke%j                  ekd{h      Zm e         e        y(      N)Enum)partialreduce)CallableListOptionalSequenceTupleTypeUnion)	sym_floatTensor)_get_default_devicenew_token_tensor)is_functional_schema)register_debug_prims)register_rng_prims)DimDimsSequenceTypeDimsTypeIntLikeNumber
NumberTypeRETURN_TYPE	ShapeType
StrideType
TensorLikeTensorLikeTypetype_to_dtypebackwards_not_supported)
FakeTensorFakeTensorMode)handle_torch_functionhas_torch_function)tree_flattentree_maptree_unflattenprimsDEFIMPLCompositeExplicitAutogradBackendSelectAutogradMeta)r   absacosacoshasinasinhatanatanhcoscosh	bessel_i0
bessel_i0e	bessel_i1
bessel_i1e	bessel_j0	bessel_j1bitwise_notcbrtceilconj_physicaldigammaerferf_inverfcerfcxexpexpm1exp2fillfloorimagisfinitelgammaloglog1plog2log10ndtrinegreal
reciprocalroundsignsignbitsinsinhspherical_bessel_j0sqrttantanhtruncaddatan2bitwise_and
bitwise_orbitwise_xordiveqfmaxfminfmodfrexpgcdgegthypotigammaigammacleltmaximumminimummulne	nextafterpow	remainderrsqrt
shift_leftshift_right_arithmeticshift_right_logicalsubzeta
as_stridedbroadcast_in_dimcollapse_viewconjexpand_dimssliceslice_in_dim	split_dimsqueeze	transposeview_ofview_element_typeas_strided_scattercollapsecatreshaperevwherecloneconvert_element_type
device_putitemmaximum_valueminimum_valuecopy_stridedcopy_toresizeamaxaminprodsumxor_sumvarempty_stridedempty_permutedscalar_tensoriotasvdnormal_uniform_helperfft_r2cfft_c2cfft_c2r_make_token_sink_tokensshapestridesdtypedevice
tensorliker   r   r   r   c                   t        | t              rZ|s|t        |t              sJ |s|t        |t              sJ d}d}t        t	        |             }t        j                  d      }nu| ct        | t
        j                        sJ t        | j                        }t        | j                               }| j                  }| j                  }n|J |J |J |J |n
t        |      }|n
t        |      }|n|}|n|}t        |t              rt        j                  |      }t        j                  ||||      S )N cpur   r   )
isinstancer   r	   r    typetorchr   r   tupler   strider   strr   )	r   r   r   r   r   inferred_shapeinferred_stridesinferred_dtypeinferred_devices	            H/var/www/html/venv/lib/python3.12/site-packages/torch/_prims/__init__.py
TensorMetar      sN    *f%emz%/JKK:gx3PQQ*,,.&tJ'78,,u- 
	*ell333z//0 !2!2!45#))$++    """   !!!#mNuE")/uW~G#mNE &_FF&#f%ugU6JJ    F)tagsuse_old_custom_ops_apiregister_conj_neg_fallthroughschemareturn_type.meta	impl_atendocr   r   r   c                 J   fdfd}fd}	| j                  d      d   }
| t        |
      d } t        j                  j	                  |
| z         }|st        |      svt        j                  |
| z   t        j                  j                         t        j                  |
       t        j                  |
|       t        j                  |
       ng }|j                  D ]A  }|j                  |j                  j                   s'|j#                  |j$                         C t        j&                  j)                  d|
z   t+        |      | 	      }|j-                         |t.        j0                  k(  s|rj|j2                  j                  |
t        j&                  j4                  d
       |j2                  j                  |
t        j&                  j4                  d       t7        t        j8                  j:                  j<                  |
      }|j>                  |r|_         nt7        t        j:                  jB                  |
d      x}r|jE                         D cg c]  }t7        ||      jF                   }}tI        |d          jJ                  |dd   jM                  t        j                  jN                         jM                  t        j                  jP                         t+        fd|d   D              _         ddl)m* tW        fdjX                  j                  D              rt[              dv rt\        j                  |
|	       |fD ],  }||_/        ||_0        | |_1        |_
        |_        |_2        . S c c}w )z)
    Creates a primitive operation.

    c                  $     | i |  | i |S Nr   )argskwargsr   r   s     r   
_prim_implz_make_prim.<locals>._prim_impl  s"     	df$)&))r   c                  &     t              | i |S r   r!   )r   r   _prims     r   _autograd_implz"_make_prim.<locals>._autograd_impl%  s    -&u-t>v>>r   c                      |j                  d      r|d   j                  dk(  r | i |S t        d | D              r | i |S  | i |S )Nr   r   c              3   r   K   | ]/  }t        |t        j                        xr |j                  d k(   1 yw)r   N)r   r   r   r   ).0xs     r   	<genexpr>z;_make_prim.<locals>._backend_select_impl.<locals>.<genexpr>+  s,     NAz!U\\*?qvv/??Ns   57)getr   any)r   r   r   r   s     r   _backend_select_implz(_make_prim.<locals>._backend_select_impl(  s_    ::hF8$4$9$9V$C(((NNN(((t.v..r   (r   N)r   zprims::)mutates_argsr   	ConjugateNegative   c              3   ,   K   | ]  }|v s|  y wr   r   )r   ttags_intersections     r   r   z_make_prim.<locals>.<genexpr>^  s     R!1@Q;QARs   	)contains_tensor_typesc              3   B   K   | ]  } |j                           y wr   )r   )r   ar   s     r   r   z_make_prim.<locals>.<genexpr>b  s     N$QVV,Ns   )zprims.device_put.default)3splitlenr   _Cparse_schemar   primdefineTagpt2_compliant_tag	prim_implimplprim_autograd_implprim_meta_impl	arguments
alias_infois_writeappendnamelibrary	custom_opr   register_faker   VIEW_libfallthrough_kernelgetattr_opsopsr*   default_tagsaten	overloadsr   setintersection_updatediscardcoredata_dependent_outputtorch._subclasses.fake_tensorr   r   _schemar   prim_backend_select_impl__doc__r   r   r   )r   r   r   r   r   r   r   r   r   r   r   
cpp_schemar   argprim_def_prim_packetaten_packetoverloadoverload_tagspr   r   r   r   s     ``                @@@@r   
_make_primr  
  s    *?/ <<QDCIK F &&tf}5J%9*%ED6M		(C(CDtZ(n5D$''' 	.C~~)cnn.E.E##CHH-	. ==**|,	 + 
 	t$ +***.KMMtU]]%E%E{SMMtU]]%E%EzR5::>>//6L  E		d;	;	;@K@U@U@W
4<GK*//
 
  a 01---}QR/@A 	!!%))..1 	!!%))"A"AB R}Q'7RRCNemm6M6MNNRUS
S 	!%%d,@AE"  	#   LE
s   -N c                       e Zd ZdZdZdZdZy)$ELEMENTWISE_PRIM_TYPE_PROMOTION_KIND)r   )   )   )   N)__name__
__module____qualname__DEFAULTINT_TO_FLOATALWAYS_BOOLCOMPLEX_TO_FLOATr   r   r   r  r  v  s    GLKr   r  )args_with_fixed_dtypestype_promotionr'  returnc                    t        |      dkD  sJ t        j                  |  t        |      }|t        |      |z   }t        j                  |ddi t        j
                  |ddi t        j                  | }t        j                  |ddi}d}d}|D ]^  }t        |t              r0t        j                  |      s|j                  } n+|j                  }Ct        |t              sTt        |      }` ||t        j                  |      }d}	d}
|D ][  }t        |t              r3t        j                  |      r|	+|j                  }	8|j                  }	 nt        |t              sW|
Z|}
] |	|J | t         j"                  k(  r|}n| t         j$                  k(  rt&        j(                  }n| t         j*                  k(  r?t        j,                  |      st        j.                  |      rUt'        j0                         }n@| t         j2                  k(  r-t        j4                  |      rt        j6                  |      }n|}|J t'        j8                  |||	|      S d}t        |
t&        j:                  t&        j<                  f      rs|D ]a  }t        |t>        t@        t&        j:                  t&        j<                  f      sJ d       |xs  t        |t@        t&        j<                  f      }c |rtC        |
      }
tE        |
      S )z
    Meta function for elementwise operations that produce outputs in the same dtype
    as their inputs.

    Stride logic is currently incorrect.
    r   Nallow_cpu_scalar_tensorsT)r   r   FNYI)#r   utilscheck_same_dtypelistcheck_same_devicecheck_same_shape3compute_elementwise_output_logical_to_physical_permextract_shaper   r   is_cpu_scalar_tensorr   r   r   r    r   r  r#  r%  r   boolr$  is_integer_dtypeis_boolean_dtypeget_default_dtyper&  is_complex_dtypecorresponding_real_dtyper   SymIntSymFloatintfloatr   r   )r(  r'  r   args_l2p_permr   r   scalar_typer  r   number
seen_floatr   s                r   _prim_elementwise_metarD  ~  s    t9q==	D!JE)+,u4	UBTB	EADAHH%PHFFE EK $c:&--c2				V$s)K$ }0##K0 FF c:&))#.> ZZF V$~"    AIIIECOOOJJECPPP%%e,0F0Fu0M//1CTTT%%e,66u=   ##E8F%PP J&5<<89 	NAa#uellENN!KLSeSL#Mz!eU^^5L'MJ	N v&Ffr   c                      t        j                  t        j                  | d   j                        d        t        | i |S )Nr   c                       y)NzOnly complex dtype is supportedr   r   r   r   <lambda>z0_complex_only_elementwise_meta.<locals>.<lambda>      r   )r   _checkr-  r9  r   rD  r   r   s     r   _complex_only_elementwise_metarK    s9    	LLtAw}}-/X "42622r   r   c                `    t        d|  dt        t        |      t        j                  d|S )z,
    Creates an elementwise unary prim.
    z(Tensor self) -> Tensorr(  r   r   r   r   r  r   rD  r   NEWr   r(  r   s      r   _make_elementwise_unary_primrR    s=      ./+NKOO 	 r   c                `    t        d|  dt        t        |      t        j                  d|S )z-
    Creates an elementwise binary prim.
    z%(Tensor self, Tensor other) -> TensorrM  rN  r   rO  rQ  s      r   _make_elementwise_binary_primrT    s=      <=+NKOO 	 r   c                      t         r   NotImplementedErrorrJ  s     r   	_not_implrX    s    
r   r1    )r   r   r(  r2   r3   r4   r5   r6   r7   r8   r9   r>   r?   r:   r;   r<   r=   r@   r   c                     t        j                  | j                          d        t        j                  t        j                  | j                         d      |       S )Nc                       y)NzJcbrt: Complex inputs not supported. Consider calling torch.pow(a, 1.0/3.0)r   r   r   r   rG  z_cbrt_aten.<locals>.<lambda>  rH  r   gUUUUUU?)r   rI  
is_complexcopysignr{   r1   r   s    r   
_cbrt_atenr_  |  sA    	LLLLN\ >>%))AEEGU3Q77r   rA   rB   inputc                     | j                   j                  st        d      t        j                  |       }t        | |      S )Nz6prims.conj_physical is only defined for complex dtypes)r   )r   r\  RuntimeErrorr-  "compute_elementwise_output_stridesr   )r`  r   s     r   _conj_physical_metard    s8    ;;!!STT66u=GeW--r   z$conj_physical(Tensor self) -> Tensorz4Returns the physical conjugation of a complex tensor)r   r   r   r   r   memory_formatrf  c                Z   |t         j                  k7  rBt        j                  | j                  | j                  | j
                  | j                  |      S t        j                  |       }t        j                  | j                  || j                  | j
                  | j                        S )N)r   layoutr   rf  )r   rh  r   )
r   preserve_formatemptyr   r   rh  r   r-  rc  r   )r`  rf  r   s      r   _clone_metark    s     ---{{KK++<<<<'
 	
 66u=Gkk|||| r   zAclone(Tensor self, *, MemoryFormat? memory_format=None) -> TensorzReturns the copy of a tensorT)r   r   r   r   r   r   rD   rE   rF   rG   rH   rI   rJ   rK   valuec                 8    t        | t        j                        S )NrM  rD  r  r#  )r   rl  s     r   
_fill_metaro    s    !	>FF r   z)fill(Tensor self, Scalar value) -> Tensor)r   r   r   r   r   rM   z!imag(Tensor(a) self) -> Tensor(a)rM  )r   r   r   r   r   rO   rP   rQ   rR   rS   rT   z!real(Tensor(a) self) -> Tensor(a)rX   rU   rV   rY   r}   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   )r   r   r   r(  rd   re   rf   rg   c                 &   t        | t        t        t        j                  f      xs; t        | t        j
                        xr t        j                  | j                        }|rt        j                  | |d      S t        j                  | |      S )Nrb   )rounding_mode)r   r5  r=  r   r;  r   r-  r6  r   rh   true_divide)r   bis_integrals      r   	_div_atenru    sn    QsELL 9: 1ell#G(>(>qww(G  yyAW55  A&&r   rh   ri   rj   rk   rl   rn   ro   rp   rq   rr   rs   rt   ru   rs  c                 8   t        | t              r3t        |t              r#t        || j                  | j
                        }nBt        |t              r2t        | t              r"t        | |j                  |j
                        } t        j                  | |      S Nr   )r   r   r   r   r   r   r   rv   r   rs  s     r   _maximum_atenry  U  g     !Z Z6%:!177188<	Az	"z!V'<!177188<==Ar   rv   c                 8   t        | t              r3t        |t              r#t        || j                  | j
                        }nBt        |t              r2t        | t              r"t        | |j                  |j
                        } t        j                  | |      S rw  )r   r   r   r   r   r   r   rw   rx  s     r   _minimum_atenr|  h  rz  r   rw   rx   ry   rz   r{   r|   r~   r   r   r   sizer   storage_offsetc                    t        |      t        |      k(  sJ |dk\  sJ t        j                  |       t        j                  |       t	        t
        j                  |      dk(  rn@t        | t        j                        r&t        j                  | j                         |||       t        j                  | |||      S Nr   )r   r-  validate_stridesvalidate_shaper   operatorrx   r   r   r   check_in_bounds_for_storage_typed_storager   r   r}  r   r~  s       r   _as_strided_metar    s     t9F###Q	6"	hllD!Q& 		Au||	$))fn	
 AtV^<<r   c                 2    t        j                  | |||      S r   )r   r   r  s       r   _as_strided_atenr    s     AtV^<<r   zy
    Creates a view of the tensor with the given shape (size), strides (stride) and
    storage offset (storage_offset).
z]as_strided(Tensor(a!) a, SymInt[] size, SymInt[] stride, SymInt storage_offset) -> Tensor(a!)r   r   r   r   r   broadcast_dimensionsc                     ddl m} t         t              sJ t        t              sJ t        |t              sJ  j
                  t        |      k(  sJ t               j
                  k\  sJ fd}t        ||d       t        |      D ]M  \   | j                     dk(        rt        j                   j                        k(   fd       O g }d}t        t                    D ]  |v rU | j                  |      k7        r|j                  d       n"|j                   j                         |          |dz   }\ |   dk7        r|j                  d       || j
                  k(  r|j                  d       |j                   j                         |    j                         |   z           j!                  | j#                               S )Nr   guard_size_obliviousc                 Z    t        |t              sJ || kD  sJ |t              k  sJ |S r   )r   r   r   )accr   r   s     r   _greater_than_reducez4_broadcast_in_dim_meta.<locals>._greater_than_reduce  s3    !S!!!3ww3u:~~r   r   c                  2     j                       d    S )Nz must be broadcastable to r   )r   idxnew_idxr   s   r   rG  z(_broadcast_in_dim_meta.<locals>.<lambda>  s     1773<.(B5>BRS r   )%torch.fx.experimental.symbolic_shapesr  r   r   r	   ndimr   r   	enumerater   r   rI  ranger   r   r}  r   r~  )	r   r   r  r  r  new_stridesoriginal_idxr  r  s	   ``     @@r   _broadcast_in_dim_metar    s    K a$$$eX&&&*H555 66S-.... u:
 !5r: ""67 W#AGGCLA$56LLg.S KLSZ  V&& $AGGL$9U3Z$GH""1%""188:l#;<'!+L#E#J!O4""1%'""1%""188:l#;affh|>T#TUV" <<{A,<,<,>??r   c                     t        |      }|D ]  }d||<   	 | }t        |      D ]  \  }}|dk7  s|j                  |      } |j                  |      S Nr  )r/  r  	unsqueezeexpand)r   r   r  sbroadcast_dimensionvr  r   s           r   _broadcast_in_dim_atenr  !  si    UA3 $!#
$ 	
AA, !Q7C A! 88E?r   aD  
  Creates a view of a with the specified shape.

  Allows adding dimensions of any length and broadcasting
  dimensions of length one in a to any length.

  The location of the broadcast dimensions must be specified
  using the broadcast_dimensions argument. Changing the
  relative order of dimensions is not supported.
  zVbroadcast_in_dim(Tensor(a) a, SymInt[] shape, int[] broadcast_dimensions) -> Tensor(a)startendc                     t        d| j                               }t        j                  |       t        j                  |       t	        j
                  k\  fd       y )Nr   c                      d  d dS )Nz Attempting to collapse but end, z, is less than start, !r   )r  r  s   r   rG  z)_validate_collapse_args.<locals>.<lambda>L  s    23%7MeWTUV r   )maxdimr-  validate_idxr   _check_value)r   r  r  r  s    `` r   _validate_collapse_argsr  B  sN    q!%%'?D	tU#	tS! 
uVr   c                     t        |       dk(  rdn
t        |       } d}| ||dz    D ]  }||z  }	 | d| |fz   | |dz   d z   S )zZ
    Returns the shape of a with dims in [start, end) merged into a single dimension.
    r   r   r   N)r   r   )r   r  r  
dim_lengthr  s        r   _collapsed_shaper  P  sf    
 J!ODuEJ537# $!^
$ 5>ZM)E#'),<<<r   c                    t        | t              sJ ddlm} t	        | ||       | j
                  dk(  rd}d}n| j                  }| j                         }| j
                  dk(  s||k(  r||fS ||   }||   }t        |dz
  |dz
  d      D ]  } |||   dk(        s |||dz      dk(        rd}d} nz |||   dk(        r7|||   z  } ||||   k        r|}n||   } || j                         dkD        so |||dz      dk7        s |||   ||dz      ||dz      z  k(        r y |d | |fz   ||dz   d  z   }	|d | |fz   ||dz   d  z   }
 || j                         dk(        rt        j                  |	      }
|	|
fS )Nr   r  r  r   r  )NN)r   r   r  r  r  r  r   r   r  numelr-  make_contiguous_strides_for)r   r  r  r  r   r   lengthr   r  	new_shaper  s              r   _collapse_view_helperr  ^  s    a$$$JAuc* 	vv{((*vv{se|g~3ZFS\FS1Weai, c
a04H#'Na5
 FFc
a0%*$ 56FS\F !Q/$U37^q%89(a 05q> AA 14 fu	)E#'),<<I&5/VI-a	0BBK AGGIN+77	Bk!!r   c                     t        | ||      \  }}|d}t        |      |J | j                  ||| j                               S )Nz?Attempting to view a collapsed tensor, but no such view exists!)r  
ValueErrorr   r~  )r   r  r  r  r  msgs         r   _collapse_view_metar    sR    21eSAI{Oo"""<<	;0@0@0BCCr   c                 R    t        | j                  ||      }| j                  |      S r   )r  r   viewr   r  r  r  s       r   _collapse_view_atenr    s#     %5I66)r   a  
  Creates a view of a with the dimensions between
  start (inclusive) and end (exclusive) merged into a
  single dimension.

  If it's not possible to take such a view then an error
  is thrown. See collapse instead.

  The dimensions can be merged if and only if
  they are all "nested" with each other. That is, they all
  have the property that

  stride[i] = stride[i+1] * shape[i+1]

  for all i in [start, end - 1).
  z;collapse_view(Tensor(a) a, int start, int end) -> Tensor(a)c                    | j                   j                  st        d      | j                  | j                  | j                         | j                               }t        j                  j                  || j                                 |S )Nz$Expected complex dtype in prims.conj)r   r\  rb  r   r   r   r~  r   r   	_set_conjis_conj)r   outs     r   
_conj_metar    sa    77ABB
,,qww
A,<,<,>
?C	HHs		O,Jr   z2
Returns a conjugated view of the original tensor
zconj(Tensor(a) a) -> Tensor(a)
dimensionsc                    | t        t        j                  ||            }n)t        t        j                  | j                  |            }t	        t        |            t	        |      k7  rdt        |       }t        |      t        | j                        }|D ]  }|j                  |d        t        t	        |            D cg c]	  }||vs| }}t        | ||      S c c}w )z
    Creates a view of a with a.ndim + len(dimensions) dimensions, with new
    dimensions of length one at the dimensions specified by dimensions.
    z+Received duplicate dimensions to expand in r   )sortedr-  canonicalize_dimsr  r   r	  r   r  r/  r   insertr  r   )r   r  r  dimsr  r  r  r  s           r   r   r     s     e--dJ?@e--affjAB
3t9~T";C
O;LMoQWWI !a ! S^,:0E  Ay*>??s   		C&C&pyslicestart_indiceslimit_indicesc                 p   ||ndgt        |      z  }| j                  t        |      k7  r'd| j                   dt        |       d}t        |      | j                  t        |      k7  r'd| j                   dt        |       d}t        |      | j                  t        |      k7  r'd| j                   dt        |       d}t        |      t        || j                        D ]=  \  }}|dk  rd| d}t        |      ||kD  s"d	| d
| j                   }t        |       t        || j                  |      D ]L  \  }}}|dk  rd| d}t        |      ||kD  rd| d| j                   }t        |      ||k  sEd	| d| }N |D ]  }|dk  s	d| d}t        |       g }	t        |||      D ]#  \  }}}|	j                  d||z
  dz
  |z  z          % g }
t        | j                         |      D ]  \  }}|
j                  ||z          | j                  |	|
| j                               S )Nr   z#Attempting to slice tensor of rank z with start_indices of length r  z with limit_indices of length z with strides of length r   z<Attempting to slice a tensor with a negative start index of z2Attempting to slice a tensor but a start index in zD is greater than the length of its corresponding dimension in shape z;Attempting to slice a tensor with a negative stop index of z1Attempting to slice a tensor but a stop index in zE is greater than the length of  its corresponding dimension in shape z/ is greater than  its corresponding stop index z9Attempting to slice a tensor with a non-positive step of )	r   r  r  zipr   r   r   r   r~  )r   r  r  r   _stridesr  r   yzr  r  s              r   _slice_metar    s    "-wA3]9K3KHvv]##3AFF8;YZ]^kZlYmmnoovv]##3AFF8;YZ]^kZlYmmnoovvX3AFF8;STWXeTfSgghioM177+ 	"1q5PQRPSSTUCS/!q5D]O TGGHwwiQ  S/!	" }agg}= 1aq5OPQsRSTCS/!q5CM? S99:	C  S/!q5DQC H1125    "6MaSPQRCS/!"
 I}mX> /1aa!eaiA--./ KAHHJ) "11q5!" <<	;0@0@0BCCr   c                     ||ndgt        |      z  }g }t        |||      D ]"  \  }}}|j                  t        |||             $ t	        j
                  | |      S Nr   )r   r  r   r  r  getitem)	r   r  r  r   r  slicesr  stopsteps	            r   _slice_atenr  4  sj     "-wA3]9K3KHF xH 2tTgeT4012 Av&&r   a  
    Creates a view of a "bounding box" within the tensor.

    The bounding box is specified independently in each of the tensor's dimensions.
    start_indices and limit_indices describe the box's boundaries for their corresponding
    dimensions. If strides is specified then they specify the step size between elements
    in their corresponding dimension.

    This operation is analogous to slicing in NumPy, but does not permit slices where
    the stop indices are less than the start indices.
    zgslice(Tensor(a) a, SymInt[] start_indices, SymInt[] limit_indices, SymInt[]? strides=None) -> Tensor(a)start_indexlimit_indexaxisc                 D   |dk  rd| }t        |      || j                  k\  rd| d| j                   d}t        |      |dk  rd| }t        |      || j                  |   kD  rd| d| }t        |      || j                  |   kD  rd	| d| }t        |      ||k  rd
| d| }t        |      |dk  rd| d}t        |      dg| j                  z  }t        | j                        }dg| j                  z  }|||<   |||<   |||<   t	        | |||      S )Nr   z'slice_in_dim: received a negative axis zslice_in_dim: axis z! is greater or equal to the rank z of the tensorz.slice_in_dim: received a negative start_index z5slice_in_dim: start_index is greater than the length z of dimension z5slice_in_dim: limit_index is greater than the length z%slice_in_dim: received a limit_index z less than the start_index z0slice_in_dim: received a non-positive stride of r  r   )r  r  r   r/  r  )	r   r  r  r   r  r  r  r  r   s	            r   _slice_in_dim_metar  X  sj    ax7v>oqvv~#D6)J166(R`aoQ>{mLoQWWT]"Ek]R`ae`fgoQWWT]"Ek]R`ae`fgo[ 5k]B]^i]jkoz@JoC!&&LMMMcAFFlG%M$%M$GDMq-@@r   c                     dg| j                   z  }t        | j                        }dg| j                   z  }|||<   |||<   |||<   t        | |||      S Nr   r   )r  r/  r   r   )r   r  r  r   r  r  r  r   s           r   _slice_in_dim_atenr    s]     C!&&LMMMcAFFlG%M$%M$GDMM='::r   zI
    Convenience wrapper for slicing just one dimension using slice.
    zhslice_in_dim(Tensor(a) a, SymInt start_index, SymInt limit_index, int stride=1, int axis=0) -> Tensor(a)r  outer_lengthc                    t        | t              sJ t        j                  | j                  |       t        j
                  |       | j                  |   |z  }| j                  |   |z  dk7  r!d| j                  |    d| d}t        |      g }g }t        | j                        D ]  }||k(  rL|j                  ||f       |j                  | j                         |   |z  | j                         |   f       T|j                  | j                  |          |j                  | j                         |           | j                  ||| j                               S )Nr   z(Attempting to split dimension of length z, but outer length of z divides it with a remainder!)r   r   r-  r  r  validate_dim_lengthr   r  r  extendr   r   r   r~  )r   r  r  inner_lengthr  r  r  r  s           r   _split_dim_metar    sD   a$$$	qvvs#	l+ 773<</L	|#)6qwws|n E##/.0MO 	 oIKQVV} 0#:lL9:
3, >
3PQQWWS\*qxxz#/0 <<	;0@0@0BCCr   c                     | j                   |   |z  }| j                   d| ||fz   | j                   |dz   d  z   }| j                  |      S r  )r   r  )r   r  r  r  r  s        r   _split_dim_atenr    sP    773<</L#,!==a	@RRI66)r   z
  Creates a view of a with the given dimension (of length l) split
  into two dimensions, with the outer of the two having
  length outer_length and the inner of the two having computed
  length inner_length such outer_length * inner_length = l.
  zAsplit_dim(Tensor(a) a, int dim, SymInt outer_length) -> Tensor(a)c                    t        | t              sJ |D ]6  }t        j                  | j                  |       | j
                  |   dk(  r6J  g }g }t        t        | j
                              D ]G  }||v r|j                  | j
                  |          |j                  | j                         |          I | j                  ||| j                               S r  )r   r   r-  r  r  r   r  r   r   r   r   r~  )r   r  r  r  r  s        r   _squeeze_metar    s    a$$$ !1663'wws|q   ! IKS\" ,*&188:c?+, <<	;0@0@0BCCr   z~
  Creates a view of the tensor with the specified dimensions removed.

  The removed dimensions must each have length one.
  z3squeeze(Tensor(a) a, int[] dimensions) -> Tensor(a)permutationc                    | j                   t        |      k7  r'd| j                    dt        |       d}t        |      t        j                  | j                   |      sd| d}t        |      dg| j                   z  }dg| j                   z  }t        |      D ]-  \  }}| j                  |   ||<   | j                         |   ||<   / | j                  t        |      t        |      | j                               S )Nz'Attempting to permute a tensor of rank z', but received a permutation of length r  z!Received an invalid permutation, r   )r  r   r  r-  is_valid_permutationr  r   r   r   r   r~  )r   r  r  r  r  r  r  s          r   _transpose_metar    s    vv[!!7x?fgjkvgwfxxyzo%%affk:1+a@oaffI#,Kk* +S	#88:c?C+ <<i(%*<a>N>N>PQQr   c                 .    t        j                  | |      S r   )r   permute)r   r  s     r   _transpose_atenr    s    ==K((r   z
    Creates a view of the tensor with its dimensions permuted.

    The length of the permutation must be the rank of the tensor,
    and each element of the permutation specifies the new order
    for the corresponding dimension.
    z6transpose(Tensor(a) a, int[] permutation) -> Tensor(a)c                 t    | j                  | j                  | j                         | j                               S r   )r   r   r   r~  r^  s    r   _view_of_metar  #  s(    <<Q-=-=-?@@r   c                 8    | j                  | j                        S r   )r  r   r^  s    r   _view_of_atenr  '  s    66!''?r   z'
    Creates a view of the tensor.
    z!view_of(Tensor(a) a) -> Tensor(a)c                 $    | j                  |      S r   r  r   r   s     r   _view_element_type_metar  8      66%=r   c                 $    | j                  |      S r   r  r  s     r   _view_element_type_atenr   <  r  r   z>
    Creates a view of the tensor with a different dtype.
    z9view_of_dtype(Tensor(a) a, ScalarType dtype) -> Tensor(a)srcc                     t        j                         t        j                         t        j                        t	        j
                   j                         k\   fd       t	        j
                  t        j                  j                        fd       t        j                         S )Nc                      d d d d j                          d j                         z   d j                          j                         z   S )Nzas_strided_scatter: sizes z
, strides z, storage offset z  and itemsize z requiring a storage size of z' are out of bounds for storage of size )element_sizer  )r`  required_sizer}  r~  r   s   r   rG  z*_as_strided_scatter_meta.<locals>.<lambda>^  so    (j@QR`Qa b"//122Ou11334 5##(;;=53E3E3G#G"HJ r   c                  (    dj                    d  S )NzCexpected src to have a size equal to the slice of self. src size = z, slice size = r  )r}  r  s   r   rG  z*_as_strided_scatter_meta.<locals>.<lambda>g  s     UVYV_V_U``optouv r   )
r-  r  r  compute_required_storage_lengthr   rI  r  is_same_shaper   clone_preserve_strides)r`  r  r}  r   r~  r  s   `````@r   _as_strided_scatter_metar
  Q  s     
	6"99$WM	LL&	
 
LLCIIt,v
 ''..r   z
    Creates a new tensor equivalent to ``out = input.clone()`` after mutation by
    ``out.as_strided(size, stride, storage_offset).copy_(src)``.
zlas_strided_scatter(Tensor self, Tensor src, SymInt[] size, SymInt[] stride, SymInt storage_offset) -> Tensorc                 l    t        | ||       t        | j                  ||      }| j                  |      S r   )r  r  r   	new_emptyr  s       r   _collapse_metar    s/    Auc* %5I;;y!!r   c                     t        | j                  ||      }| j                  |      }t        j                         5  |j                  |       j                  |        d d d        |S # 1 sw Y   |S xY wr   )r  r   r  r   no_gradview_ascopy_)r   r  r  r  r  s        r   _collapse_atenr    s[     %5I
++i
 C	  AQ J Js   !A((A2zn
Collapse a span of neighboring dimensions into one.

See collapse_view for the corresponding view operation.
z0collapse(Tensor a, int start, int end) -> Tensortensorsc           	        	 dk\  sJ | d   j                   }d}t        |       D ]|  \  	}t        |      t        |j                         k(  sJ t        t        ||j                               D ]2  \  }\  |k(  r|z   }t	        j
                  k(  	fd       4 ~ t        | d   j                         j                         }||<   t        | d   |t        j                  |            S )Nr   c            	      "    d d  d d d	S )Nz0Sizes of tensors must match except in dimension z. Expected z	 but got z for tensor number z in the listr   )common_lengthr  r  
tensor_idxs   r   rG  z_cat_meta.<locals>.<lambda>  s,    Nse T  -ix?R!l,0 r   r   r   )r   r  r   r  r   rI  r/  copyr   r-  r  )
r  r  r   concat_lengthtensorr  r  r  r  r  s
    `     @@@r   	_cat_metar    s    !8O8AJEM'0 
F5zS....,5c%6N,O 		(C(-cz - 6m+0			 WQZ%%&++-I"IcN
11)< r   c                 .    t        j                  | |      S r   )r   r   )r  r  s     r   	_cat_atenr    s    99Wc""r   z
  Concatenates tensors along the specified dimension.

  The tensors' shapes must have the same rank and same length for other dimensions.
  z(cat(Tensor[] tensors, int dim) -> Tensorc                 0   t        | t              sJ t        j                  |       t	        t
        j                  |      }|| j                         k7  r"d| j                          d| d}t        |      t        | |t        j                  |            S )Nz$Attempting to reshape a tensor with z elements to a shape with 
 elements!r  )r   r   r-  r  r   r  rx   r  r  r   r  )r   r   r  r  s       r   _reshape_metar!    s    a$$$	 8<<'E	4QWWYK?YZ_Y``jkoaue.O.OPU.VWWr   c                 \    | j                  |      j                         j                         S r   )r   
contiguousr   r   r   s     r   _reshape_atenr%    s#    99U&&(..00r   z`
  Creates a contiguous tensor with the specified shape
  containing a copy of the data in a.
  z+reshape(Tensor a, SymInt[] shape) -> Tensorr  c                     t        j                  | j                  |       t        j                  | t        j
                        S )Nre  )r-  validate_dimension_indicesr  r   
empty_likeri  )r   r  s     r   	_rev_metar)    s/    	$$QVVT2AU-B-BCCr   zD
    Reverses the order of elements along the given dimensions.
    z#rev(Tensor a, int[] dims) -> Tensorpredc                 >    t        ||t        j                  | f      S )N)r(  r'  rn  )r*  r   rs  s      r   _where_metar,    s%     "		;CC $w	 r   z
  Selects elements from a and b according to pred.

  Where pred is true the result contains the element from a, and
  where pred is false the result contains the element from b.
  z0where(Tensor pred, Tensor a, Tensor b) -> Tensorc                    t        | t              sJ t        |t        j                        sJ t        j                  j                  |       r| j                         }nt        j                  |       }t        | ||      S )N)r   r   )
r   r   r   r   _prims_commonis_non_overlapping_and_denser   r-  rc  r   )r   r   r   s      r   _convert_element_type_metar0  !  sf    a$$$eU[[))) 77:((*::1=a66r   c                 .   t        j                  |      sd}n	 | j                  }t	        j
                  | | j                  ||      }t	        j                         5  t        ||       cd d d        S # t        $ r}d}Y d }~]d }~ww xY w# 1 sw Y   y xY w)NF)r   r   requires_grad)	r-  is_grad_dtyper2  	Exceptionr   r(  r   r  r   )r   r   r2  eresults        r   _convert_element_type_atenr7  /  s    u%	"OOM 	!((%}F 
 "vq!" "  	"!M	"" "s#   A3 B3	B<BBBz6
  Creates a copy of a tensor with the given dtype.
  z:convert_element_type(Tensor a, ScalarType dtype) -> Tensor)r   r   r   r   r   r   c                     t        | t              sJ t        |t        t        j                  f      sJ t        | t        j                  |            S )N)r   )r   r   r   r   r   r   r-  canonicalize_devicer   r   s     r   _device_put_metar;  O  sE     a$$$fsELL1222a 9 9& ABBr   c                 $    | j                  |      S r   )tor:  s     r   _device_put_atenr>  X  s    44<r   z5
  Creates a copy of a tensor on the given device.
  z-device_put(Tensor a, Device device) -> Tensorc                 b    t        j                  | j                        }t         |d            S r  )r-  dtype_to_typer   r   )r   number_types     r   
_item_metarB  k  s%    %%agg.Kk"o&&r   z<
    Converts a tensor with one element to a Python number.
zitem(Tensor a) -> Scalarc                 N    t        j                  |       }t         |d            S r  r-  r@  r   r   rA  s     r   _maximum_value_metarF    !    %%e,Kk"o&&r   c                     | t         j                  k(  ry| j                  s| j                  rt        j                  |       j
                  S t        j                  |       j
                  S )NT)r   r5  r\  is_floating_pointfinfor  iinfor   s    r   _maximum_value_atenrM    sL    

			U44{{5!%%%{{5!%%%r   z2
    Return the maximum finite value for a dtype.
z)maximum_value(ScalarType dtype) -> Scalarc                 N    t        j                  |       }t         |d            S r  rD  rE  s     r   _minimum_value_metarO    rG  r   c                     | t         j                  k(  ry| j                  s| j                  rt        j                  |       j
                  S t        j                  |       j
                  S )NF)r   r5  r\  rI  rJ  minrK  rL  s    r   _minimum_value_atenrR    sL    

			U44{{5!%%%{{5!%%%r   z2
    Return the minimum finite value for a dtype.
z)minimum_value(ScalarType dtype) -> Scalarc                     t        | t              sJ t        |t              sJ | j                         |j                         k7  r0d|j                          d| j                          d}t        |      | S )NzAttempting to copy z elements to a tensor with r   )r   r   r  rb  )r   rs  r  s      r   _copy_to_metarT    sj    a$$$a$$$ 	wwyAGGI#AGGI;.I!'')T^_3Hr   c                 $    | j                  |      S r   )r  rx  s     r   _copy_to_atenrV    s    771:r   z;
  Copies the data in b to a and returns the modified a.
  z-copy_to(Tensor(a!) a, Tensor b) -> Tensor(a!))r   r   r   r   r   r   c                     t        | t              sJ t        j                  | j                  || j
                  | j                  | j                  | j                        S )N)r   rh  r   r2  )	r   r   r   r   r   r   rh  r   r2  )r   r   s     r   _copy_strided_metarX    sK    a$$$	ggxxxxoo r   c                     t        j                  | j                         || j                  | j                  | j
                  | j                        }|j                  |        |S )N)r   r   rh  r   r2  )r   r   r}  r   rh  r   r2  r  )r   r   r  s      r   _copy_strided_atenrZ    sL    


	ggxxxxooC IIaLJr   zp
  Copies the data in a to a new tensor, the new tensor has same shape with a size, but has different stride.
  z1copy_strided(Tensor a, SymInt[] stride) -> Tensorc                 $    | j                  |      S r   resize_r$  s     r   _resize_metar^  	      99Ur   c                 $    | j                  |      S r   r\  r$  s     r   _resize_atenra  	  r_  r   z
  Gives a tensor with no elements a new shape, returning the modified tensor.

  The tensor's strides are contiguous and its values are unitialized.
  z2resize(Tensor(a!) a, SymInt[] shape) -> Tensor(a!)output_dtypec                    t        | t              sJ || j                  }t        j                  | j
                  |      }t        |t        j                  |      || j                        S )z\
    Meta function for single output reduction operations
    Stride logic is incorrect
    r   )	r   r   r   r-  compute_reduction_output_shaper   r   r  r   )inpr  rc  output_shapes       r   _reduction_metarh  )	  sa    
 c:&&&yy77		4HL11,?zz	 r   c                     t        j                  | j                        r t        j                  | j                        }n| j                  }t	        | ||      S )Nrb  )r-  r9  r   r:  rh  )rf  r  
correctionrc  s       r   _var_reduction_metark  :	  s@    cii(55cii@yy3<@@r   zx
    Computes the sum of elements in the input tensor over the list of dimensions
    specified in the dim argument
    z|
    Computes the xor sum of elements in the input tensor over the list of dimensions
    specified in the dim argument
    z|
    Computes the product of elements in the input tensor over the list of dimensions
    specified in the dim argument
    z
    Computes the maximum value of elements in the input tensor over the list of dimensions
    specified in the dim argument
    z
    Computes the minimum value of elements in the input tensor over the list of dimensions
    specified in the dim argument
    ze
    Computes the biased variance of x over the list of dimensions specified in the dim argument
    c                 L    t        |  dt        |t        j                  |      S )Creates a reduction prim.zE(Tensor inp, int[]? dims, *, ScalarType? output_dtype=None) -> Tensorr  )r  rh  r   rP  r   r   r   s      r   _make_reduction_primro  [	  s*    \]OO r   c                 L    t        |  dt        |t        j                  |      S )rm  zZ(Tensor inp, int[]? dims, float? correction=1, *, ScalarType? output_dtype=None) -> Tensorr  )r  rk  r   rP  rn  s      r   _make_var_reduction_primrq  f	  s*    qr OO r   r   rn  rL  rf  c                    t        d      )Nz&xor_sum only implemented with inductorrV  )rf  r  r   s      r   _xor_sum_atenrs  x	  s     F
GGr   r   c                    |Qt        |      dk(  r| j                         S t        |d      D ]!  }|dk\  sJ t        j                  | ||      } # | S t        j                  | ||      S )Nr   T)reverserL  )r   r   r  r   r   )rf  r  r   ds       r   
_prod_atenrw  	  sn     t9>99;d+ 	2A6M6**S!51C	2 
zz#t511r   r   c                 4    t        j                  | f||d|S )N)r  rj  )r   r   )r`  r  rj  r   s       r   	torch_varry  	  s    99UE
EfEEr   r   r   r   zC
    Constructs a 1-D tensor t where ``t[i] == start + i * step``.
r  r  r2  c                    t        j                  t        j                  |      d        t        j                  |dk7  d        t        j                  | |||      S )Nc                       y)Nz'prims.iota only supports integer dtypesr   r   r   r   rG  z_iota_meta.<locals>.<lambda>	  rH  r   r   c                       y)Nzstep must be nonzeror   r   r   r   rG  z_iota_meta.<locals>.<lambda>	  rH  r   r   r   r2  )r   rI  r-  r6  rj  )r  r  r  r   r   r2  s         r   
_iota_metar~  	  sS     
LLu%9 
LL:;;;#	 r   c                H    || |z  z   }t        j                  ||||||      S Nr}  )r   arange)r  r  r  r   r   r2  r  s          r   
_iota_atenr  	  s0     &4-
C<<sDfM r   zpiota(SymInt length, *, SymInt start, SymInt step, ScalarType dtype, Device device, bool requires_grad) -> Tensorc                J    t        j                  |       }t        | |||      S Nr   r-  r  r   )r   r   r   r2  r   s        r   _empty_metar  	  s%     //6GE7%OOr   c                4    t        j                  | |||      S r  )r   rj  )r   r   r   r2  s       r   _empty_atenr  	  s     ;;uE&VVr   z\
    Creates a tensor with uninitialized values and the specified shape, dtype, and device.
zWempty(SymInt[] shape, *, ScalarType dtype, Device device, bool requires_grad) -> Tensorc                     t        | |||      S r  )r   )r   r   r   r   r2  s        r   _empty_strided_metar  	
  s     E7%OOr   z1
    Creates a tensor with uninitialized values.
zqempty_strided(SymInt[] shape, SymInt[] strides, *, ScalarType dtype, Device device, bool requires_grad) -> Tensorphysical_layoutc                  	
 t        j                  D cg c]  }| |   	 c}      }t        |       	t        j                  t              	k(  	fd       dgt        |       z  }t               }t              D ]`  \  
t        j                  dcxk  xr 	k  nc 	
fd       t        j                  |vd        |
   |<   |j                         b t        | |||      S c c}w )Nc                  &    d  dt               S )NzlNumber of dimensions in the tensor input does not match the length of the physical layout; i.e. len(size) = z( is not equal to len(physical_layout) = )r   )r  r  s   r   rG  z&_empty_permuted_meta.<locals>.<lambda>.
  s)    ??Be D669/6J5KM r   r   c                  "    d dz
   d d dS )Nz5Dimension out of range (expected to be between 0 and r   z
, but got z
 at index zL).  NB: negative dims not currently supported; file an issue if you want it.r   )r  lr  s   r   rG  z&_empty_permuted_meta.<locals>.<lambda>9
  s-    GayPZ#Zs #II r   c                       y)NzDuplicate dim not allowedr   r   r   r   rG  z&_empty_permuted_meta.<locals>.<lambda>?
  rH  r   r   )	r-  r  r   r   rI  r	  r  rc   r   )r   r  r   r   r2  r  	p_stridesr   	seen_dimsr  r  s    `   `   @@r   _empty_permuted_metar  "
  s     11_2U582UVI
e*C	LLO#	
 cCJGI/* 1LSL	
 	Qi')LMq\
a 	 1 3Vs   C2z
    Creates a tensor with uninitialized values according to some physical layout,
    that is guaranteed to be non-overlapping and dense.
zwempty_permuted(SymInt[] shape, int[] physical_layout, *, ScalarType dtype, Device device, bool requires_grad) -> Tensor
fill_valuec                J    t        j                  |       }t        | |||      S r  r  )r   r  r   r   r2  r   s         r   
_full_metar  Y
  s%     //6GE7%OOr   c                6    t        j                  | ||||      S r  )r   full)r   r  r   r   r2  s        r   
_full_atenr  e
  s      ::zv] r   zi
    Creates a tensor filled with the given fill value, and with the specified shape, dtype, and device.
zifull(SymInt[] shape, Scalar fill_value, *, ScalarType dtype, Device device, bool requires_grad) -> Tensorc                    t        j                  |       }| j                         dk(  r| j                         }t	        | |||      S )Nr   )r   r   r   )r-  rc  r  r   r   )r   r  r   r   r2  r   s         r   _full_like_metar  
  s=     66q9GwwyA~((*afEEr   c                6    t        j                  | ||||      S r  )r   	full_like)r   r  r   r   r2  s        r   _full_like_atenr  
  s      ??	:U6 r   z
    Creates a tensor filled with the given fill value, and the same shape, dtype, and device as the
    given tensor by default. The dtype and device settings can be overridden
    by specifying them explicitly.
zhfull_like(Tensor a, Scalar fill_value, *, ScalarType dtype, Device device, bool requires_grad) -> Tensorscalarc                P    g }t        j                  |      }t        | ||||      S r  r  )r  r   r   r   r   s        r   _scalar_tensor_metar  
  s-     E//6GfE7%PVWWr   c                    t        | t              r"|t        j                  |      st	        d      t        j                  | ||      S )Nz-Complex scalar requires complex tensor dtype.r   )r   complexr-  r9  	TypeErrorr   r   )r  r   r   s      r   _scalar_tensor_atenr  
  sA     &'"U33E:GHHvU6BBr   zG
    Wraps a Number into a Tensor with the specified dtype and device.
zQscalar_tensor(Scalar s, *, ScalarType? dtype=None, Device? device=None) -> TensorAfull_matricesc                   t        j                  | d       t        j                  | j                  dd       | j                  }|d d }|dd  \  }}t        ||      }|||r|n|fz   }t        j                  |d      }t        ||| j                  | j                        }	||fz   }
t        j                  |
      }t        |
|| j                         rt        j                  | j                        n| j                  | j                        }||r|n||fz   }| j                  j                  dk(  }t        j                  ||      }t        ||| j                  | j                        }| j                         dk7  r>|j                         r.t        j                  j                         r|j!                         }|	||fS )	Nz
linalg.svdF)allow_low_precision_dtypes)	row_majorr   cudar   )r-  check_is_matrixcheck_fp_or_complexr   r   rQ  r  r   r   r\  r:  r   r  r   r  is_availabler   )r  r  A_shapebatchmnkshape_U	strides_UUshape_S	strides_SSshape_Vhis_cuda
strides_VhVhs                    r   	_svd_metar  
  sw    
!\*	agg|PUVggGCRLE23<DAqAq	Aq}!!44G11'UKI)177188TAqdlG11':I9:e,,QWW5QWWxx		A ]155H hhmmv%G228wOJ	(Jaggahh	WB 	wwyA~"--/ejj.E.E.GWWYa8Or   c                D    t         j                  j                  | |      S )N)r  )r   linalgr   )r  r  s     r   	_svd_atenr  
  s     <<A];;r   z
    Returns the SVD of a matrix or batch of matrices.

    The `full_matrices` flag controls whether the full or reduced SVD decomposition is returned.
zGsvd(Tensor A, *, bool full_matrices) -> (Tensor U, Tensor S, Tensor Vh)	generatormeanstdr  c                   t        j                  dk\  fd       t        j                  t        j                        xs t        j                        fd       t        j
                  |       }t        | ||      S )Ng        c                      d  S )Nz6expected non-negative standard deviation, but got std=r   )r  s   r   rG  z_normal_meta.<locals>.<lambda>$  s    HN r   c                      d  S )Nz:expected a floating-point or complex dtype, but got dtype=r   rL  s   r   rG  z_normal_meta.<locals>.<lambda>)  s    LUGT r   r   )r   rI  r-  is_float_dtyper9  r  r   )r   r  r  r   r   r2  r  r   s     ``    r   _normal_metar    sm     
LLs
N
 
LLU#Du'='=e'DT
 //6GE7%OOr   c                    t        j                  | |||      }t        j                         5  |j                  |||       d d d        |S # 1 sw Y   |S xY w)Nr}  r  )r   rj  r  normal_)r   r  r  r   r   r2  r  r   s           r   _normal_atenr  0  sQ     	Ev]SA	 2			$y	12 H2 Hs   AAz
    Constructs a tensor filled with values drawn from a normal distribution with the specified mean
    and standard deviation.

    Only supports floating-point types.
znormal(SymInt[] shape, *, Scalar mean, Scalar std, ScalarType dtype, Device device, bool requires_grad, Generator? generator=None) -> Tensorlowhighc                J    t        j                  |       }t        | |||      S r  r  )r   r  r  r   r   r  r   s          r   _uniform_metar  S  s%     //6GE7%OOr   c                ^    t        j                  | ||      }|j                  |||       |S )Nr   r  )r   rj  uniform_)r   r  r  r   r   r  r   s          r   _uniform_atenr  `  s-     	Ev6AJJsDIJ.Hr   zN
    Constructs a tensor filled with values drawn uniformly from low to high.
zyuniform(SymInt[] shape, *, Scalar low, Scalar high, ScalarType dtype, Device device, Generator? generator=None) -> Tensoronesidedc                Z   t        j                  | j                  |      }t        j                  |       t	        | j
                        }|r|d   }||   dz  dz   ||<   t        j                  | j                        }t        j                  |      }t        |||| j                        S )Nr  r  r   r   )r-  r  r  validate_no_repeating_dimsr/  r   corresponding_complex_dtyper   r  r   r   )r`  r  r  r   last_dimr   r   s          r   _fft_r2c_metar    s     
!
!%**c
2C	$$S)Er7/Q.2h--ekk:E//6GE7%UUr   c                6    d}t        j                  | |||      S r  )r   _fft_r2c)r`  r  r  normalizations       r   _fft_r2c_atenr    s     M>>%mX>>r   z7
    Performs a real to complex Fast Fourier Transform
z;fft_r2c(Tensor self, *, int[] dim, bool onesided) -> Tensorforwardc                    t        j                  | j                  |      }t        j                  |       | j                  }t        j
                  |      }t        ||| j                  | j                        S r  )	r-  r  r  r  r   r  r   r   r   )r`  r  r  r   r   s        r   _fft_c2c_metar    s_     
!
!%**c
2C	$$S)KKE//6GWEKK r   c                6    d}t        j                  | |||      S r  )r   _fft_c2c)r`  r  r  r  s       r   _fft_c2c_atenr    s     M>>%mW==r   z>
    Performs either a Fast Fourier Transform, or its inverse
z:fft_c2c(Tensor self, *, int[] dim, bool forward) -> Tensorlast_dim_sizec                @   t        j                  | j                  |      }t        j                  |       t	        | j
                        }|||d   <   t        j                  | j                        }t        j                  |      }t        |||| j                        S )Nr  r   )r-  r  r  r  r/  r   r:  r   r  r   r   )r`  r  r  r   r   r   s         r   _fft_c2r_metar    s|     
!
!%**c
2C	$$S)E"E#b'N**5;;7E//6GE7%UUr   c                6    d}t        j                  | |||      S r  )r   _fft_c2r)r`  r  r  r  s       r   _fft_c2r_atenr    s     M>>%m]CCr   z?
    Performs a complex to real Inverse Fast Fourier Transform
zBfft_c2r(Tensor self, *, int[] dim, SymInt last_dim_size) -> Tensorselfc                     t        j                  | j                  j                  d        t        j                  |       t        j                  | t         j
                        fS )Nc                       y)Nz1torch.frexp() only supports floating-point dtypesr   r   r   r   rG  z_frexp_meta.<locals>.<lambda>   rH  r   rL  )r   rI  r   rI  r(  int32)r  s    r   _frexp_metar    sG    	LL

$$C D!5#3#3D#LLLr   z8frexp(Tensor self) -> (Tensor mantissa, Tensor exponent)c                      t               S r   r   r   r   r   _make_token_atenr    s    r   z_make_token() -> Tensorz7Creates a token used for keeping track of side effects.c                      y r   r   )tokenss    r   _sink_tokens_atenr    s    r   z#_sink_tokens(Tensor[] tokens) -> ()zTSink all of the tokens which were previously used for keeping track of side effects.r   )r   r   r  )r)  N(n  r  enumr   	functoolsr   r   typingr   r   r   r	   r
   r   r   r   torch._prims_commonr.  r-  torch.libraryr   r   torch._Cr   torch._higher_order_ops.effectsr   torch._library.utilsr   torch._prims.debug_primsr   torch._prims.rng_primsr   r   r   r   r   r   r   r   r   r   r   r   r    torch._prims_common.wrappersr"   r  r#   r$   torch.overridesr%   r&   torch.utils._pytreer'   r(   r)   r   Libraryr   r   r  r   r   __all__r   r   r   r   r   r5  r  r  rD  rK  rR  rT  rX  r1   r&  r2   r#  r3   r4   r5   r6   r7   r8   r9   specialr>   r?   i0r:   i0er;   i1r<   i1er=   r@   r_  rA   rB   rd  _conj_physicalrP  rC   ri  rf  rk  r   rD   rE   erfinvrF   rG   rH   rI   rJ   rK   ro  rL   rM   r   rN   rO   r%  rP   rQ   rR   rS   rT   rW   rX   rU   rV   rY   r}   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   ru  rh   ri   rj   rk   rl   rn   ro   rp   rq   gammaincrr   	gammainccrs   rt   ru   ry  rv   r|  rw   rx   ry   rz   r{   r|   bitwise_left_shiftr~   bitwise_right_shiftr   r   r   r   r=  r  r  _as_strided_docr   r  r  _broadcast_in_dim_docr   r  r  r  r  r  _collapse_view_docr   r  	_conj_docr   r   r   r  __annotations__r  r  
_slice_docr  r  _slice_in_dim_docr   r  r  _split_dim_docr   r  _squeeze_docr   r  r  _transpose_docr   r  r  _view_of_docr   r  r   _view_element_type_docr   r
  _as_strided_scatter_docr   r  r  _collapse_docr   r  r  _cat_docr   r!  r%  _reshape_docr   r)  _rev_docflipr   r,  
_where_docr   r0  r7  _convert_element_type_doc	pointwiser   r;  r>  _device_put_docr   rB  	_item_docr   rF  rM  _maximum_value_docr   rO  rR  _minimum_value_docr   rT  rV  _copy_to_docINPLACEr   rX  rZ  _copy_strided_docr   r^  ra  _resize_docr   rh  rk  _sum_doc_xor_sum_doc	_prod_doc	_amax_doc	_amin_doc_var_docro  rq  r   rs  r   rw  r   ry  r   r   r   	_iota_docr~  r  r   r  r  
_empty_docrj  r  _empty_strided_docr   r  _empty_permuted_docr   r  r  	_full_docr  r  r  _full_like_docr  r  r  _scalar_tensor_docr   r  r  _svd_docr   r>  r  	Generatorr  r  _normal_docr   r  r  _uniform_docr   r  r  _fft_r2c_docr   r  r  _fft_c2c_docr   r  r  _fft_c2r_docr   r  rm   r  r   r  NONEr   r   r   r   <module>rB     s#     % I I I  #  # ( < 5 9 5    A D E F F }}We,MM!!'63NO	 ==00&/R ]]**7FJG &&w?ph =A(K "&$(#'15(Kz5<<789(K I(K j!	(K
 EKK (K U5<<,-.(Kd +/#(*/ii {E+s*:$;;<i 	i
 i 
i 8EII&
'i !i $(iX4  DH\8\ %U>3+>%?@\ 	\~3
"F
"F #	ii
7HH	 $
jj
7??	 	%kk
7??		 $
jj
7??	 	%kk
7??		 $
jj
7??	 	%kk
7??		 #	ii
7??	 $
jj
7??	 )mm%%
7??		 )mm%%
7??		 )hh
7??		 *mm
7??	
 )mm
7??		 *mm
7??	
 +
7??	8%,, 86 8 $

7??	 $
jj
7??	.~ .. . 1	""> DICXCX-2-@-@. 	N	kk&"&	 'mm
7??	 #	ii
7??	 'mm""
7??	 $
mm  
7??	 	%mm!!
7??		 #	ii
7??	 	%mm!!
7??		 $
mm  
7??	.    6	jj
 	%kk
7??		 .	&;LL
   jj
	 (nn
7CC	 
&ll
7??	
 #	ii
7??	 	%kk
7??		 $
jj
7??	 	%kk
7??		 .	&;LL
   jj
	 *
7??	
 	%mm!!
7??		 #	ii
7??	 	%kk
7??		 	%kk
7??		 $
jj
7??	 'mm
7??	 #	ii
7??	 $
jj
7??	 3mm//
7??	  $
jj
7??	 #	ii
7??	 $
jj
7??	 	%kk
7??		 $	ii
7??	 	&	kk
7??		 ,
7??	 +
7??	
 ,
7??	 ' $	
7??	 #hh
7CC	 %
jj
7??	 %
jj
7??	 %
jj
7??	 $	ii
7??	 #hh
7CC	 #hh
7CC	 	&kk
7??		 
'mm$$
7??	
 (mm%%
7??	 #hh
7CC	 #hh
7CC	^Z'(-2>:3M-N (
7??	^Z'(-2>:3M-N (
7??	 $	ii
7??	 #hh
7CC	 *oo
7??		 $	ii
7??	 *oo
7??		 +&&
7??	
 7''
7??	    #	ii
7??	 %
mm  
7??	==&=0:=LO==(===(2=DG==
 j	  
7@7@'7@?G}7@t
	  c	$   v c   =I =c = =c3h =7"7"!7"(+7"
8I 4457"tD> D# DC DN D6 # C F 
 " H	!  . ^ 	 +	jj   ;?@@#3@@6 e  %)	<D<D#<D $<D j!	<D
 <DF %)	''#' $' j!	'
 '

 	t	  	 *A*A*A *A 	*A
 *A *Ab ;;; ; 	;
 ; ;$ 
 u	   D~ DC Ds D~ D8v C s v  N	  	D^ D Dn D& @	mm  R~ R4D R R$)v ),< ) ) C	  	A^ A AV   .	  ~ ekk n v ekk f   F	 %   //	/ / 	/
 / /8 
  y	!&& "f "S "s "v "f S s v 
 =	x/ c n 6#uU63;/f=> #S #V # 5	X^ XI X1V 1I 1& 1 8	D D'7 DN D
 0	jj
+0>
 	=	kk	7. 7 7 7"& " " "$  "G	#(!
))

	 CC$S%,,%67CC c5<<.?(@ V  :	
'. 'Z '
	 %	ll'u{{ 'z '
&u{{ &  6	!'u{{ 'z '
&u{{ &  6	!^  &V  6 
 :	##"&	. 	) 	
& 
) 
 
 
 >	 N 9 F 9   
?	##
 04 "A			
s 3  	ii $(	H	H
#
$H EKK 	H
 H 	 $(	2	2
#
$2 EKK 	2
 2" 	F 	 	jj 	jj	  	
 ;; LL  ,  	
 ;; LL   }	PP %P5:\\PRVPPWW %W5:\\WRVWW
 	d		PPP ;;	P
 LLP P P 
 ~	!!%%%% ;;	%
 LL% % %P   E	""	P	P	P ;;		P
 LL	P 	P 	P ;;	
 LL  	
 v	FFF ;;	F
 LLF F F ;;	
 LL   u		XX ;;X LL	X
 XCC ;;C LL	C
 C 
 ^	!"")-"
>>>9:"J<<)-<
666!"< T	+//;??C, ,0PP w
P 
	P
 ;;P LLP P (P P@ ,0 w
 
	
 ;; LL  ( " 
 	W	
$ ,0
P
P 

P 	
P
 ;;
P LL
P (
P 
P( ,0 
 	
 ;; LL ( 
  	D	VV 
V 	V
 V&?? 
? 	?
 ?
 H	 
 	
  >> 
> 	>
 >
 G	VV 
V 	V
 V DD 
D 	D
 D
 O	Mn M~~/M)N M 	E	+//2kk
	.  $	A	 0	  ^    r   