
    j	                     H    S r SSKrSSKrSSKrSSKrS rS rS rS\	4S jr
g)zShared utility functions.    Nc                     [        U [        5      (       a  U $ U R                  5       S;   a  gU R                  5       S;   a  g[        R                  " S5      e)a   Used in argparse.ArgumentParser.add_argument to indicate
that a type is a bool type and user can enter

    - yes, true, t, y, 1, to represent True
    - no, false, f, n, 0, to represent False

See https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse  # noqa
)yestruety1T)nofalsefn0FzBoolean value expected.)
isinstanceboollowerargparseArgumentTypeError)vs    6/mnt/workspace/git/OmniVoice/omnivoice/utils/common.pystr2boolr      sL     !Twwy22	
4	4(()BCC    c                     [         R                  R                  5       (       a  g[        [         S5      (       a$  [         R                  R                  5       (       a  g[         R
                  R                  R                  5       (       a  gg)z>Auto-detect the best available device: CUDA > XPU > MPS > CPU.cudaxpumpscpu)torchr   is_availablehasattrr   backendsr    r   r   get_best_devicer!   .   sY    zz  ue!7!7!9!9~~&&((r   c                     [         R                  R                  5       (       a   S[         R                  R                  5       4$ [	        [         S5      (       aC  [         R
                  R                  5       (       a   S[         R
                  R                  5       4$ [         R                  R                  R                  5       (       a  gg)z?Auto-detect best device and return (device_type, device_count).r   r   )r      )r   r#   )r   r   r   device_countr   r   r   r   r    r   r   get_best_device_with_countr%   9   s    zz  uzz..000ue!7!7!9!9eii,,...~~&&((r   random_seedc                     [         R                  " U 5        [        R                   R                  U 5        [        R                   R	                  U 5        [         R
                  " 5       nUR                  U 5        g)zk
Set the same random seed for the libraries and modules.
Includes the ``random`` module, numpy, and torch.
N)randomseednpr   manual_seedRandom)r&   rds     r   fix_random_seedr.   D   sI    
 KKIINN;	LL[)	BGGKr   )__doc__r   r(   numpyr*   r   r   r!   r%   intr.   r    r   r   <module>r2      s2   $      D&
 
r   