Skip to content

Commit

Permalink
[NumPy] Remove references to deprecated NumPy type aliases.
Browse files Browse the repository at this point in the history
This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str).

NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy.

PiperOrigin-RevId: 496614643
Change-Id: Id77f7d25d14565de18397ba9f864c011cac7e1af
  • Loading branch information
hawkinsp authored and lanctot committed Jan 2, 2023
1 parent e2b29a8 commit 55011e6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions open_spiel/python/algorithms/alpha_zero/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def stack(train_inputs):
observation, legals_mask, policy, value = zip(*train_inputs)
return TrainInput(
np.array(observation, dtype=np.float32),
np.array(legals_mask, dtype=np.bool),
np.array(legals_mask, dtype=bool),
np.array(policy),
np.expand_dims(value, 1))

Expand Down Expand Up @@ -328,7 +328,7 @@ def inference(self, observation, legals_mask):
return self._session.run(
[self._value_out, self._policy_softmax],
feed_dict={self._input: np.array(observation, dtype=np.float32),
self._legals_mask: np.array(legals_mask, dtype=np.bool),
self._legals_mask: np.array(legals_mask, dtype=bool),
self._training: False})

def update(self, train_inputs: Sequence[TrainInput]):
Expand Down
2 changes: 1 addition & 1 deletion open_spiel/python/algorithms/lp_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def iterated_dominance(game_or_payoffs, mode, tol=1e-7):
payoffs = utils.game_payoffs_array(game_or_payoffs) if isinstance(
game_or_payoffs, pyspiel.NormalFormGame) else np.asfarray(game_or_payoffs)
live_actions = [
np.ones(num_actions, np.bool) for num_actions in payoffs.shape[1:]
np.ones(num_actions, bool) for num_actions in payoffs.shape[1:]
]
progress = True
while progress:
Expand Down
6 changes: 3 additions & 3 deletions open_spiel/python/egt/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ class SimplexStreamMask(object):
"""

def __init__(self, density=1.):
self._n = np.int(30. * density)
self._mask = np.zeros([self._n + 1] * 2 + [2], dtype=np.bool)
self._n = int(30. * density)
self._mask = np.zeros([self._n + 1] * 2 + [2], dtype=bool)
self.shape = self._mask.shape

def index(self, point):
Expand Down Expand Up @@ -561,7 +561,7 @@ def streamplot(self,

if linewidth == "velocity" or color == "velocity":
vel_max = 0
vel_min = np.float("inf")
vel_min = float("inf")
velocities = []
for t in trajectories:
dx = np.apply_along_axis(dynamics, 1, t)
Expand Down
2 changes: 1 addition & 1 deletion open_spiel/python/examples/lewis_signaling_dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def plot_confusion_matrix(cm, cmap=plt.cm.Blues, title=None):
ax_labels=["Episodes", "% optimal actions"])

plot_confusion_matrix(
converge_point.astype(np.int), title="Final policy (DQN)")
converge_point.astype(int), title="Final policy (DQN)")

plt.show()

Expand Down
2 changes: 1 addition & 1 deletion open_spiel/python/examples/lewis_signaling_qlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def plot_confusion_matrix(cm, cmap=plt.cm.Blues, title=None):

for i, cp in enumerate(converge_point_list):
plot_confusion_matrix(
cp.astype(np.int),
cp.astype(int),
title="Final policy (Tabular {})".format(labels[i]))

plt.show()
Expand Down

0 comments on commit 55011e6

Please sign in to comment.