Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sequence to accept stacked np arrays if the feature space is Box #241

Merged
merged 7 commits into from
Jan 5, 2023
Merged

Conversation

jjshoots
Copy link
Member

@jjshoots jjshoots commented Jan 5, 2023

Description

This allows the Sequence space to accept numpy arrays of size [n, *base_size] if the feature space of the Sequence is Box(shape=base_size).

Fixes # (issue)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'm very uncertain of this implementation.

I don't understand the difference between the new and old contains functions. Could you provide an example where the old would fail and it won't with new?

There are a couple of places in the code that need modifying if we want the whole space to support stacked sequences

@jjshoots
Copy link
Member Author

jjshoots commented Jan 5, 2023

@pseudo-rnd-thoughts The simplest case where the old would fail is the test_stacked_box test.

We're not really accepting stacked sequences, we're just allowing the sequence space to accept np.stack([array_a, array_b, array_c]) if the base feature space is Box.

More concisely, this is the only difference:

import numpy as np
>>> sample = np.float32(np.random.rand(5, 3))
>>> sample
array([[0.55573964, 0.5059766 , 0.1776721 ],
       [0.78431445, 0.19933775, 0.75381595],
       [0.82225245, 0.5078049 , 0.24258688],
       [0.66441643, 0.7965829 , 0.9005535 ],
       [0.31705654, 0.6865207 , 0.25575027]], dtype=float32)
import collections.abc
>>> isinstance(sample, collections.abc.Iterable)
True
>>> isinstance(sample, collections.abc.Sequence)
False

@pseudo-rnd-thoughts
Copy link
Member

Could the contains function not just have Sequence changed to Iterable.
Personally, I prefer the contains functions to check if the sample is positively contained within the space rather than negatively if that makes any sense.

I guess we can add this but @kad99kev will be looking into adding this feature to the whole space.

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit c2a3877 into Farama-Foundation:main Jan 5, 2023
@jjshoots jjshoots deleted the sequence-box-numpy branch January 6, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants