mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[rllib] Make RLLib handle zero-length observation arrays (#5208)
* [rllib] Make _summarize handle zero-len arrays Fixes #5207 * [rllib] Make aligned_array() handle empty arrays * [rllib] Conform with old yapf
This commit is contained in:
parent
3e0ad11ae0
commit
214f09d969
2 changed files with 9 additions and 2 deletions
|
@ -78,7 +78,10 @@ def _summarize(obj):
|
||||||
elif isinstance(obj, tuple):
|
elif isinstance(obj, tuple):
|
||||||
return tuple(_summarize(x) for x in obj)
|
return tuple(_summarize(x) for x in obj)
|
||||||
elif isinstance(obj, np.ndarray):
|
elif isinstance(obj, np.ndarray):
|
||||||
if obj.dtype == np.object:
|
if obj.size == 0:
|
||||||
|
return _StringValue("np.ndarray({}, dtype={})".format(
|
||||||
|
obj.shape, obj.dtype))
|
||||||
|
elif obj.dtype == np.object:
|
||||||
return _StringValue("np.ndarray({}, dtype={}, head={})".format(
|
return _StringValue("np.ndarray({}, dtype={}, head={})".format(
|
||||||
obj.shape, obj.dtype, _summarize(obj[0])))
|
obj.shape, obj.dtype, _summarize(obj[0])))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -56,7 +56,11 @@ def aligned_array(size, dtype, align=64):
|
||||||
empty = np.empty(n + (align - 1), dtype=np.uint8)
|
empty = np.empty(n + (align - 1), dtype=np.uint8)
|
||||||
data_align = empty.ctypes.data % align
|
data_align = empty.ctypes.data % align
|
||||||
offset = 0 if data_align == 0 else (align - data_align)
|
offset = 0 if data_align == 0 else (align - data_align)
|
||||||
output = empty[offset:offset + n].view(dtype)
|
if n == 0:
|
||||||
|
# stop np from optimising out empty slice reference
|
||||||
|
output = empty[offset:offset + 1][0:0].view(dtype)
|
||||||
|
else:
|
||||||
|
output = empty[offset:offset + n].view(dtype)
|
||||||
|
|
||||||
assert len(output) == size, len(output)
|
assert len(output) == size, len(output)
|
||||||
assert output.ctypes.data % align == 0, output.ctypes.data
|
assert output.ctypes.data % align == 0, output.ctypes.data
|
||||||
|
|
Loading…
Add table
Reference in a new issue