L i[UddlmZddlmZddlmZmZmZmZm Z m Z m Z m Z ddl Z ddlmcmZddl mZmZddlmZddlmZmZmZmZdZeeed <gd Zd e eefd eed ffdZ dee e!efde ede ed efdZ"dede!d efdZ#d*dede$d efdZ%ded efdZ&d*dede$d efdZ'e ddZ(e dd Z)Gd!d"ee(e)fZ*Gd#d$e*e(e)fe+Z,d+d%ed&e!d efd'Z-d+d(ed&e!d efd)Z.y),)Sequence)update_wrapper)AnyCallableFinalGenericOptionaloverloadTypeVarUnionN)SymIntTensoris_tensor_like)_dtype_NumberDeviceNumbergox?euler_constant) broadcast_alllogits_to_probs clamp_probsprobs_to_logits lazy_propertytril_matrix_to_vecvec_to_tril_matrixvaluesreturn.ctd|Ds tdtd|Dsttj}|D]?}t |tj st|j|j}n|Dcgc]%}t|r|ntj|fi|'}}tj|Stj|Scc}w)a Given a list of values (possibly containing numbers), returns a list where each value is broadcasted based on the following rules: - `torch.*Tensor` instances are broadcasted as per :ref:`_broadcasting-semantics`. - Number instances (scalars) are upcast to tensors having the same size and type as the first tensor passed to `values`. If all the values are scalars, then they are upcasted to scalar Tensors. Args: values (list of `Number`, `torch.*Tensor` or objects implementing __torch_function__) Raises: ValueError: if any of the values is not a `Number` instance, a `torch.*Tensor` instance, or an instance implementing __torch_function__ c3VK|]!}t|xst|t#ywN)r isinstancer.0vs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributions/utils.py z broadcast_all..+s$Kq~a :Jq'$::Ks')ziInput arguments must all be instances of Number, torch.Tensor or objects implementing __torch_function__.c32K|]}t|ywr!rr#s r&r'z broadcast_all..0s1Q~a 1s)dtyper)device) all ValueErrordicttorchget_default_dtyper"rr)r+rtensorbroadcast_tensors)roptionsvaluer% new_valuess r&rrs KFK K G   1&1 1"&U-D-D-F"G E%.U[[F  MS GH"A Q(B'(B B  && 33  " "F ++  s*C&shaper)r+ctjjrBtjtj|||tj |||Stj |||jS)Nr*)r/_C_get_tracing_statenormalzerosonesemptynormal_)r6r)r+s r&_standard_normalr?=sc  xx""$|| KKU6 : JJuE& 9   ;;uE& 9 A A CCr4dimcv|dk(r|S|jd| dz}|j|jdS)z Sum out ``dim`` many rightmost dimensions of a given tensor. Args: value (Tensor): A tensor of ``.dim()`` at least ``dim``. dim (int): The number of rightmost dims to sum out. rN)rC)r6reshapesum)r4rArequired_shapes r&_sum_rightmostrGKsA ax [[3$'%/N == ( , ,R 00r@logits is_binaryc^|rtj|Stj|dS)a Converts a tensor of logits into probabilities. Note that for the binary case, each value denotes log odds, whereas for the multi-dimensional case, the values along the last dimension denote the log probabilities (possibly unnormalized) of the events. rC)rA)r/sigmoidFsoftmax)rHrIs r&rrYs'}}V$$ 99V $$r@probsctj|jj}|j |d|z S)aClamps the probabilities to be in the open interval `(0, 1)`. The probabilities would be clamped between `eps` and `1 - eps`, and `eps` would be the smallest representable positive number for the input data type. Args: probs (Tensor): A tensor of probabilities. Returns: Tensor: The clamped probabilities. Examples: >>> probs = torch.tensor([0.0, 0.5, 1.0]) >>> clamp_probs(probs) tensor([1.1921e-07, 5.0000e-01, 1.0000e+00]) >>> probs = torch.tensor([0.0, 0.5, 1.0], dtype=torch.float64) >>> clamp_probs(probs) tensor([2.2204e-16, 5.0000e-01, 1.0000e+00], dtype=torch.float64) )minmax)r/finfor)epsclamp)rNrTs r&rres3, ++ekk " & &C ;;3AG; ,,r@ct|}|r,tj|tj| z Stj|S)a$ Converts a tensor of probabilities into logits. For the binary case, this denotes the probability of occurrence of the event indexed by `1`. For the multi-dimensional case, the values along the last dimension denote the probabilities of occurrence of each of the events. )rr/loglog1p)rNrI ps_clampeds r&rrs?U#Jyy$u{{J;'??? 99Z  r@TT) contravariantR) covariantceZdZdZdeegefddfdZe d ddde ddfd Z ed dede defd Z d de edfde dd fd Z y)rz Used as a decorator for lazy loading of class attributes. This uses a non-data descriptor that calls the wrapped method to compute the property on first call; thereafter replacing the wrapped method into an instance attribute. wrappedrNc*||_t||yr!)r_rselfr_s r&__init__zlazy_property.__init__s)0 tW%r@instanceobj_typez!_lazy_property_and_property[T, R]cyr!rbrdres r&__get__zlazy_property.__get__s/2r@cyr!rgrhs r&rizlazy_property.__get__s?Br@z%R | _lazy_property_and_property[T, R]c|t|jStj5|j|}dddt ||jj |S#1swY,xYwr!)_lazy_property_and_propertyr_r/ enable_gradsetattr__name__)rbrdrer4s r&rizlazy_property.__get__sc  .t||< <     +LL*E +$,,//7  + +s A))A2r!) ro __module__ __qualname____doc__rrZr\rcr rrir rgr@r&rrs&!a 0&T&.222(+2 ,22BBSBABB9=ag25 0r@rc,eZdZdZdeegefddfdZy)rlzWe want lazy properties to look like multiple things. * property when Sphinx autodoc looks * lazy_property when Distribution validate_args looks r_rNc0tj||yr!)propertyrcras r&rcz$_lazy_property_and_property.__init__s$(r@)rorprqrrrrZr\rcrgr@r&rlrls% )!a 0)T)r@rlmatdiagc .|jd}tjjs$|| ks||k\rt d|d| d|dz dtj ||j }||jdd|dzzk}|d|f}|S) z Convert a `D x D` matrix or a batch of matrices into a (batched) vector which comprises of lower triangular elements from the matrix in row order. rCzdiag (z) provided is outside [z, rPz].r+.)r6r/r8r9r-aranger+view)rvrwnrz tril_maskvecs r&rrs " A 88 & & (daRi4196$'>rd"QUG2NOO \\!CJJ /FR+tax88I c9n C Jr@r~cdd|zz dd|zzdzd|jdzzdt|z|dzzzdzzdz }tj|jj }tj js0t||z |kDrtd|jddd zt|tjrt|jn t|}|j|jd dtj||fz}tj||j }||j#dd|dzzk}||d |f<|S) z Convert a vector or a batch of vectors into a batched `D x D` lower triangular matrix containing elements from the vector in row order. rPrCg?zThe size of last dimension is z which cannot be expressed as z3the lower triangular part of a square D x D matrix.Nry.)r6absr/rSr)rTr8r9roundr-r"ritem new_zerosSizerzr+r{)r~rwr|rTrvrzr}s r&rrsV a$h, DLQ SYYr]!2 2QT]dQh5O OTW W X  A ++cii $ $C 88 & & (eAhlS.@,SYYr]O;Y ZC D  &a6affhE!HA -- #2QF);; rs$$TTT  *77 6e 5 ,50,U63;5G,D D E#v+& ' D F  D V  D D 1& 1s 1v 1 %F %t % %-v-&-4 !6 !d !v ! Ct$ C4 GAqDM>)-1"5x) F # f F#fr@