Skip to content

Commit

Permalink
Fix deprecation warnings (#703)
Browse files Browse the repository at this point in the history
* fix deprecation warnings in numpy 1.25
* add corresponding tests
  • Loading branch information
lanpa committed Jun 25, 2023
1 parent 246a867 commit 55ef907
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tensorboardX/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def scalar(name, scalar, display_name="", summary_description=""):
name = _clean_tag(name)
scalar = make_np(scalar)
assert scalar.squeeze().ndim == 0, 'scalar should be 0D'
scalar = float(scalar)
scalar = float(scalar.squeeze())
if display_name == "" and summary_description == "":
return Summary(value=[Summary.Value(tag=name, simple_value=scalar)])

Expand Down
2 changes: 1 addition & 1 deletion tensorboardX/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def __append_to_scalar_dict(self, tag, scalar_value, global_step,
if tag not in self.scalar_dict.keys():
self.scalar_dict[tag] = []
self.scalar_dict[tag].append(
[timestamp, global_step, float(make_np(scalar_value))])
[timestamp, global_step, float(make_np(scalar_value).squeeze())])

def _check_caffe2_blob(self, item):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pytest
import unittest
import torch
# compare_proto = write_proto # massive update expect

def tensor_N(shape, dtype=float):
Expand Down Expand Up @@ -39,6 +40,14 @@ def test_list_input(self):
with pytest.raises(Exception):
summary.histogram('dummy', [1, 3, 4, 5, 6], 'tensorflow')

def test_0d_input(self):
x = torch.rand(1)
summary.scalar('0d', x[0])

def test_1d_input(self):
x = torch.rand(1)
summary.scalar('0d', x)

def test_empty_input(self):
print('expect error here:')
with pytest.raises(Exception):
Expand Down

0 comments on commit 55ef907

Please sign in to comment.