bugfix for empty_ (#114)

* bugfix for empty_

* use v.__class__(0) for scalar
This commit is contained in:
youkaichao 2020-07-08 08:10:34 +08:00 committed by GitHub
parent 69caf89908
commit 9c7d31e5d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -569,10 +569,8 @@ class Batch:
else: # scalar value
warnings.warn('You are calling Batch.empty on a NumPy scalar, '
'which may cause undefined behaviors.')
if isinstance(v, (np.generic, Number)):
self.__dict__[k] *= 0
if np.isnan(self.__dict__[k]):
self.__dict__[k] = 0
if isinstance(v, (np.number, np.bool_, Number)):
self.__dict__[k] = v.__class__(0)
else:
self.__dict__[k] = None
return self