
    h                        S 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
Jr  SSKJrJr  SSKJr  SS	KJrJrJr  S
/r " S S
\\R,                  R.                  5      rg)zFVector wrapper for converting between Array API compatible frameworks.    )annotations)
ModuleType)AnyN)ActTypeObsType)	VectorEnvVectorWrapper)	ArrayType)Devicearray_conversionmodule_name_to_namespaceArrayConversionc                  x    \ rS rSrSr  S         SS jjr    SS jrSSS.     SS jjrS rS	 r	S
r
g)r      a%  Wraps a vector environment returning Array API compatible arrays so that it can be interacted with through a specific framework.

Popular Array API frameworks include ``numpy``, ``torch``, ``jax.numpy``, ``cupy`` etc. With this wrapper, you can convert outputs from your environment to
any of these frameworks. Conversely, actions are automatically mapped back to the environment framework, if possible without moving the
data or device transfers.

Notes:
    A vectorized version of :class:`gymnasium.wrappers.ArrayConversion`

Example:
    >>> import gymnasium as gym                                         # doctest: +SKIP
    >>> envs = gym.make_vec("JaxEnv-vx", 3)                             # doctest: +SKIP
    >>> envs = ArrayConversion(envs, xp=np)                             # doctest: +SKIP
Nc                    [         R                  R                  R                  U 5        [        R                  " X5        X l        X0l        X@l        XPl        g)at  Wrapper class to change inputs and outputs of environment to any Array API framework.

Args:
    env: The Array API compatible environment to wrap
    env_xp: The Array API framework the environment is on
    target_xp: The Array API framework to convert to
    env_device: The device the environment is on
    target_device: The device on which Arrays should be returned
N)	gymutilsRecordConstructorArgs__init__r	   _env_xp
_target_xp_env_device_target_device)selfenvenv_xp	target_xp
env_devicetarget_devices         d/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/wrappers/vector/array_conversion.pyr   ArrayConversion.__init__&   s@    " 			''006t)#%+    c           
        [        XR                  U R                  S9nU R                  R	                  U5      u  p#pEn[        X R
                  U R                  S9[        X0R
                  U R                  S9[        X@R
                  U R                  S9[        XPR
                  U R                  S9[        X`R
                  U R                  S94$ )zTransforms the action to the specified xp module array type.

Args:
    actions: The action to perform

Returns:
    A tuple containing xp versions of the next observation, reward, termination, truncation, and extra info.
xpdevice)r   r   r   r   stepr   r   )r   actionsobsreward
terminated	truncatedinfos          r    r'   ArrayConversion.step>   s     #7||DDTDTU3788==3I0ZD S__T=P=PQV@S@STt7J7J Y??4CVCVWTood>Q>QR
 	
r"   seedoptionsc                   U(       a  [        X R                  U R                  S9n[        U R                  R	                  XS9U R
                  U R                  S9$ )zResets the environment returning xp-based observation and info.

Args:
    seed: The seed for resetting the environment
    options: The options for resetting the environment, these are converted to xp arrays.

Returns:
    xp-based observations and info
r$   r/   )r   r   r   r   resetr   r   )r   r0   r1   s      r    r3   ArrayConversion.resetV   sQ     &LL1A1AG  HHNNN6&&
 	
r"   c                    U R                   R                  R                  SS5      nU R                  R                  R                  SS5      nU R                  nU R
                  nUUUUU R                  S.$ )z5Returns the object pickle state with args and kwargs.zarray_api_compat. )env_xp_nametarget_xp_namer   r   r   )r   __name__replacer   r   r   r   )r   r7   r8   r   r   s        r    __getstate__ArrayConversion.__getstate__p   so    ll++334GL1199:MrR%%
++&,$*88
 	
r"   c                    US   U l         [        US   5      U l        [        US   5      U l        US   U l        US   U l        g)z%Sets the object pickle state using d.r   r7   r8   r   r   N)r   r   r   r   r   r   )r   ds     r    __setstate__ArrayConversion.__setstate__~   sI    U8/-0@A215E3FG\?0r"   )r   r   r   r   r   )NN)
r   r   r   ModuleType | strr   rA   r   Device | Noner   rB   )r(   r   returnz5tuple[ObsType, ArrayType, ArrayType, ArrayType, dict])r0   zint | list[int] | Noner1   zdict[str, Any] | NonerC   ztuple[ObsType, dict[str, Any]])r9   
__module____qualname____firstlineno____doc__r   r'   r3   r;   r?   __static_attributes__ r"   r    r   r      s    ( %)'+,, !, $	,
 ", %,0

	>
6 (,)-	
 %
 '	

 
(
4
1r"   )rG   
__future__r   typesr   typingr   	gymnasiumr   gymnasium.corer   r   gymnasium.vectorr   r	   gymnasium.vector.vector_envr
   #gymnasium.wrappers.array_conversionr   r   r   __all__r   r   r   rI   r"   r    <module>rS      sK    L "    + 5 1  
n1mSYY%D%D n1r"   