Table of Contents

Class Tuple

Namespace
Gym.Spaces
Assembly
Gym.dll

The cartesian product of spaces: every element is a tuple (an object?[], DR-13's generic form) holding one element of each subspace, in order, such as Blackjack's (player sum, dealer card, usable ace).

public class Tuple : Space<object?[]>, IDisposable, IReadOnlyList<Space>, IReadOnlyCollection<Space>, IEnumerable<Space>, IEnumerable, IEquatable<Tuple>
Inheritance
Tuple
Implements
Inherited Members
Extension Methods

Remarks

Named as Gymnasium names it, so using System; makes Tuple ambiguous with Tuple (CS0104): Gym.NET's files alias it, using Tuple = Gym.Spaces.Tuple; (port plan ยง3.8).

The space owns its subspaces: disposing it disposes them. Reference: gymnasium/spaces/tuple.py.

Constructors

Tuple(params Space[])

The product of the given subspaces.

public Tuple(params Space[] spaces)

Parameters

spaces Space[]

The subspaces, in order.

Exceptions

TypeError

Thrown for a null subspace.

Tuple(IEnumerable<Space>, SpaceSeed?)

The product of spaces (Gymnasium's Tuple(spaces, seed=seed)).

public Tuple(IEnumerable<Space> spaces, SpaceSeed? seed = null)

Parameters

spaces IEnumerable<Space>

The subspaces, in order; the tuple owns them from now on.

seed SpaceSeed?

An integer seed (it seeds the tuple's own generator, which then draws one int32 seed per subspace), a generator to share, or null.

Exceptions

TypeError

Thrown for a null subspace, Gymnasium's "does not inherit from gymnasium.Space".

ArgumentNullException

Thrown when spaces is null.

Error

Thrown when an integer seed is negative.

Properties

Count

The number of subspaces (Gymnasium's len(space)).

public int Count { get; }

Property Value

int

IsNpFlattenable

Whether every subspace flattens to a box.

public override bool IsNpFlattenable { get; }

Property Value

bool

this[int]

The subspace at index (Gymnasium's space[index]).

public Space this[int index] { get; }

Parameters

index int

The index; negative counts from the end, as in Python.

Property Value

Space

The subspace.

Exceptions

IndexError

Thrown for an index outside the tuple: tuple index out of range.

Spaces

The subspaces (Gymnasium's spaces).

public IReadOnlyList<Space> Spaces { get; }

Property Value

IReadOnlyList<Space>

Methods

Contains(object?)

Whether x is an element (Gymnasium's contains): a tuple (or a list, a .NET array, or an array along its first axis, which Gymnasium promotes) with one member of each subspace, in order.

public override bool Contains(object? x)

Parameters

x object

The candidate.

Returns

bool

true for an element.

CountOf(Space)

How many subspaces equal value (Gymnasium's count, from Python's Sequence mixin; named CountOf because Count is the length).

public int CountOf(Space value)

Parameters

value Space

The space to look for; compared with Equals(object), Python's ==.

Returns

int

The number of equal subspaces.

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(Tuple?)

Gymnasium's ==: the same subspaces, equal in order.

public bool Equals(Tuple? other)

Parameters

other Tuple

The other tuple.

Returns

bool

true when 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)

Converts Gymnasium's per-subspace JSON lists back to tuples (Gymnasium's from_jsonable).

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

Parameters

jsonable object

The list of per-subspace lists.

Returns

IList<object[]>

The samples.

Exceptions

ValueError

Thrown when the per-subspace lists differ in length (Python's zip(strict=True)).

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<Space> GetEnumerator()

Returns

IEnumerator<Space>

An enumerator that can be used to iterate through the collection.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

IndexOf(Space, int, int?)

The position of the first subspace equal to value within [start, stop) (Gymnasium's index, from Python's Sequence mixin); negative bounds count from the end, as in Python.

public int IndexOf(Space value, int start = 0, int? stop = null)

Parameters

value Space

The space to look for.

start int

The first position searched.

stop int?

One past the last position searched, or null for the end.

Returns

int

The position.

Exceptions

ValueError

Thrown when no subspace in the range equals value (Python's bare ValueError).

Sample(object?, object?)

Draws one element (Gymnasium's sample): one sample from each subspace, in order, optionally under a tuple of per-subspace masks or probability masks.

public override object?[] Sample(object? mask = null, object? probability = null)

Parameters

mask object

null, or a tuple (an object?[] or an ITuple) with one mask (or null) per subspace.

probability object

null, or a tuple with one probability mask (or null) per subspace.

Returns

object[]

A new tuple of the subspaces' samples; arrays in it are owned by the caller.

Exceptions

ValueError

Thrown when both masks are given.

AssertionError

Thrown for a mask that is not a tuple of the right length, with Gymnasium's messages.

SeedCore(BigInteger?)

Gymnasium's Tuple.seed for an integer or null: null seeds every subspace from entropy; an integer seeds the tuple's generator, which draws one seed below int32's maximum per subspace (integers(iinfo(int32).max, size=len)).

protected override object SeedCore(BigInteger? seed)

Parameters

seed BigInteger?

The seed, or null.

Returns

object

The subspaces' seeds, as a list.

Exceptions

Error

Thrown for a negative seed.

SeedListCore(IReadOnlyList<object?>)

Gymnasium's Tuple.seed for a list: one seed (of any form) per subspace.

protected override object SeedListCore(IReadOnlyList<object?> seeds)

Parameters

seeds IReadOnlyList<object>

The seeds.

Returns

object

The subspaces' seeds.

Exceptions

ValueError

Thrown when the list's length is not the number of subspaces.

SeedTypeError(object?)

Gymnasium's Tuple.seed error for a seed that is not an integer, a list, a tuple or null.

protected override Exception SeedTypeError(object? seed)

Parameters

seed object

The refused seed.

Returns

Exception

TypeError: Expected seed type: list, tuple, int or None, actual type: <class 'dict'>.

ToJsonable(IEnumerable<object?[]>)

Converts samples to Gymnasium's JSON form, a list with one entry per subspace, each the subspace's to_jsonable of that position across the batch.

public override object ToJsonable(IEnumerable<object?[]> samples)

Parameters

samples IEnumerable<object[]>

Samples of this space.

Returns

object

The per-subspace lists.

ToString()

Gymnasium's repr: Tuple(Discrete(2), Box(-1.0, 1.0, (2,), float32)).

public override string ToString()

Returns

string

The text.