
    hH                    f   S r SSKJr  SSKrSSKJrJrJr  SSKJ	r	  SSK
Jr  SSKJr  SSKrSSKJr  SS	KJrJrJrJrJrJrJrJrJrJrJrJr  SS
KJr  / SQr \S0S1S jj5       r!\!RE                  \5      S0S2S jj5       r#\!RE                  \5      S0S3S jj5       r$\!RE                  \5      S0S4S jj5       r%\!RE                  \5      S0S5S jj5       r&\!RE                  \5      S0S6S jj5       r'\!RE                  \5      S0S7S jj5       r(\!RE                  \5      \!RE                  \5      \!RE                  \5      \!RE                  \5      \!RE                  \5      S0S8S jj5       5       5       5       5       r)\S9S j5       r*\*RE                  \5      S:S j5       r+\*RE                  \5      S;S j5       r,\*RE                  \5      S<S j5       r-\*RE                  \5      S=S j5       r.\*RE                  \5      S>S j5       r/\*RE                  \5      S?S j5       r0\*RE                  \5      \*RE                  \5      \*RE                  \5      \*RE                  \5      S@S j5       5       5       5       r1\SAS j5       r2\2RE                  \5      SBS j5       r3\2RE                  \5      \2RE                  \5      \2RE                  \5      SCS j5       5       5       r4\2RE                  \5      SDS  j5       r5\2RE                  \5      SES! j5       r6\        SFS" j5       r7\7RE                  \5      \7RE                  \5      \7RE                  \5      \7RE                  \5              SGS# j5       5       5       5       r8\7RE                  \5              SHS$ j5       r9\7RE                  \5              SIS% j5       r:\7RE                  \5      \7RE                  \5      \7RE                  \5      \7RE                  \5      \7RE                  \5      SJS& j5       5       5       5       5       r;\S\Rx                  4       SKS' jj5       r=\=RE                  \5      \=RE                  \5      \=RE                  \5      \=RE                  \5      S\Rx                  4SLS( jj5       5       5       5       r>\=RE                  \5      S\Rx                  4SMS) jj5       r?\=RE                  \5      S\Rx                  4SNS* jj5       r@\=RE                  \5      S\Rx                  4     SOS+ jj5       rA\=RE                  \5      S\Rx                  4SPS, jj5       rB\=RE                  \5      S\Rx                  4     SQS- jj5       rC\=RE                  \5      S\Rx                  4SRS. jj5       rD\=RE                  \5      S\Rx                  4S/ j5       rEg)SaT  Space-based utility functions for vector environments.

- ``batch_space``: Create a (batched) space containing multiple copies of a single space.
- ``batch_differing_spaces``: Create a (batched) space containing copies of different compatible spaces (share a common dtype and shape)
- ``concatenate``: Concatenate multiple samples from (unbatched) space into a single object.
- ``Iterate``: Iterate over the elements of a (batched) space and items.
- ``create_empty_array``: Create an empty (possibly nested) (normally numpy-based) array, used in conjunction with ``concatenate(..., out=array)``
    )annotationsN)CallableIterableIteratordeepcopy)singledispatch)Any)CustomSpaceError)BoxDictDiscreteGraphGraphInstanceMultiBinaryMultiDiscreteOneOfSequenceSpaceTextTuple)T_cov)batch_spacebatch_differing_spacesiterateconcatenatecreate_empty_array   c                6    [        S[        U 5       SU  35      e)a  Batch spaces of size `n` optimized for neural networks.

Args:
    space: Space (e.g. the observation space for a single environment in the vectorized environment).
    n: Number of spaces to batch by (e.g. the number of environments in a vectorized environment).

Returns:
    Batched space of size `n`.

Raises:
    ValueError: Cannot batch spaces that does not have a registered function.

Example:

    >>> from gymnasium.spaces import Box, Dict
    >>> import numpy as np
    >>> space = Dict({
    ...     'position': Box(low=0, high=1, shape=(3,), dtype=np.float32),
    ...     'velocity': Box(low=0, high=1, shape=(2,), dtype=np.float32)
    ... })
    >>> batch_space(space, n=5)
    Dict('position': Box(0.0, 1.0, (5, 3), float32), 'velocity': Box(0.0, 1.0, (5, 2), float32))
zMThe space provided to `batch_space` is not a gymnasium Space instance, type: , 	TypeErrortypespacens     \/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/vector/utils/space_utils.pyr   r   /   s,    2 
WX\]bXcWddfglfmn     c                "   [        U/S/U R                  R                  -  -   5      n[        R                  " U R                  U5      [        R                  " U R
                  U5      pC[        X4U R                  [        U R                  5      S9$ Nr   lowhighdtypeseed)
tupler,   ndimnptiler-   r   r.   r   	np_randomr%   r&   repeatsr,   r-   s        r'   _batch_space_boxr7   M   sc    QC1#		../G		7+RWWUZZ-I38EOO;TUUr(   c                    [        [        R                  " U4U R                  U R                  S9U R                  [        U R                  5      [        R                  " U4U R                  U R                  S9S9$ )Nr.   )r.   r/   start)r   r2   fullr&   r.   r   r4   r:   r$   s     r'   _batch_space_discreter<   T   sV    
eggU[[1kkeoo&ggqdEKKu{{;	 r(   c                2   [        U/S/U R                  R                  -  -   5      n[        R                  " U R
                  U5      nU[        R                  " U R                  U5      -   S-
  n[        UUU R                  [        U R                  5      S9$ r*   )
r0   nvecr1   r2   r3   r:   r   r.   r   r4   r5   s        r'   _batch_space_multidiscreter?   ^   sz    QC1#

//0G
''%++w
'CW--1Dkkeoo&	 r(   c           	     r    [        SSU4U R                  -   U R                  [        U R                  5      S9$ )Nr   r   r,   r-   shaper.   r/   )r   rB   r.   r   r4   r$   s     r'   _batch_space_multibinaryrC   k   s6    dU[[ kkeoo& r(   c                x   ^ [        [        U4S jU R                   5       5      [        U R                  5      S9$ )Nc              3  8   >#    U  H  n[        UTS 9v   M     g7f)r&   N)r   ).0subspacer&   s     r'   	<genexpr>%_batch_space_tuple.<locals>.<genexpr>y   s     FXk(a(s   r/   )r   r0   spacesr   r4   r$   s    `r'   _batch_space_tuplerM   v   s.    FFFeoo& r(   c                    [        U R                  5        VVs0 s H  u  p#U[        X1S9_M     snn[        U R                  5      S9$ s  snnf )NrF   rK   )r   itemsr   r   r4   )r%   r&   keyrH   s       r'   _batch_space_dictrQ   ~   sB    >CkkmLm]Sk((	(mLeoo& Ls   A	
c           
       ^  [        [        U 4S j[        U5       5       5      [        T R                  5      S9n[        T R                  5      n[        [        [        UR                  SSU5      5      5      nUR                  U5        U$ )Nc              3  :   >#    U  H  n[        T5      v   M     g 7fNr   rG   _r%   s     r'   rI   &_batch_space_custom.<locals>.<genexpr>   s     0x!huoox   rK   r   g    חA)
r   r0   ranger   r4   listmapintintegersr/   )r%   r&   batched_space	space_rng	new_seedss   `    r'   _batch_space_customra      sp     0uQx00x7PM )ISi00C;<=Iy!r(   c                t  ^  [        T 5      S:  d   S5       e[        U 4S jT  5       5      (       d$   ST  Vs/ s H  n[        U5      PM     sn 35       e[        T S   5      [        R                  ;   d   S[        R                   35       e[        R                  [        T S   5      5      " T 5      $ s  snf )a  Batch a Sequence of spaces where subspaces to contain minor differences.

Args:
    spaces: A sequence of Spaces with minor differences (the same space type but different parameters).

Returns:
    A batched space

Example:
    >>> from gymnasium.spaces import Discrete
    >>> spaces = [Discrete(3), Discrete(5), Discrete(4), Discrete(8)]
    >>> batch_differing_spaces(spaces)
    MultiDiscrete([3 5 4 8])
r   z"Expects a non-empty list of spacesc              3  T   >#    U  H  n[        U[        TS    5      5      v   M     g7fr   N)
isinstancer#   rG   r%   rL   s     r'   rI   )batch_differing_spaces.<locals>.<genexpr>   s&      8>u
5$vay/**s   %(z7Expects all spaces to be the same shape, actual types: zTRequires the Space type to have a registered `batch_differing_space`, current list: )lenallr#   r   registrydispatchrL   r%   s   ` r'   r   r      s      v;?@@@? 8>   e	@[aAb[aRW$u+[aAb@cde  	VAY1:::@	]^t^}^}]~@: "**4q	?;FCC Bcs   B5c           	       ^  [        U 4S jT  5       5      (       d$   ST  Vs/ s H  oR                  PM     sn 35       e[        U 4S jT  5       5      (       d.   ST  Vs/ s H  oR                  R                  PM     sn 35       e[        U 4S jT  5       5      (       d.   ST  Vs/ s H  oR                  R                  PM     sn 35       e[        [        R                  " T  Vs/ s H  oR                  PM     sn5      [        R                  " T  Vs/ s H  oR                  PM     sn5      T S   R                  [        T S   R                  5      S9$ s  snf s  snf s  snf s  snf s  snf )	Nc              3  \   >#    U  H!  nTS    R                   UR                   :H  v   M#     g7frd   r9   rf   s     r'   rI   ._batch_differing_spaces_box.<locals>.<genexpr>   %      4:5q	5;;&F   ),*Expected all dtypes to be equal, actually c              3     >#    U  H5  nTS    R                   R                  UR                   R                  :H  v   M7     g7frd   )r,   rB   rf   s     r'   rI   ro      s/      <B5q	uyy.F   =A z1Expected all Box.low shape to be equal, actually c              3     >#    U  H5  nTS    R                   R                  UR                   R                  :H  v   M7     g7frd   )r-   rB   rf   s     r'   rI   ro      1      >DUq	

 0 00frt   z2Expected all Box.high shape to be equal, actually r   r+   )
ri   r.   r,   rB   r-   r   r2   arrayr   r4   rl   s   ` r'   _batch_differing_spaces_boxrx      sn    4:   X	3f4UfU[[f4U3VWX   <B   c	:Y_;`Y_PUIIOOY_;`:abc   >D   e	;[a<b[aRWZZ=M=M[a<b;cde  HHV4VEiiV45XXv6vezzv67QioofQi))*	  5V <a =c 56s   E E (E%)E*E/c           	        [        [        R                  " U  Vs/ s H  oR                  PM     sn5      [        R                  " U  Vs/ s H  oR                  PM     sn5      [        U S   R                  5      S9$ s  snf s  snf )Nr   )r>   r:   r/   )r   r2   rw   r&   r:   r   r4   rl   s     r'    _batch_differing_spaces_discreterz      sa    XXF3F5wwF34hh889fQi))* 38s   A>	Bc           
       ^  [        U 4S jT  5       5      (       d$   ST  Vs/ s H  oR                  PM     sn 35       e[        U 4S jT  5       5      (       d.   ST  Vs/ s H  oR                  R                  PM     sn 35       e[        U 4S jT  5       5      (       d.   ST  Vs/ s H  oR                  R                  PM     sn 35       e[        [        R                  " T  Vs/ s H  oR                  PM     sn5      [        R                  " T  Vs/ s H  oR                  UR                  -   PM     sn5      S-
  T S   R                  [        T S   R                  5      S	9$ s  snf s  snf s  snf s  snf s  snf )
Nc              3  \   >#    U  H!  nTS    R                   UR                   :H  v   M#     g7frd   r9   rf   s     r'   rI   9_batch_differing_spaces_multi_discrete.<locals>.<genexpr>   rp   rq   rr   c              3     >#    U  H5  nTS    R                   R                  UR                   R                  :H  v   M7     g7frd   )r>   rB   rf   s     r'   rI   r}      rv   rt   z/Expects all MultiDiscrete.nvec shape, actually c              3     >#    U  H5  nTS    R                   R                  UR                   R                  :H  v   M7     g7frd   )r:   rB   rf   s     r'   rI   r}      s1      @Fuq	!2!22rt   z0Expects all MultiDiscrete.start shape, actually r   r   r+   )
ri   r.   r>   rB   r:   r   r2   rw   r   r4   rl   s   ` r'   &_batch_differing_spaces_multi_discreter      s}    4:   X	3f4UfU[[f4U3VWX   >D   b	8X^9_X^u**:J:JX^9_8`ab   @F   d	9Z`:aZ`QV;;;L;LZ`:a9bcd  HHv6vekkv67XXVDVE{{UZZ/VDEIQioofQi))*	  5V :` ;b 7Ds   E+ E0(E5)E:"E?c           
        ^  [        U 4S jT  5       5      (       d   e[        SS[        T 5      4T S   R                  -   T S   R                  [        T S   R                  5      S9$ )Nc              3  \   >#    U  H!  nTS    R                   UR                   :H  v   M#     g7frd   )rB   rf   s     r'   rI   7_batch_differing_spaces_multi_binary.<locals>.<genexpr>   s"     B6%vay%++-6rq   r   r   rA   )ri   r   rh   rB   r.   r   r4   )rL   s   `r'   $_batch_differing_spaces_multi_binaryr      s`    B6BBBBB6{nvay.QioofQi))* r(   c                    [        [        S [        U  Vs/ s H  oR                  PM     sn6  5       5      [	        U S   R
                  5      S9$ s  snf )Nc              3  8   #    U  H  n[        U5      v   M     g 7frT   )r   )rG   	subspacess     r'   rI   0_batch_differing_spaces_tuple.<locals>.<genexpr>   s      
E	 #9--Es   r   rK   )r   r0   ziprL   r   r4   rl   s     r'   _batch_differing_spaces_tupler      sT     
 V"DVE<<V"DE
 	
 fQi))*  #Es   Ac                  ^  [        U 4S jT  5       5      (       d   e[        T S   R                  5        VVs0 s H"  nU[        T  Vs/ s H  o"U   PM	     sn5      _M$     snn[	        T S   R
                  5      S9$ s  snf s  snnf )Nc              3  l   >#    U  H)  nTS    R                  5       UR                  5       :H  v   M+     g7frd   )keysrf   s     r'   rI   /_batch_differing_spaces_dict.<locals>.<genexpr>   s'     DVEvay~~5::</Vs   14r   rK   )ri   r   r   r   r   r4   )rL   rP   r%   s   `  r'   _batch_differing_spaces_dictr      s    DVDDDDD ay~~'	
' '(Hs(HII'	
 fQi))* (H	
s   B
	A?B
?B
c                    [        U  Vs/ s H  n[        U5      PM     sn[        U S   R                  5      S9$ s  snf )Nr   rK   )r   r   r4   rl   s     r'   _batch_spaces_undefinedr     s;    
 &,-fU%f-HVAY=P=P4Q -s   ;c                    [        U [        5      (       a$  [        S[        U 5       S[        U 5       S35      e[	        S[        U 5       SU  35      e)a  Iterate over the elements of a (batched) space.

Args:
    space: (batched) space (e.g. `action_space` or `observation_space` from vectorized environment).
    items: Batched samples to be iterated over (e.g. sample from the space).

Example:
    >>> from gymnasium.spaces import Box, Dict
    >>> import numpy as np
    >>> space = Dict({
    ... 'position': Box(low=0, high=1, shape=(2, 3), seed=42, dtype=np.float32),
    ... 'velocity': Box(low=0, high=1, shape=(2, 2), seed=42, dtype=np.float32)})
    >>> items = space.sample()
    >>> it = iterate(space, items)
    >>> next(it)
    {'position': array([0.77395606, 0.43887845, 0.85859793], dtype=float32), 'velocity': array([0.77395606, 0.43887845], dtype=float32)}
    >>> next(it)
    {'position': array([0.697368  , 0.09417735, 0.97562236], dtype=float32), 'velocity': array([0.85859793, 0.697368  ], dtype=float32)}
    >>> next(it)
    Traceback (most recent call last):
        ...
    StopIteration
zSpace of type `z;` doesn't have an registered `iterate` function. Register `z` for `iterate` to support it.zIThe space provided to `iterate` is not a gymnasium Space instance, type: r    )re   r   r   r#   r"   r%   rO   s     r'   r   r     so    2 %d5k]*efjkpfqer  sQ  R
 	
 WX\]bXcWddfglfmn
 	
r(   c                    [        S5      e)Nz2Unable to iterate over a space of type `Discrete`.)r"   r   s     r'   _iterate_discreter   5  s    
H
IIr(   c                \     [        U5      $ ! [         a  n[        SU 35      UeS nAff = f)Nz/Unable to iterate over the following elements: )iterr"   )r%   rO   es      r'   _iterate_baser   :  s;    E{ =eWE
	s   
 
+&+c                   [        S U  5       5      (       a2  [        [        U 5       VVs/ s H  u  p#[        X1U   5      PM     snn6 $  [	        U5      $ s  snnf ! [
         a[  nU  Vs/ s H-  n[        U5      [        R                  ;  d  M"  [        U5      PM/     Os  snf nn[        SU  SU SU S35      UeS nAff = f)Nc              3  Z   #    U  H!  n[        U5      [        R                  ;   v   M#     g 7frT   )r#   r   rj   )rG   rH   s     r'   rI   !_iterate_tuple.<locals>.<genexpr>I  s     
De(4>W---es   )+zCould not iterate through z1 as no custom iterate function is registered for z/ and `iter(items)` raised the following error: .)	ri   r   	enumerater   r   	Exceptionr#   rj   r   )r%   rO   irH   r   unregistered_spacess         r'   _iterate_tupler   F  s     
De
DDDIeDTUDT[QWXQx0DTUVV
E{ V   "
!H~W%5%55 DN!
 

 (/`at`u  ve  fg  eh  hi  j
	s/   A

A 
C&B<*!BBB<<Cc              #    #    [        U R                  R                  5        VVs/ s H  u  p#U[        X1U   5      4PM     snn6 u  pE[        U6  H%  n[        XF5       VVs0 s H  u  p'X'_M	     snnv   M'     g s  snnf s  snnf 7frT   )r   rL   rO   r   )r%   rO   rP   rH   r   valuesitemvalues           r'   _iterate_dictr   Y  s      "'!3!3!5

!5 '(#J/0!5

LD V,/O<OjcszO<< 

 =s   #BA:
 B!B /Bc                6    [        S[        U 5       SU  35      e)ac  Concatenate multiple samples from space into a single object.

Args:
    space: Space of each item (e.g. `single_action_space` from vectorized environment)
    items: Samples to be concatenated (e.g. all sample should be an element of the `space`).
    out: The output object (e.g. generated from `create_empty_array`)

Returns:
    The output object, can be the same object `out`.

Raises:
    ValueError: Space is not a valid :class:`gymnasium.Space` instance

Example:
    >>> from gymnasium.spaces import Box
    >>> import numpy as np
    >>> space = Box(low=0, high=1, shape=(3,), seed=42, dtype=np.float32)
    >>> out = np.zeros((2, 3), dtype=np.float32)
    >>> items = [space.sample() for _ in range(2)]
    >>> concatenate(space, items, out)
    array([[0.77395606, 0.43887845, 0.85859793],
           [0.697368  , 0.09417735, 0.97562236]], dtype=float32)
zMThe space provided to `concatenate` is not a gymnasium Space instance, type: r    r!   r%   rO   outs      r'   r   r   e  s,    6 
WX\]bXcWddfglfmn r(   c                .    [         R                  " USUS9$ )Nr   )axisr   )r2   stackr   s      r'   _concatenate_baser     s     88Es++r(   c                X   ^^ [        UU4S j[        U R                  5       5       5      $ )Nc           	   3  x   >#    U  H*  u  p[        UT Vs/ s H  o3U   PM	     snTU   5      v   M,     g s  snf 7frT   )r   )rG   r   rH   r   rO   r   s       r'   rI   %_concatenate_tuple.<locals>.<genexpr>  s@      4MQ 	H5954Aw593q6BB4 :s   :5:)r0   r   rL   r   s    ``r'   _concatenate_tupler     s(      &u||4  r(   c                    U R                  5        VVVs0 s H'  u  p4U[        XA Vs/ s H  oUU   PM	     snX#   5      _M)     snnn$ s  snf s  snnnf rT   )rO   r   )r%   rO   r   rP   rH   r   s         r'   _concatenate_dictr     sU     #[[]*MC 	[%#@%$I%#@#(KK* #@s   AAAAc                    [        U5      $ rT   r0   r   s      r'   _concatenate_customr     s     <r(   c                6    [        S[        U 5       SU  35      e)a  Create an empty (possibly nested and normally numpy-based) array, used in conjunction with ``concatenate(..., out=array)``.

In most cases, the array will be contained within the batched space, however, this is not guaranteed.

Args:
    space: Observation space of a single environment in the vectorized environment.
    n: Number of environments in the vectorized environment. If ``None``, creates an empty sample from ``space``.
    fn: Function to apply when creating the empty numpy array. Examples of such functions are ``np.empty`` or ``np.zeros``.

Returns:
    The output object. This object is a (possibly nested) numpy array.

Raises:
    ValueError: Space is not a valid :class:`gymnasium.Space` instance

Example:
    >>> from gymnasium.spaces import Box, Dict
    >>> import numpy as np
    >>> space = Dict({
    ... 'position': Box(low=0, high=1, shape=(3,), dtype=np.float32),
    ... 'velocity': Box(low=0, high=1, shape=(2,), dtype=np.float32)})
    >>> create_empty_array(space, n=2, fn=np.zeros)
    {'position': array([[0., 0., 0.],
           [0., 0., 0.]], dtype=float32), 'velocity': array([[0., 0.],
           [0., 0.]], dtype=float32)}
zTThe space provided to `create_empty_array` is not a gymnasium Space instance, type: r    r!   r%   r&   fns      r'   r   r     s,    < 
^_cdi_j^kkmnsmtu r(   c                @    U" U4U R                   -   U R                  S9$ )Nr9   )rB   r.   r   s      r'   _create_empty_array_multir     s      qdU[[ 44r(   c                F   ^^ [        UU4S jU R                   5       5      $ )Nc              3  :   >#    U  H  n[        UTTS 9v   M     g7f)r&   r   N)r   )rG   rH   r   r&   s     r'   rI   ,_create_empty_array_tuple.<locals>.<genexpr>  s     W,h#Hb9,rX   )r0   rL   r   s    ``r'   _create_empty_array_tupler     s    W%,,WWWr(   c                j    U R                  5        VVs0 s H  u  p4U[        XAUS9_M     snn$ s  snnf )Nr   )rO   r   )r%   r&   r   rP   rH   s        r'   _create_empty_array_dictr     s<     LQ;;=KX-#"55=  s   /c                   ^ ^ T R                   b  [        UU 4S j[        U5       5       5      $ [        UU 4S j[        U5       5       5      $ )Nc           
   3     >#    U  H  n[        T" S TR                  R                  -   TR                  R                  S9T" S TR                  R                  -   TR                  R                  S9T" S[
        R                  S9S9v   M     g7f)r   r9   )r      nodesedges
edge_linksN)r   
node_spacerB   r.   
edge_spacer2   int64rG   rV   r   r%   s     r'   rI   ,_create_empty_array_graph.<locals>.<genexpr>  s}      
   0 0 6 66e>N>N>T>TU 0 0 6 66e>N>N>T>TUfBHH5
 s   BBc              3     >#    U  H@  n[        T" S TR                  R                  -   TR                  R                  S9SSS9v   MB     g7f)r   r9   Nr   )r   r   rB   r.   r   s     r'   rI   r     sN      
   0 0 6 66e>N>N>T>TU
 s   AA)r   r0   rY   r   s   ` `r'   _create_empty_array_graphr     sS     # 
 1X
 
 	
  
 1X
 
 	
r(   c                @   ^  [        U 4S j[        U5       5       5      $ )Nc              3  \   >#    U  H!  nTR                   S    TR                  -  v   M#     g7frd   )
characters
min_lengthrU   s     r'   rI   +_create_empty_array_text.<locals>.<genexpr>  s'     JA!!!$u'7'77rq   r0   rY   r   s   `  r'   _create_empty_array_textr     s    JqJJJr(   c                   ^ ^ T R                   (       a  [        UU 4S j[        U5       5       5      $ [        S [        U5       5       5      $ )Nc              3  N   >#    U  H  n[        TR                  S TS9v   M     g7f)r   r   N)r   feature_spacer   s     r'   rI   /_create_empty_array_sequence.<locals>.<genexpr>	  s$      
IQAu22aB?s   "%c              3  6   #    U  H  n[        5       v   M     g 7frT   r   rG   rV   s     r'   rI   r     s     /hUWWh   )r   r0   rY   r   s   ` `r'   _create_empty_array_sequencer     sA     {{ 
INq
 
 	
 /eAh///r(   c                8    [        S [        U5       5       5      $ )Nc              3  6   #    U  H  n[        5       v   M     g 7frT   r   r   s     r'   rI   ,_create_empty_array_oneof.<locals>.<genexpr>  s     +(Q(r   r   r   s      r'   _create_empty_array_oneofr     s    +%(+++r(   c                    g rT    r   s      r'   _create_empty_array_customr     s    r(   r   )r%   
Space[Any]r&   r\   returnr   )r%   r   r&   r\   )r%   r   r&   r\   )r%   r   r&   r\   )r%   r   r&   r\   )r%   r   r&   r\   )r%   r   r&   r\   )r%   zGraph | Text | Sequence | OneOfr&   r\   )rL   ztyping.Sequence[Space]r   r   )rL   z	list[Box])rL   zlist[Discrete])rL   zlist[MultiDiscrete])rL   zlist[MultiBinary])rL   zlist[Tuple])rL   z
list[Dict])rL   z%list[Graph | Text | Sequence | OneOf])r%   zSpace[T_cov]rO   r   r   r   )r%   r   rO   r   )r%   z!Box | MultiDiscrete | MultiBinaryrO   
np.ndarray)r%   r   rO   tuple[Any, ...])r%   r   rO   dict[str, Any])r%   r   rO   r   r   -tuple[Any, ...] | dict[str, Any] | np.ndarrayr   r   )r%   z,Box | Discrete | MultiDiscrete | MultiBinaryrO   r   r   r   r   r   )r%   r   rO   r   r   r   r   r   )r%   r   rO   r   r   r   r   r   )r%   r   rO   r   r   Noner   r   )r%   r   r&   r\   r   r   r   r   )r%   r   r&   r\   r   r   )r%   r   r&   r\   r   r   )r%   r   r&   r\   r   r   )r%   r   r&   r\   r   ztuple[GraphInstance, ...])r%   r   r&   r\   r   ztuple[str, ...])r%   r   r&   r\   r   r   )r%   r   r&   r\   )F__doc__
__future__r   typingcollections.abcr   r   r   copyr   	functoolsr	   r
   numpyr2   gymnasium.errorr   gymnasium.spacesr   r   r   r   r   r   r   r   r   r   r   r   gymnasium.spaces.spacer   __all__r   registerr7   r<   r?   rC   rM   rQ   ra   r   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zerosr   r   r   r   r   r   r   r   r   r   r(   r'   <module>r      s   #  8 8  $   ,    )  : cV V h   m$	 %	 k" # e  d  edhee	      
	 D D4   % &&   * +   / 0&   -	 .	   ' (   &	 '	   '  &  *  ' ( + ' ( 
 
D 	(J J 	#- +  !  	% $ 	$= = !(U2 > chm$k",7,, 
, 	, # %   , e!(7  d '5  edhee      
 RXX"*2 F S!X&]+[)34 5 * , ' "
5 U#56288 X $X T"34  # U#



 $
. T"34 K #K X&BHH0000 '0 U#56288 , $, U#()bhh  $r(   