You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [2]: a=Batch(a={})
In [3]: b=Batch(a=torch.tensor([3,4], device='cuda'))
In [4]: Batch.cat([a,b])
will raise an exception. Same as Batch.stack:
~/github/tianshou-new/tianshou/data/batch.pyin_is_scalar(value)
37# the check of dict / Batch is omitted because this only checks a value.38# a dict / Batch will eventually check their values--->39value=np.asanyarray(value)
40returnvalue.size==1andnotvalue.shape41~/.local/lib/python3.6/site-packages/numpy/core/_asarray.pyinasanyarray(a, dtype, order)
136137 """
-->138returnarray(a, dtype, copy=False, order=order, subok=True)
139140~/.local/lib/python3.6/site-packages/torch/tensor.pyin__array__(self, dtype)
490def__array__(self, dtype=None):
491ifdtypeisNone:
-->492returnself.numpy()
493else:
494returnself.numpy().astype(dtype, copy=False)
TypeError: can'tconvertcuda:0devicetypetensortonumpy. UseTensor.cpu() tocopythetensortohostmemoryfirst.
The text was updated successfully, but these errors were encountered:
def_is_scalar(value: Any) ->bool:
# check if the value is a scalar# 1. python bool object, number object: isinstance(value, Number)# 2. numpy scalar: isinstance(value, np.generic)# 3. python object rather than dict / Batch / tensor# the check of dict / Batch is omitted because this only checks a value.# a dict / Batch will eventually check their valuesifisinstance(value, (dict, Batch)):
returnFalse#=================== add these two linesifisinstance(value, torch.Tensor):
returnvalue.numel() ==1andnotvalue.shapevalue=np.asanyarray(value)
returnvalue.size==1andnotvalue.shape
will raise an exception. Same as Batch.stack:
The text was updated successfully, but these errors were encountered: