
    h`
              
           S r SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  S\R                  S\\\R                  4   S	\
4S
 jrS\R                  S	\\\   \\\\S4   4   \\\R&                  4   4   4S jrg)z3
Helpers for dealing with vectorized environments.
    )AnyN)spaces)check_for_nested_spaces)	VecEnvObs	obs_spaceobs_dictreturnc                   ^ [        U [        R                  5      (       a  T$ [        U [        R                  5      (       aZ  [	        T5      [	        U R                  5      :X  d   S5       e[        U4S j[        [	        U R                  5      5       5       5      $ [        TR                  5       5      S1:X  d   S5       eTS   $ )a  
Convert an internal representation raw_obs into the appropriate type
specified by space.

:param obs_space: an observation space.
:param obs_dict: a dict of numpy arrays.
:return: returns an observation of the same type as space.
    If space is Dict, function is identity; if space is Tuple, converts dict to Tuple;
    otherwise, space is unstructured and returns the value raw_obs[None].
z<size of observation does not match size of observation spacec              3   .   >#    U  H
  nTU   v   M     g 7f)N ).0ir   s     _/home/james-whalen/.local/lib/python3.13/site-packages/stable_baselines3/common/vec_env/util.py	<genexpr>dict_to_obs.<locals>.<genexpr>   s     G*FQXa[*Fs   Nz<multiple observation keys for unstructured observation space)	
isinstancer   DictTuplelentuplerangesetkeys)r   r   s    `r   dict_to_obsr      s     )V[[))	Iv||	,	,8}I$4$4 55u7uu5G%I4D4D0E*FGGG8==?#v-m/mm-~    .c                 L   [        U 5        [        U [        R                  5      (       a3  [        U R                  [        5      (       d   S5       eU R                  nOr[        U [        R
                  5      (       a*  [        U R                  5       VVs0 s H  u  p#X#_M	     nnnO)[        U S5      (       a   S[        U 5       S35       eSU 0n/ n0 n0 nUR                  5        H2  u  pxUR                  U5        UR                  XW'   UR                  Xg'   M4     XEU4$ s  snnf )a  
Get dict-structured information about a gym.Space.

Dict spaces are represented directly by their dict of subspaces.
Tuple spaces are converted into a dict with keys indexing into the tuple.
Unstructured spaces are represented by {None: obs_space}.

:param obs_space: an observation space
:return: A tuple (keys, shapes, dtypes):
    keys: a list of dict keys.
    shapes: a dict mapping keys to shapes.
    dtypes: a dict mapping keys to dtypes.
z&Dict space must have ordered subspacesr   zUnsupported structured space ''N)r   r   r   r   dictr   	enumeratehasattrtypeitemsappendshapedtype)	r   	subspacesr   spacer   shapesdtypeskeyboxs	            r   obs_space_infor,   #   s    I&)V[[)))**D11[3[[1$$		Iv||	,	,.7	8H8H.IJ.I(!QX.I	J	9h//d3QRVW`RaQbbc1dd/9%	DFFOO%Ciiii &  Ks   D )__doc__typingr   numpynp	gymnasiumr   &stable_baselines3.common.preprocessingr   -stable_baselines3.common.vec_env.base_vec_envr   Spacer   ndarrayr   r   liststrintr%   r,   r   r   r   <module>r9      s       J C6<< 4RZZ3H Y * fll  uT#YS%PSUXPX/EY@Z\`adfhfnfnan\o5o/p  r   