Table of Contents

Class ObjectSpace

Namespace
Gym.Spaces
Assembly
Gym.dll

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

inner Space

The space; owned by the view from now on.

Exceptions

ArgumentNullException

Thrown when inner is null.

Properties

Inner

The wrapped space.

public Space Inner { get; }

Property Value

Space

IsNpFlattenable

Whether this space flattens to a Box (Gymnasium's is_np_flattenable).

public override bool IsNpFlattenable { get; }

Property Value

bool

NpRandom

The wrapped space's generator, never one of the view's own.

public override Generator NpRandom { get; set; }

Property Value

Generator

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

Generator

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

x object

The candidate.

Returns

bool

true for an element.

Dispose(bool)

Releases what a derived space owns (a Box's bounds); called once, by Dispose().

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose(); no space has a finalizer.

Equals(ObjectSpace?)

Equal to another view of an equal space, or to an equal space itself.

public bool Equals(ObjectSpace? other)

Parameters

other ObjectSpace

The other view.

Returns

bool

true when the wrapped spaces are equal.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

FromJsonable(object)

The wrapped space's conversion back from JSON-friendly values.

public override IList<object?> FromJsonable(object jsonable)

Parameters

jsonable object

The values.

Returns

IList<object>

The samples.

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

mask object

The wrapped space's mask.

probability object

The wrapped space's probability mask.

Returns

object

The element.

SeedCore(BigInteger?)

Seeds the wrapped space.

protected override object SeedCore(BigInteger? seed)

Parameters

seed BigInteger?

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

samples IEnumerable<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)

Parameters

space Space

A space, a view of one, or null.

Returns

Space

Inner for a view, else space unchanged (null stays null).