o
    
jt
                     @   sN   d dl mZ d dlmZ d dlZd dlZdefddZdddZ	dd	d
Z
dS )    )AnyNvaluec                 C   sL   t | tjr		 | S t | trt| } | S t| r"|   } | S t	d)a  
    Validates the input and makes sure it returns a numpy array (i.e on CPU)

    Args:
        value (Any): the input value

    Raises:
        TypeError: if the value is not a numpy array or torch tensor

    Returns:
        np.ndarray: numpy array of the value
    z5Value must be a numpy array, a torch tensor or a list)

isinstancenpndarraylistarraytorch	is_tensorcpunumpy	TypeError)r    r   Y/home/kuhnn/.local/lib/python3.10/site-packages/TTS/tts/layers/overflow/plotting_utils.pyvalidate_numpy_array   s   


r   c                 C   s   t j| ddd }|jd }|jd }|dd|d|}t |d|d| j}|durO||j	dt j
|jd g|jdddd dj	}|S |}|S )	a|  Get the most probable state means from the log_alpha_scaled.

    Args:
        log_alpha_scaled (torch.Tensor): Log alpha scaled values.
            - Shape: :math:`(T, N)`
        means (torch.Tensor): Means of the states.
            - Shape: :math:`(N, T, D_out)`
        decoder (torch.nn.Module): Decoder module to decode the latent to melspectrogram. Defaults to None.
       )dimr      N)deviceT)reverse)r	   maxshape	unsqueezeexpandgathersqueezetodtypeTtensorr   )log_alpha_scaledmeansdecodermax_state_numbersmax_lenn_mel_channelsmelr   r   r   !get_spec_from_most_probable_state!   s   


,r'   Fc                 C   s   t | } t |}tjdd\}}||d |d |d |d |dd tt	|D  |j
d	d | D d
d t  |sIt  |S )zGenerates trainsition probabilities plot for the states and the probability of transition.

    Args:
        states (torch.IntTensor): the states
        transition_probabilities (torch.FloatTensor): the transition probabilities
    )      )figsizeozTransition probability of statezhidden stateprobabilityc                 S   s   g | ]}|qS r   r   ).0ir   r   r   
<listcomp>J   s    z:plot_transition_probabilities_to_numpy.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   )int)r-   xr   r   r   r/   K   s    Z   )rotation)r   pltsubplotsplot	set_title
set_xlabel
set_ylabel
set_xticksrangelenset_xticklabelstight_layoutclose)statestransition_probabilities
output_figfigaxr   r   r   &plot_transition_probabilities_to_numpy;   s   


rE   )N)F)typingr   matplotlib.pyplotpyplotr4   r   r   r	   r   r'   rE   r   r   r   r   <module>   s    
