Skip to content

Commit

Permalink
🤖 Format .jl files (#107)
Browse files Browse the repository at this point in the history
Co-authored-by: d-monnet <[email protected]>
  • Loading branch information
github-actions[bot] and d-monnet authored Nov 3, 2023
1 parent f10841d commit e639a63
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 65 deletions.
24 changes: 12 additions & 12 deletions src/performance_profiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ end
Returns `performance_profile_data` output (vectors) as matrices. Matrices are padded with NaN if necessary.
"""
function performance_profile_data_mat(T::Matrix{Float64};kwargs...)
x_data, y_data, max_ratio = performance_profile_data(T;kwargs...)
function performance_profile_data_mat(T::Matrix{Float64}; kwargs...)
x_data, y_data, max_ratio = performance_profile_data(T; kwargs...)
max_elem = maximum(length.(x_data))
for i in eachindex(x_data)
append!(x_data[i],[NaN for i=1:max_elem-length(x_data[i])])
append!(y_data[i],[NaN for i=1:max_elem-length(y_data[i])])
append!(x_data[i], [NaN for i = 1:(max_elem - length(x_data[i]))])
append!(y_data[i], [NaN for i = 1:(max_elem - length(y_data[i]))])
end
x_mat = hcat(x_data...)
y_mat = hcat(y_data...)
Expand Down Expand Up @@ -204,26 +204,26 @@ function export_performance_profile(
) where {S <: AbstractString}
nsolvers = size(T)[2]

x_mat, y_mat = performance_profile_data_mat(T;kwargs...)
x_mat, y_mat = performance_profile_data_mat(T; kwargs...)
isempty(solver_names) && (solver_names = ["solver_$i" for i = 1:nsolvers])

if !isempty(header)
header_l = size(T)[2]*2
header_l = size(T)[2] * 2
length(header) == header_l || error("Header should contain $(header_l) elements")
header = vcat([[sname*"_x",sname*"_y"] for sname in solver_names]...)
header = vcat([[sname * "_x", sname * "_y"] for sname in solver_names]...)
end
data = Matrix{Float64}(undef,size(x_mat,1),nsolvers*2)
for i =0:nsolvers-1
data[:,2*i+1] .= x_mat[:,i+1]
data[:,2*i+2] .= y_mat[:,i+1]
data = Matrix{Float64}(undef, size(x_mat, 1), nsolvers * 2)
for i = 0:(nsolvers - 1)
data[:, 2 * i + 1] .= x_mat[:, i + 1]
data[:, 2 * i + 2] .= y_mat[:, i + 1]
end

if !isempty(header)
header_l = size(T)[2] * 2
length(header) == header_l || error("Header should contain $(header_l) elements")
header = vcat([[sname * "_x", sname * "_y"] for sname in solver_names]...)
end
data = Matrix{Float64}(undef, size(x_mat,1), nsolvers * 2)
data = Matrix{Float64}(undef, size(x_mat, 1), nsolvers * 2)
for i = 0:(nsolvers - 1)
data[:, 2 * i + 1] .= x_mat[:, i + 1]
data[:, 2 * i + 2] .= y_mat[:, i + 1]
Expand Down
112 changes: 64 additions & 48 deletions src/tikz_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,60 +43,61 @@ function export_performance_profile_tikz(
T::Matrix{Float64},
filename::String;
file_type = TIKZ,
solvernames::Vector{String}=String[],
xlim::AbstractFloat=10.,
ylim::AbstractFloat=10.,
nxgrad::Int=5,
nygrad::Int=5,
grid::Bool=true,
solvernames::Vector{String} = String[],
xlim::AbstractFloat = 10.0,
ylim::AbstractFloat = 10.0,
nxgrad::Int = 5,
nygrad::Int = 5,
grid::Bool = true,
# markers::Vector{S} = String[],
colours::Vector{String} = String[],
linestyles::Vector{String} = String[],
linewidth::AbstractFloat = 1.0,
xlabel::String = "",
ylabel::String = "",
axis_tick_length::AbstractFloat = 0.2,
lgd_pos::Vector = [xlim+0.5,ylim],
lgd_pos::Vector = [xlim + 0.5, ylim],
lgd_plot_length::AbstractFloat = 0.7,
lgd_v_offset::AbstractFloat = 0.7,
lgd_plot_offset::AbstractFloat = 0.1,
lgd_box_length::AbstractFloat = 3.,
label_val::Vector = [0.2,0.25,0.5,1],
lgd_box_length::AbstractFloat = 3.0,
label_val::Vector = [0.2, 0.25, 0.5, 1],
logscale::Bool = true,
kwargs...)
kwargs...,
)
xlabel_def, ylabel_def, solvernames =
performance_profile_axis_labels(solvernames, size(T, 2), logscale; kwargs...)
isempty(xlabel) && (xlabel = xlabel_def)
isempty(ylabel) && (ylabel = ylabel_def)

xlabel_def, ylabel_def, solvernames = performance_profile_axis_labels(solvernames, size(T, 2), logscale; kwargs...)
isempty(xlabel) && (xlabel=xlabel_def)
isempty(ylabel) && (ylabel=ylabel_def)
y_grad = collect(0.0:(1.0 / (nygrad - 1)):1.0)

y_grad = collect(0.:1.0/(nygrad-1):1.0)
isempty(colours) && (colours = ["black" for _ = 1:size(T, 2)])
isempty(linestyles) && (linestyles = ["solid" for _ = 1:size(T, 2)])

isempty(colours) && (colours = ["black" for _ =1:size(T,2)])
isempty(linestyles) && (linestyles = ["solid" for _ =1:size(T,2)])

x_mat, y_mat = BenchmarkProfiles.performance_profile_data_mat(T;kwargs...)
x_mat, y_mat = BenchmarkProfiles.performance_profile_data_mat(T; kwargs...)

# get nice looking graduation on x axis
xmax , _ = findmax(x_mat[.!isnan.(x_mat)])
dist = xmax/(nxgrad-1)
n=log.(10,dist./label_val)
xmax, _ = findmax(x_mat[.!isnan.(x_mat)])
dist = xmax / (nxgrad - 1)
n = log.(10, dist ./ label_val)
_, ind = findmin(abs.(n .- round.(n)))
xgrad_dist = label_val[ind]*10^round(n[ind])
x_grad = [0. , [xgrad_dist*i for i =1 : nxgrad-1]...]
xmax=max(x_grad[end],xmax)
xgrad_dist = label_val[ind] * 10^round(n[ind])
x_grad = [0.0, [xgrad_dist * i for i = 1:(nxgrad - 1)]...]
xmax = max(x_grad[end], xmax)

# get nice looking graduation on y axis
dist = 1.0/(nygrad-1)
n=log.(10,dist./label_val)
dist = 1.0 / (nygrad - 1)
n = log.(10, dist ./ label_val)
_, ind = findmin(abs.(n .- round.(n)))
ygrad_dist = label_val[ind]*10^round(n[ind])
y_grad = [0. , [ygrad_dist*i for i =1 : nygrad-1]...]
ymax=max(y_grad[end],1.0)
ygrad_dist = label_val[ind] * 10^round(n[ind])
y_grad = [0.0, [ygrad_dist * i for i = 1:(nygrad - 1)]...]
ymax = max(y_grad[end], 1.0)

to_int(x) = isinteger(x) ? Int(x) : x

xratio = xlim/xmax
yratio = ylim/ymax
xratio = xlim / xmax
yratio = ylim / ymax
io = IOBuffer()

# axes
Expand All @@ -107,35 +108,47 @@ function export_performance_profile_tikz(
# axes graduations and labels,
if logscale
for i in eachindex(x_grad)
println(io, "\\draw[line width=$linewidth] ($(x_grad[i]*xratio),0) -- ($(x_grad[i]*xratio),$axis_tick_length) node [pos=0, below] {\$2^{$(to_int(x_grad[i]))}\$};")
println(
io,
"\\draw[line width=$linewidth] ($(x_grad[i]*xratio),0) -- ($(x_grad[i]*xratio),$axis_tick_length) node [pos=0, below] {\$2^{$(to_int(x_grad[i]))}\$};",
)
end
else
for i in eachindex(x_grad)
println(io, "\\draw[line width=$linewidth] ($(x_grad[i]*xratio),0) -- ($(x_grad[i]*xratio),$axis_tick_length) node [pos=0, below] {$(to_int(x_grad[i]))};")
println(
io,
"\\draw[line width=$linewidth] ($(x_grad[i]*xratio),0) -- ($(x_grad[i]*xratio),$axis_tick_length) node [pos=0, below] {$(to_int(x_grad[i]))};",
)
end
end
for i in eachindex(y_grad)
println(io, "\\draw[line width=$linewidth] (0,$(y_grad[i]*yratio)) -- ($axis_tick_length,$(y_grad[i]*yratio)) node [pos=0, left] {$(to_int(y_grad[i]))};")
println(
io,
"\\draw[line width=$linewidth] (0,$(y_grad[i]*yratio)) -- ($axis_tick_length,$(y_grad[i]*yratio)) node [pos=0, left] {$(to_int(y_grad[i]))};",
)
end
# grid
if grid
for i in eachindex(x_grad)
println(io, "\\draw[gray] ($(x_grad[i]*xratio),0) -- ($(x_grad[i]*xratio),$ylim);")
end
for i in eachindex(y_grad)
println(io, "\\draw[gray] (0,$(y_grad[i]*yratio)) -- ($xlim,$(y_grad[i]*yratio)) node [pos=0, left] {$(to_int(y_grad[i]))};")
println(
io,
"\\draw[gray] (0,$(y_grad[i]*yratio)) -- ($xlim,$(y_grad[i]*yratio)) node [pos=0, left] {$(to_int(y_grad[i]))};",
)
end
end

# profiles
for j in eachindex(solvernames)
for j in eachindex(solvernames)
drawcmd = "\\draw[line width=$linewidth, $(colours[j]), $(linestyles[j]), line width = $linewidth] "
drawcmd *= "($(x_mat[1,j]*xratio),$(y_mat[1,j]*yratio))"
for k in 2:size(x_mat,1)
if isnan(x_mat[k,j])
for k = 2:size(x_mat, 1)
if isnan(x_mat[k, j])
break
end
if y_mat[k,j] > 1 # for some reasons last point of profile is set with y=1.1 by data function...
if y_mat[k, j] > 1 # for some reasons last point of profile is set with y=1.1 by data function...
drawcmd *= " -- ($(xmax*xratio),$(y_mat[k-1,j]*yratio)) -- ($(xmax*xratio),$(y_mat[k-1,j]*yratio))"
else
# if !isempty(markers)
Expand All @@ -146,23 +159,26 @@ function export_performance_profile_tikz(
end
end
drawcmd *= ";"
println(io,drawcmd)
println(io, drawcmd)
end
# legend
for j in eachindex(solvernames)
for j in eachindex(solvernames)
legcmd = "\\draw[$(colours[j]), $(linestyles[j]), line width = $linewidth] "
legcmd *= "($(lgd_pos[1]+lgd_plot_offset),$(lgd_pos[2]-j*lgd_v_offset)) -- ($(lgd_pos[1]+lgd_plot_offset+lgd_plot_length),$(lgd_pos[2]-j*lgd_v_offset)) node [black,pos=1,right] {$(String(solvernames[j]))}"
# if !isempty(markers)
# legcmd *= " node [midway,draw,$(markers[j]),solid] {}"
# end
legcmd *= ";"

println(io,legcmd)
println(io, legcmd)
end
# legend box
println(io,"\\draw[line width=$linewidth] ($(lgd_pos[1]),$(lgd_pos[2])) -- ($(lgd_pos[1]+lgd_box_length),$(lgd_pos[2])) -- ($(lgd_pos[1]+lgd_box_length),$(lgd_pos[2]-lgd_v_offset*(length(solvernames)+1))) -- ($(lgd_pos[1]),$(lgd_pos[2]-lgd_v_offset*(length(solvernames)+1))) -- cycle;")

println(
io,
"\\draw[line width=$linewidth] ($(lgd_pos[1]),$(lgd_pos[2])) -- ($(lgd_pos[1]+lgd_box_length),$(lgd_pos[2])) -- ($(lgd_pos[1]+lgd_box_length),$(lgd_pos[2]-lgd_v_offset*(length(solvernames)+1))) -- ($(lgd_pos[1]),$(lgd_pos[2]-lgd_v_offset*(length(solvernames)+1))) -- cycle;",
)

raw_code = String(take!(io))
tp = TikzPicture(raw_code)
save(file_type(filename),tp)
end
save(file_type(filename), tp)
end
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ if !Sys.isfreebsd() # GR_jll not available, so Plots won't install
@test isfile(filename)
rm(filename)
end

@testset "tikz export" begin
T = 10 * rand(25, 3)
filename = "tikz_fig"
export_performance_profile_tikz(T,filename)
export_performance_profile_tikz(T, filename)
@test isfile(filename * ".tikz")
rm(filename * ".tikz")
export_performance_profile_tikz(T,filename,file_type = TEX)
export_performance_profile_tikz(T, filename, file_type = TEX)
@test isfile(filename * ".tex")
rm(filename * ".tex")
export_performance_profile_tikz(T,filename,file_type = SVG)
export_performance_profile_tikz(T, filename, file_type = SVG)
@test isfile(filename * ".svg")
rm(filename * ".svg")
export_performance_profile_tikz(T,filename,file_type = PDF)
export_performance_profile_tikz(T, filename, file_type = PDF)
@test isfile(filename * ".pdf")
rm(filename * ".pdf")
end
Expand Down

0 comments on commit e639a63

Please sign in to comment.