/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/utils.cpython-36.pyc (6802B)
3
Eg4 @ s d dl mZ d dlmZ d dlZd dljjZd dl m
Z
mZ d dlm
Z
dZdd Zd d
Zdd ZdddZdd ZdddZG dd dZG dd deeZdddZdddZdS ) )update_wrapper)NumberN)DictAny)has_torch_functiongox?c s t dd | D stdt dd | D sttj d x*| D ]"}t|tjr@t|j|jd P q@W fdd| D }tj | S tj | S ) 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`.
- numbers.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 `numbers.Number`, `torch.*Tensor` or objects implementing __torch_function__)
Raises:
ValueError: if any of the values is not a `numbers.Number` instance,
a `torch.*Tensor` instance, or an instance implementing __torch_function__
c s s. | ]&}t |tjp$t|fp$t |tV qd S )N)
isinstancetorchTensorr r ).0v r E/usr/local/lib64/python3.6/site-packages/torch/distributions/utils.py
s z broadcast_all..zqInput arguments must all be instances of numbers.Number, torch.Tensor or objects implementing __torch_function__.c S s" g | ]}t |tjpt|fqS r )r r r r )r
r r r r
s z!broadcast_all..)dtype)r devicec s4 g | ],}t |tjst|fr"|ntj|f qS r )r r r r Ztensor)r
r )optionsr r
r % s )
all
ValueErrordictr Zget_default_dtyper r r r Zbroadcast_tensors)valuesvalue
new_valuesr )r r
broadcast_all s
r c C sB t jj r.t jt j| ||dt j| ||dS t j| ||dj S )N)r r )r _C_get_tracing_statenormalZzerosZonesemptyZnormal_)shaper r r r r
_standard_normal+ s
r c C s0 |dkr| S | j d| d }| 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.
r N )r! r! )r Zreshapesum)r dimZrequired_shaper r r
_sum_rightmost3 s r$ Fc C s |rt j| S tj| ddS )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.
r )r# r! )r ZsigmoidFZsoftmax)Zlogits is_binaryr r r
logits_to_probsA s
r' c C s t j| jj}| j|d| dS )Nr )minmax)r finfor epsclamp)probsr+ r r r
clamp_probsM s r. c C s, t | }|r"tj|tj| S tj|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.
)r. r loglog1p)r- r&