Skip to content

Commit

Permalink
Merge pull request #46 from triscale-innov/ck/compat
Browse files Browse the repository at this point in the history
Update to PrettyTables v2
  • Loading branch information
ffevotte authored Aug 27, 2023
2 parents 98385e8 + 17e1203 commit 408cdee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
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

0 comments on commit 408cdee

Please sign in to comment.