Skip to content

Commit

Permalink
Clean the commit history
Browse files Browse the repository at this point in the history
  • Loading branch information
HAOCHENYE committed Feb 1, 2023
1 parent 5753cd9 commit c7264fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mmengine/logging/message_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _get_valid_value(
Returns:
float or int: python built-in type value.
"""
if isinstance(value, np.ndarray):
if isinstance(value, (np.ndarray, np.number)):
assert value.size == 1
value = value.item()
elif isinstance(value, (int, float)):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_logging/test_message_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ def test_init(self):

def test_update_scalar(self):
message_hub = MessageHub.get_instance('mmengine')
# test create target `HistoryBuffer` by name
# Update scalar with int.
message_hub.update_scalar('name', 1)
log_buffer = message_hub.log_scalars['name']
assert (log_buffer._log_history == np.array([1])).all()
# test update target `HistoryBuffer` by name
message_hub.update_scalar('name', 1)

# Update scalar with np.ndarray.
message_hub.update_scalar('name', np.array(1))
assert (log_buffer._log_history == np.array([1, 1])).all()
# unmatched string will raise a key error

# Update scalar with np.int
message_hub.update_scalar('name', np.int32(1))
assert (log_buffer._log_history == np.array([1, 1, 1])).all()

def test_update_info(self):
message_hub = MessageHub.get_instance('mmengine')
Expand Down

0 comments on commit c7264fc

Please sign in to comment.