pub struct VecEnv<E: Env> { /* private fields */ }Expand description
Synchronous vectorized environment.
Wraps a Vec<E> of homogeneous environments. All environments must share
the same obs_dim and action_dim; this is validated lazily on the first
step call to avoid redundant checks.
§Auto-reset
When step detects that environment i is done, it immediately calls
reset() on it and places the resulting observation in the corresponding
slot of VecStepResult::obs.
§Example
use oxicuda_rl::env::env::LinearQuadraticEnv;
use oxicuda_rl::env::vectorized::VecEnv;
let envs: Vec<_> = (0..4).map(|_| LinearQuadraticEnv::new(3, 50)).collect();
let mut ve = VecEnv::new(envs);
let obs = ve.reset_all().unwrap();
assert_eq!(obs.len(), 4 * 3);Implementations§
Source§impl<E: Env> VecEnv<E>
impl<E: Env> VecEnv<E>
Sourcepub fn new(envs: Vec<E>) -> Self
pub fn new(envs: Vec<E>) -> Self
Create a new VecEnv from a non-empty vector of environments.
§Panics
Does not panic; returns an instance even with an empty envs slice
(though subsequent calls will fail with RlError::DimensionMismatch).
Sourcepub fn step(&mut self, actions: &[f32]) -> RlResult<VecStepResult>
pub fn step(&mut self, actions: &[f32]) -> RlResult<VecStepResult>
Step all environments simultaneously.
actions must have length n_envs × action_dim; the slice is split
into per-environment chunks before dispatch.
§Errors
RlError::DimensionMismatch—actions.len()is not a multiple ofn_envs, or a chunk length does not match the environment’saction_dim.- Any error propagated from individual
step()orreset()calls.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for VecEnv<E>
impl<E> RefUnwindSafe for VecEnv<E>where
E: RefUnwindSafe,
impl<E> Send for VecEnv<E>where
E: Send,
impl<E> Sync for VecEnv<E>where
E: Sync,
impl<E> Unpin for VecEnv<E>where
E: Unpin,
impl<E> UnsafeUnpin for VecEnv<E>
impl<E> UnwindSafe for VecEnv<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more