
    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rSSK	J
r
   " S S\
\\S	4      \R                  \   5      rg)
zPImplementation of a space that represents the cartesian product of other spaces.    )annotationsN)Iterable)Any)Spacec                     ^  \ rS rSrSr S   SU 4S jjjr\S 5       rSSU 4S jjjr  S     SS jjr	SS jr
SS jr    SS	 jrSS
 jrSS jrSS jrSS jrSrU =r$ )Tuple   a  A tuple (more precisely: the cartesian product) of :class:`Space` instances.

Elements of this space are tuples of elements of the constituent spaces.

Example:
    >>> from gymnasium.spaces import Tuple, Box, Discrete
    >>> observation_space = Tuple((Discrete(2), Box(-1, 1, shape=(2,))), seed=42)
    >>> observation_space.sample()
    (np.int64(0), array([-0.3991573 ,  0.21649833], dtype=float32))
c                   > [        U5      U l        U R                   H-  n[        U[        5      (       a  M   U S[	        U5       35       e   [
        TU ]  SSU5        g)ap  Constructor of :class:`Tuple` space.

The generated instance will represent the cartesian product :math:`\text{spaces}[0] \times ... \times \text{spaces}[-1]`.

Args:
    spaces (Iterable[Space]): The spaces that are involved in the cartesian product.
    seed: Optionally, you can use this argument to seed the RNGs of the ``spaces`` to ensure reproducible sampling.
z7 does not inherit from `gymnasium.Space`. Actual Type: N)tuplespaces
isinstancer   typesuper__init__)selfr   seedspace	__class__s       P/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/spaces/tuple.pyr   Tuple.__init__   sj     Fm[[Eu  ^OPTUZP[}]^  ! 	tT*    c                :    [        S U R                   5       5      $ )zDChecks whether this space can be flattened to a :class:`spaces.Box`.c              3  8   #    U  H  oR                   v   M     g 7fN)is_np_flattenable.0r   s     r   	<genexpr>*Tuple.is_np_flattenable.<locals>.<genexpr>1   s     Du**s   )allr   r   s    r   r   Tuple.is_np_flattenable.   s     DDDDr   c                  > Uc  [        S U R                   5       5      $ [        U[        5      (       a  [        TU ]  U5        U R                  R                  [        R                  " [        R                  5      R                  [        U R                  5      S9n[        S [        U R                  U5       5       5      $ [        U[         [        45      (       at  [        U5      [        U R                  5      :w  a-  [        S[        U5       S[        U R                  5       35      e[        S [        XR                  5       5       5      $ [!        S[#        U5       35      e)a  Seed the PRNG of this space and all subspaces.

Depending on the type of seed, the subspaces will be seeded differently

* ``None`` - All the subspaces will use a random initial seed
* ``Int`` - The integer is used to seed the :class:`Tuple` space that is used to generate seed values for each of the subspaces. Warning, this does not guarantee unique seeds for all the subspaces.
* ``List`` / ``Tuple`` - Values used to seed the subspaces. This allows the seeding of multiple composite subspaces ``[42, 54, ...]``.

Args:
    seed: An optional list of ints or int to seed the (sub-)spaces.

Returns:
    A tuple of the seed values for all subspaces
c              3  B   #    U  H  oR                  S 5      v   M     g 7fr   r   r   s     r   r   Tuple.seed.<locals>.<genexpr>C   s     C{eD)){s   )sizec              3  Z   #    U  H!  u  pUR                  [        U5      5      v   M#     g 7fr   )r   int)r   subspacesubseeds      r   r   r&   I   s*      )C%H c'l++)Cs   )+z\Expects that the subspaces of seeds equals the number of subspaces. Actual length of seeds: z, length of subspaces: c              3  H   #    U  H  u  pUR                  U5      v   M     g 7fr   r%   )r   r+   r   s      r   r   r&   S   s"      :P

7##:P    "z;Expected seed type: list, tuple, int or None, actual type: )r   r   r   r)   r   r   	np_randomintegersnpiinfoint32maxlenziplist
ValueError	TypeErrorr   )r   r   subseedsr   s      r   r   
Tuple.seed3   sW    <Ct{{CCCc""GL~~.."&&S-= / H  ),T[[()C   udm,,4yC,, rsvw{s|r}  ~U  VY  Z^  Ze  Ze  Vf  Ug  h   :=dKK:P   MdSWj\Z r   c                   Ub  Ub  [        SU SU 35      eUb  [        U[        5      (       d   S[        U5       35       e[	        U5      [	        U R
                  5      :X  d)   S[	        U R
                  5       S[	        U5       35       e[        S [        U R
                  U5       5       5      $ Ub  [        U[        5      (       d   S[        U5       35       e[	        U5      [	        U R
                  5      :X  d)   S[	        U R
                  5       S[	        U5       35       e[        S	 [        U R
                  U5       5       5      $ [        S
 U R
                   5       5      $ )a  Generates a single random sample inside this space.

This method draws independent samples from the subspaces.

Args:
    mask: An optional tuple of optional masks for each of the subspace's samples,
        expects the same number of masks as spaces
    probability: An optional tuple of optional probability masks for each of the subspace's samples,
        expects the same number of probability masks as spaces

Returns:
    Tuple of the subspace's samples
zIOnly one of `mask` or `probability` can be provided, actual values: mask=z, probability=z2Expected type of `mask` to be tuple, actual type: z Expected length of `mask` to be z, actual length: c              3  D   #    U  H  u  pUR                  US 9v   M     g7f))maskNsample)r   r   
space_masks      r   r   Tuple.sample.<locals>.<genexpr>y   s%      )?%E *-)?    z9Expected type of `probability` to be tuple, actual type: z'Expected length of `probability` to be c              3  D   #    U  H  u  pUR                  US 9v   M     g7f))probabilityNr>   )r   r   space_probabilitys      r   r   rA      s&      0M,E ):;0MrB   c              3  @   #    U  H  oR                  5       v   M     g 7fr   r>   r   s     r   r   rA      s     A[E[s   )r7   r   r   r   r4   r   r5   )r   r=   rD   s      r   r?   Tuple.sample[   s   $  7[\`[aaop{o|}  e  QCDJ<PQ  t9!  a1#dkk2B1CCTUXY]U^T_`a   ),T[[$)?  
 $U  _J4P[K\J]^_  {#s(  o8T[[9I8JJ[\_`k\l[mno   03DKK0M  
 AT[[AAAr   c                ,   [        U[        [        R                  45      (       a  [	        U5      n[        U[        5      =(       aN    [        U5      [        U R                  5      :H  =(       a&    [        S [        U R                  U5       5       5      $ )z?Return boolean specifying if x is a valid member of this space.c              3  H   #    U  H  u  pUR                  U5      v   M     g 7fr   )contains)r   r   parts      r   r   !Tuple.contains.<locals>.<genexpr>   s      R>Q]eENN4((>Qr-   )	r   r6   r0   ndarrayr   r4   r   r    r5   )r   xs     r   rJ   Tuple.contains   sl    a$

+,,aA q%  SA#dkk**SRc$++q>QRR	
r   c           	         SSR                  U R                   Vs/ s H  n[        U5      PM     sn5      -   S-   $ s  snf )z,Gives a string representation of this space.zTuple(z, ))joinr   str)r   ss     r   __repr__Tuple.__repr__   s5    $))T[[$A[SV[$ABBSHH$As   <
c                    [        U R                  5       VVVs/ s H)  u  p#UR                  U Vs/ s H  oDU   PM	     sn5      PM+     snnn$ s  snf s  snnnf )zCConvert a batch of samples from this space to a JSONable data type.)	enumerater   to_jsonabler   sample_nir   r?   s        r   rY   Tuple.to_jsonable   sS     &dkk2
2 x@xVayx@A2
 	
@
s   AAAAc           
         [        [        U R                  5       VVs/ s H  u  p#UR                  X   5      PM     snn6  Vs/ s H  nUPM     sn$ s  snnf s  snf )zCConvert a JSONable data type to a batch of samples from this space.)r5   rX   r   from_jsonablerZ   s        r   r_   Tuple.from_jsonable   sl      %.dkk$:$: ''4$:
 
 	

s   A
Ac                     U R                   U   $ )z%Get the subspace at specific `index`.r   )r   indexs     r   __getitem__Tuple.__getitem__   s    {{5!!r   c                ,    [        U R                  5      $ )zGGet the number of subspaces that are involved in the cartesian product.)r4   r   r!   s    r   __len__Tuple.__len__   s    4;;r   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ )z7Check whether ``other`` is equivalent to this instance.)r   r   r   )r   others     r   __eq__Tuple.__eq__   s!    %'GDKK5<<,GGr   rb   r   )r   zIterable[Space[Any]]r   z7int | typing.Sequence[int] | np.random.Generator | None)r   z!int | typing.Sequence[int] | Nonereturnztuple[int, ...])NN)r=   tuple[Any | None, ...] | NonerD   rn   rm   ztuple[Any, ...])rN   r   rm   bool)rm   rS   )r[   z typing.Sequence[tuple[Any, ...]]rm   list[list[Any]])r[   rp   rm   zlist[tuple[Any, ...]])rc   r)   rm   z
Space[Any])rm   r)   )rj   r   rm   ro   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r?   rJ   rU   rY   r_   rd   rg   rk   __static_attributes____classcell__)r   s   @r   r   r      s    	 IM+$+ F+ +( E E& &T /3590B+0B 30B 
	0Bd	
I
8
	


" H Hr   r   .)ru   
__future__r   typingcollections.abcr   r   numpyr0   gymnasium.spaces.spacer   r   Sequencer    r   r   <module>r      sB    V "  $   (nHE%S/"FOOC$8 nHr   