Skip to content

Commit

Permalink
Merge pull request #259 from control-toolbox/auto-juliaformatter-pr
Browse files Browse the repository at this point in the history
[AUTO] JuliaFormatter.jl run
  • Loading branch information
ocots authored Aug 26, 2024
2 parents 26b89af + 7c72703 commit ddcf699
Show file tree
Hide file tree
Showing 45 changed files with 606 additions and 1,354 deletions.
10 changes: 0 additions & 10 deletions bench/Bench.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ using MLStyle
using MacroTools

function doBenchMarking(expr, f)

expr = MacroTools.striplines(expr)
println("Benchmarking $expr")
write(f, string(expr) * "\n")
Expand All @@ -12,11 +11,9 @@ function doBenchMarking(expr, f)
$expr
end))
write(f, "\n```\n\n")

end

function bench(file::String)

file_name = split(file, ".")[1]
println("Benching $file_name.jl\n")

Expand All @@ -39,7 +36,6 @@ function bench(file::String)
#dump(expr)

open(file_name_output, write = true, append = true) do f

if has_displayed
write(f, "```julia\n")
has_displayed = false
Expand All @@ -48,13 +44,11 @@ function bench(file::String)
if hasproperty(expr, :head) &&
expr.head == :macrocall &&
expr.args[1] == Symbol("@benchmark")

has_displayed = true
doBenchMarking(expr, f)
expr = :()

else

MLStyle.@match expr begin
:(display($benchname)) => begin
has_displayed = true
Expand All @@ -67,15 +61,11 @@ function bench(file::String)
write(f, string(expr) * "\n")
end
end

end

end

return expr

end

include(mapexpr, file)

end
37 changes: 15 additions & 22 deletions bench/bench_nlp_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,9 @@ function nlp_constraints_original(ocp::OptimalControlModel)
(ul, uind, uu),
(xl, xind, xu),
(vl, vind, vu)

end

function test_alloc_bad(ocp, N)

println(" getters and setters")
begin
function get_state(XU, i, n, m)
Expand All @@ -173,15 +171,15 @@ function test_alloc_bad(ocp, N)
end

function set_control_constraint!(C, i, ξ, nξ, nc)
C[(i-1)*nc+1:(i-1)*nc+] = ξ
C[((i - 1) * nc + 1):((i - 1) * nc + nξ)] = ξ
end

function set_state_constraint!(C, i, η, nη, nξ, nc)
C[(i-1)*nc++1:(i-1)*nc++] = η
C[((i - 1) * nc ++ 1):((i - 1) * nc ++ nη)] = η
end

function set_mixed_constraint!(C, i, ψ, nψ, nξ, nη, nc)
C[(i-1)*nc+++1:(i-1)*nc+++] = ψ
C[((i - 1) * nc +++ 1):((i - 1) * nc +++ nψ)] = ψ
end
end

Expand Down Expand Up @@ -226,7 +224,6 @@ function test_alloc_bad(ocp, N)
println(" end for loop")

nothing

end

# --------------------------------------------------------------------
Expand Down Expand Up @@ -408,41 +405,38 @@ function nlp_constraints_optimized(ocp::OptimalControlModel)
(uind, ul, uu),
(xind, xl, xu),
(vind, vl, vu)

end

function test_alloc_good(ocp, N)

begin

println(" getters and setters")
begin
function get_state(XU, i, n, m)
if n == 1
return XU[(i-1)*(n+m)+1]
return XU[(i - 1) * (n + m) + 1]
else
return @view XU[(i-1)*(n+m)+1:(i-1)*(n+m)+n]
return @view XU[((i - 1) * (n + m) + 1):((i - 1) * (n + m) + n)]
end
end

function get_control(XU, i, n, m)
if m == 1
return XU[(i-1)*(n+m)+n+1]
return XU[(i - 1) * (n + m) + n + 1]
else
return @view XU[(i-1)*(n+m)+n+1:(i-1)*(n+m)+n+m]
return @view XU[((i - 1) * (n + m) + n + 1):((i - 1) * (n + m) + n + m)]
end
end

function set_control_constraint!(C, i, valξ, nξ, nc)
C[(i-1)*nc+1:(i-1)*nc+] = valξ
C[((i - 1) * nc + 1):((i - 1) * nc + nξ)] = valξ
end

function set_state_constraint!(C, i, valη, nη, nξ, nc)
C[(i-1)*nc++1:(i-1)*nc++] = valη
C[((i - 1) * nc ++ 1):((i - 1) * nc ++ nη)] = valη
end

function set_mixed_constraint!(C, i, valψ, nψ, nξ, nη, nc)
C[(i-1)*nc+++1:(i-1)*nc+++] = valψ
C[((i - 1) * nc +++ 1):((i - 1) * nc +++ nψ)] = valψ
end
end

Expand Down Expand Up @@ -510,24 +504,23 @@ function test_alloc_good(ocp, N)
nothing
=#
t = times[i]
x[:] = XU[(i-1)*(n+m)+1:(i-1)*(n+m)+n]
u[:] = @view XU[(i-1)*(n+m)+n+1:(i-1)*(n+m)+n+m]
x[:] = XU[((i - 1) * (n + m) + 1):((i - 1) * (n + m) + n)]
u[:] = @view XU[((i - 1) * (n + m) + n + 1):((i - 1) * (n + m) + n + m)]
ξ!(valξ, t, u, v)
η!(valη, t, x, v)
ψ!(valψ, t, x, u, v)
#set_control_constraint!(C, i, valξ, nξ, nc)
C[(i-1)*nc+1:(i-1)*nc+] = valξ
C[((i - 1) * nc + 1):((i - 1) * nc + nξ)] = valξ
#set_state_constraint!(C, i, valη, nη, nξ, nc)
C[(i-1)*nc++1:(i-1)*nc++] = valη
C[((i - 1) * nc ++ 1):((i - 1) * nc ++ nη)] = valη
#set_mixed_constraint!(C, i, valψ, nψ, nξ, nη, nc)
C[(i-1)*nc+++1:(i-1)*nc+++] = valψ
C[((i - 1) * nc +++ 1):((i - 1) * nc +++ nψ)] = valψ
#end
end
println(" end for loop")

nothing
end

end

N = 10000
Expand Down
2 changes: 0 additions & 2 deletions bench/bench_scalar.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BenchmarkTools

function tt()

function bench_scalar(y)
x = 0
for i = 1:y
Expand Down Expand Up @@ -62,5 +61,4 @@ function tt()
end

@benchmark bench_scalar_6()

end
8 changes: 4 additions & 4 deletions bench/bench_usage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ F = Fun_dim_usage_each_call((t, x, u) -> x + u[1])
@benchmark F(t, x, u)

# fun with dimension usage handled by parameterization
struct Fun_dim_usage_parametrization{dim_x,dim_u}
struct Fun_dim_usage_parametrization{dim_x, dim_u}
f::Function
end

function (F::Fun_dim_usage_parametrization{1,1})(
function (F::Fun_dim_usage_parametrization{1, 1})(
t::Real,
x::Vector{<:Real},
u::Vector{<:Real},
Expand All @@ -51,11 +51,11 @@ end
# bench fun with dimension usage handled by parameterization

# x, u scalar
F = Fun_dim_usage_parametrization{1,1}((t, x, u) -> x + u)
F = Fun_dim_usage_parametrization{1, 1}((t, x, u) -> x + u)
@benchmark F(t, x, u)

# x scalar, u vector
F = Fun_dim_usage_parametrization{1,1}((t, x, u) -> x + u[1])
F = Fun_dim_usage_parametrization{1, 1}((t, x, u) -> x + u[1])
@benchmark F(t, x, u)

# direct call to the function
Expand Down
Loading

0 comments on commit ddcf699

Please sign in to comment.