CoolFace
Apppublic

declare-lab/tango2

sourceHugging Faceupdated 2y agoView on Hugging Face
92likes
outputs.cpython-39.pyc33 linesDownload Raw Back to __pycache__
1a

2��'d9�@s\dZddlmZddlmZddlmZmZddlZ	ddl3mZdd	�ZGd4d�de�Z
dS)z5Generic utilities6�)�OrderedDict)�fields)�Any�TupleN�)�is_torch_availablecCs*t�rddl}t||j�rdSt|tj�S)z;7    Tests if `x` is a `torch.Tensor` or `np.ndarray`.8    rNT)r�torch�9isinstance�Tensor�np�ndarray)�xr�r�L/home/deep/Projects/audio_diffusion/diffusers/src/diffusers/utils/outputs.py�	is_tensors10rcsneZdZdZdd�Zdd�Zdd�Zdd	�Zd11d�Zdd
�Z	�fdd�Z12�fdd�Zee
d�dd�Z�ZS)�13BaseOutputa�14    Base class for all model outputs as dataclass. Has a `__getitem__` that allows indexing by integer or slice (like a15    tuple) or strings (like a dictionary) that will ignore the `None` attributes. Otherwise behaves like a regular16    python dictionary.17 18    <Tip warning={true}>19 20    You can't unpack a `BaseOutput` directly. Use the [`~utils.BaseOutput.to_tuple`] method to convert it to a tuple21    before.22 23    </Tip>24    cs�t��}t|�s"t�jj�d���t�|dj�}t�fdd�|dd�D��}|rzt|t	�rz|�25�D]\}}|�|<qfn(|D]"}t�|j�}|dur~|�|j<q~dS)Nz has no fields.rc3s|]}t�|j�duVqdS�N)�getattr�name)�.0�field��selfrr�	<genexpr>>�z+BaseOutput.__post_init__.<locals>.<genexpr>r)r�len�26ValueError�	__class__�__name__rr�allr	�dict�items)r�class_fields�first_field�other_fields_are_none�key�valuer�vrrr�
__post_init__6szBaseOutput.__post_init__cOstd|jj�d���dS)Nz$You cannot use ``__delitem__`` on a �27 instance.��	Exceptionrr�r�args�kwargsrrr�__delitem__IszBaseOutput.__delitem__cOstd|jj�d���dS)Nz#You cannot use ``setdefault`` on a r)r*r,rrr�28setdefaultLszBaseOutput.setdefaultcOstd|jj�d���dS)NzYou cannot use ``pop`` on a r)r*r,rrr�popOszBaseOutput.popcOstd|jj�d���dS)NzYou cannot use ``update`` on a r)r*r,rrr�updateRszBaseOutput.updatecCs.t|t�rt|���}||S|��|SdSr)r	�strr r!�to_tuple)r�k�29inner_dictrrr�__getitem__Us30zBaseOutput.__getitem__cs4||��vr"|dur"t��||�t��||�dSr)�keys�super�__setitem__�__setattr__)rrr&�rrrr;\szBaseOutput.__setattr__cs t��||�t��||�dSr)r9r:r;)rr%r&r<rrr:bszBaseOutput.__setitem__)�returncst�fdd����D��S)za31        Convert self to a tuple containing all the attributes/keys that are not `None`.32        c3s|]}�|VqdSrr)rr5rrrrlrz&BaseOutput.to_tuple.<locals>.<genexpr>)�tupler8rrrrr4hszBaseOutput.to_tuple)r�33__module__�__qualname__�__doc__r(r/r0r1r2r7r;r:rrr4�
__classcell__rrr<rr(s
r)rA�collectionsr�dataclassesr�typingrr�numpyr�import_utilsrrrrrrr�<module>s