-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow two (same/different) Batch objs to be tested for equality #1098
Allow two (same/different) Batch objs to be tested for equality #1098
Conversation
* Introduce a new test class named `TestBatchEquality`. * Got rid of comments and assert messages as the test method names are expressive enough.
* Restrict to Batch in method
* Add tests for `Batch.to_dict()` * Add deepdiff library (for testing equality of dicts in the tests mentioned above) * Update poetry.toml and poetry.lock
* Note: `Batch.to_numpy()` should be extended to support also a non in-place operation.
tianshou/data/batch.py
Outdated
if not isinstance(other, self.__class__): | ||
return False | ||
|
||
self.to_numpy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modifies self and other inplace on a supposedly harmless equality check - this should never happen.
Starting a new thread about the questions you raised regarding to_numpy
.
- For other methods we have the convention that things ending in
_
are inplace. So it should really be thatto_numpy_
operates inplace and returns nothing, whereasto_numpy()
doesn't change the original and returns a new batch. That's a breaking change, so you'd need to check all the places whereto_numpy
is currently being used. - I think the name
to_numpy
is ok for the moment, since all values of batch are either batches, tensors or arrays, right? Then it's clear thatto_numpy
would turn all tensors into arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Batch.to_torch()
has same problem because it is also in-place. We can change this in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks for bringing it up! We should generally reduce the number of inplace operations as much as possible
* Breaking change: Previous in-place `Batch.to_numpy` is now `Batch.to_numpy_` (following naming convention of other in-place methods). * Update places where in-place was expected * Add tests for both to_numpy/to_numpy_
Closes: #1086
Api Extensions
to_numpy_
. Allow two (same/different) Batch objs to be tested for equality #1098to_dict
in Batch supports also non-recursive conversion. Allow two (same/different) Batch objs to be tested for equality #1098__eq__
now implemented, semantic equality check of batches is now possible. Allow two (same/different) Batch objs to be tested for equality #1098Breaking Changes
to_numpy
indata.utils.batch.Batch
is not in-place anymore. Instead, a new methodto_numpy_
does the conversion in-place. Allow two (same/different) Batch objs to be tested for equality #1098