Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to PrettyTables v2 #46

Merged
merged 4 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "GFlops"
uuid = "2ea8233c-34d4-5acc-88b4-02f326385bcc"
license = "MIT"
authors = ["François Févotte <francois.fevotte@triscale-innov.com>"]
version = "0.1.7"
version = "0.1.8"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand All @@ -15,8 +15,8 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
BenchmarkTools = "^0.4.2, 0.5, 0.6, 0.7, 1"
Cassette = "^0.2.3, 0.3.2"
PrettyTables = "^0.12, 1"
julia = "^1"
PrettyTables = "^2"
julia = "^1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
21 changes: 11 additions & 10 deletions src/Counter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ end
import Base: ==, *, show

function Base.show(io::IO, c::Counter)
fl = flop(c)
print(io, "Flop Counter: $fl flop")
fl == 0 && return

type_names = [typ for (typ, _) in typs]
type_suffix = [suffix for (_, suffix) in typs]
op_names = [name for (name, _) in ops]
Expand All @@ -27,18 +31,15 @@ function Base.show(io::IO, c::Counter)
name in op_names,
suffix in type_suffix]

fl = flop(c)
print(io, "Flop Counter: $fl flop")
fl == 0 && return
# PrettyTables now needs data to be filtered ahead of time:
rows = filter(i -> any(mat[i,:] .> 0), 1:size(mat, 1))
cols = filter(i -> any(mat[:,i] .> 0), 1:size(mat, 2))
mat = mat[rows, cols]

print(io, "\n")
fc(data, i) = any(data[:,i] .> 0)
fr(data, i) = any(data[i,:] .> 0)
pretty_table(io, mat,
header = type_names,
row_names = op_names,
filters_col = (fc,),
filters_row = (fr,),
pretty_table(io, mat;
header = type_names[cols],
row_labels = op_names[rows],
newline_at_end = false)
end

Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ GFlops.times(::BenchmarkTools.Trial) = [2.0, 3.0]
@test occursin(" 1 ", str)
end
end

@testset "display mixed" begin
let
cnt = GFlops.Counter()
cnt.add32 = 1
cnt.mul64 = 2
str = string(cnt)
@test occursin("Float32", str)
@test occursin("Float64", str)
@test occursin("add", str)
@test occursin("mul", str)
@test !occursin("div", str)
@test occursin(" 1 ", str)
@test occursin(" 2 ", str)
end
end
end

@testset "@count_ops" begin
Expand Down
Loading