Skip to content

Commit 1541ebc

Browse files
Introduce _relu function
1 parent e57a0e8 commit 1541ebc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/TerminalSystemMonitor.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function plot_cpu_utilization_rates(::Type{CPUDevice})
8484
ys = get_cpu_percent()
8585
npad = 1 + floor(Int, log10(length(ys)))
8686
xs = ["id: $(lpad(i-1, npad))" for (i, _) in enumerate(ys)]
87+
_relu(x) = max(x, zero(x))
88+
8789
function plot_cpu_utilization_rates(::Type{CPUDevice}, statfn=identity)
8890
ys = statfn(get_cpu_percent())
8991
if !(ys isa AbstractVector)
@@ -95,7 +97,9 @@ function plot_cpu_utilization_rates(::Type{CPUDevice}, statfn=identity)
9597
end
9698

9799
ncpus = length(ys)
98-
ys = round.(ys, digits = 1)
100+
# Sometimes `ys`` can be negative, so we need to use relu function so that
101+
# it ensures elements in `ys`` are positive.
102+
ys = round.(_relu.(ys), digits = 1)
99103

100104
plts = []
101105

0 commit comments

Comments
 (0)