Class ObjectSpace
Any space seen as a Space<object?>, for an env typed Env<object?, object?> whose spaces
vary (Gymnasium's generic test envs take any space). Everything forwards to Inner: sampling, membership,
seeding, the generator, repr and equality, so the view behaves as the space itself.
public sealed class ObjectSpace : Space<object?>, IDisposable, IEquatable<ObjectSpace>
- Inheritance
-
ObjectSpace
- Implements
- Inherited Members
- Extension Methods
Remarks
Gym.NET's spaces are typed by their elements (DR-07), and a Box is a Space<NDArray>, which C#
cannot treat as a Space<object?> (classes are not covariant). This view bridges the two;
((IEnv)env).ActionSpace = box wraps automatically for an env whose action type is object.
The view owns the space it wraps: disposing the view (as its env does) disposes Inner.
Constructors
ObjectSpace(Space)
Wraps a space.
public ObjectSpace(Space inner)
Parameters
innerSpaceThe space; owned by the view from now on.
Exceptions
- ArgumentNullException
Thrown when
inneris null.
Properties
Inner
The wrapped space.
public Space Inner { get; }
Property Value
IsNpFlattenable
Whether this space flattens to a Box (Gymnasium's is_np_flattenable).
public override bool IsNpFlattenable { get; }
Property Value
NpRandom
The wrapped space's generator, never one of the view's own.
public override Generator NpRandom { get; set; }
Property Value
NpRandomOrNull
The generator if one exists, without creating it (Gymnasium's _np_random); for code that must not draw OS
entropy just to look, such as a parity check of an unseeded space.
public override Generator? NpRandomOrNull { get; }
Property Value
Methods
Contains(object?)
Whether x is an element of this space (Gymnasium's contains and x in space).
Values of the wrong kind return false rather than throwing, as in Gymnasium.
public override bool Contains(object? x)
Parameters
xobjectThe candidate.
Returns
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
Equals(ObjectSpace?)
Equal to another view of an equal space, or to an equal space itself.
public bool Equals(ObjectSpace? other)
Parameters
otherObjectSpaceThe other view.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
FromJsonable(object)
The wrapped space's conversion back from JSON-friendly values.
public override IList<object?> FromJsonable(object jsonable)
Parameters
jsonableobjectThe values.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Sample(object?, object?)
The wrapped space's sample, as it returns it.
public override object? Sample(object? mask = null, object? probability = null)
Parameters
Returns
- object
The element.
SeedCore(BigInteger?)
Seeds the wrapped space.
protected override object SeedCore(BigInteger? seed)
Parameters
seedBigInteger?The seed, or null for entropy.
Returns
- object
The wrapped space's seed(s).
ToJsonable(IEnumerable<object?>)
The wrapped space's JSON conversion.
public override object ToJsonable(IEnumerable<object?> samples)
Parameters
samplesIEnumerable<object>Samples of the wrapped space.
Returns
- object
Their JSON-friendly values.
ToString()
The wrapped space's repr.
public override string ToString()
Returns
- string
The text.
Unview(Space?)
The space a value of an env's space really is: the wrapped space for a view, the space itself otherwise. Code
that dispatches on the space's class (isinstance(env.observation_space, spaces.Box)) must look through
the view, or an untyped env's Box would read as no Box at all.
public static Space? Unview(Space? space)