[NumPy] Replace numpy.asscalar(x) with x.item() in preparation for upgrading NumPy to 1.23.

NumPy 1.23 removes numpy.asscalar() (https://numpy.org/doc/stable/release/1.23.0-notes.html#expired-deprecations), which has been deprecated since NumPy 1.16 (https://numpy.org/doc/stable/release/1.16.0-notes.html#new-deprecations).

x.item() should be identical to the previous implementation of numpy.asscalar(x) in every way.

PiperOrigin-RevId: 466743223
This commit is contained in:
Peter Hawkins 2022-08-10 11:26:30 -07:00 committed by A. Unique TensorFlower
parent 6718ae2636
commit 857fe8f482

View file

@ -190,7 +190,7 @@ def rdp_gaussian(logq, sigma, orders):
assert np.all(ret >= 0) assert np.all(ret >= 0)
if np.isscalar(orders): if np.isscalar(orders):
return np.asscalar(ret) return ret.item()
else: else:
return ret return ret
@ -357,7 +357,7 @@ def rdp_pure_eps(logq, pure_eps, orders):
np.minimum(0.5 * pure_eps * pure_eps * orders_vec, np.minimum(0.5 * pure_eps * pure_eps * orders_vec,
log_t / (orders_vec - 1)), pure_eps) log_t / (orders_vec - 1)), pure_eps)
if np.isscalar(orders): if np.isscalar(orders):
return np.asscalar(ret) return ret.item()
else: else:
return ret return ret