From ab566c53f4647b4449faeab6f84088bae4037248 Mon Sep 17 00:00:00 2001 From: sshin23 Date: Fri, 19 Sep 2025 00:51:49 +0000 Subject: [PATCH] Format .jl files --- docs/src/guide.jl | 6 ++++-- ext/ExaModelsMOI.jl | 14 +++++++------- src/graph.jl | 13 ++++++++----- src/simdfunction.jl | 2 +- test/NLPTest/luksan_struct.jl | 13 +++++++++---- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/docs/src/guide.jl b/docs/src/guide.jl index cf513f2..8d5b8a6 100644 --- a/docs/src/guide.jl +++ b/docs/src/guide.jl @@ -60,7 +60,8 @@ constraint( c, 3x[i+1]^3 + 2 * x[i+2] - 5 + sin(x[i+1] - x[i+2])sin(x[i+1] + x[i+2]) + 4x[i+1] - x[i]exp(x[i] - x[i+1]) - 3 for i = 1:(N-2); - lcon = -1.0, ucon = 1.0 + lcon = -1.0, + ucon = 1.0, ) # If you want to create a single-bounded constraint, you can set `lcon` to `-Inf` or `ucon` to `Inf`. For example, if we wanted to set the lower bound of the constraint to -1 and the upper bound to infinity, we could do it as follows: @@ -68,7 +69,8 @@ constraint( c, 3x[i+1]^3 + 2 * x[i+2] - 5 + sin(x[i+1] - x[i+2])sin(x[i+1] + x[i+2]) + 4x[i+1] - x[i]exp(x[i] - x[i+1]) - 3 for i = 1:(N-2); - lcon = -1.0, ucon = Inf + lcon = -1.0, + ucon = Inf, ) # ## ExaModel diff --git a/ext/ExaModelsMOI.jl b/ext/ExaModelsMOI.jl index 174b8f4..9318af2 100644 --- a/ext/ExaModelsMOI.jl +++ b/ext/ExaModelsMOI.jl @@ -314,9 +314,7 @@ function exafy_con( func = MOI.get(moim, MOI.ConstraintFunction(), ci) set = MOI.get(moim, MOI.ConstraintSet(), ci) con_to_idx[ci] = offset + i - start = if MOI.supports( - moim, MOI.ConstraintPrimalStart(), typeof(ci) - ) + start = if MOI.supports(moim, MOI.ConstraintPrimalStart(), typeof(ci)) MOI.get(moim, MOI.ConstraintPrimalStart(), ci) else nothing @@ -457,10 +455,12 @@ function _exafy(i::R, var_to_idx, p) where {R<:Real} end function _exafy(e::MOI.ScalarNonlinearFunction, var_to_idx, p = ()) - return op(e.head)((begin - c, p = _exafy(e, var_to_idx, p) - c - end for e in e.args)...), p + return op(e.head)(( + begin + c, p = _exafy(e, var_to_idx, p) + c + end for e in e.args + )...), p end function _exafy(e::MOI.ScalarAffineFunction{T}, var_to_idx, p = ()) where {T} diff --git a/src/graph.jl b/src/graph.jl index ee4fa1c..3f53857 100644 --- a/src/graph.jl +++ b/src/graph.jl @@ -115,11 +115,13 @@ end @inline Base.getproperty(n::ParSource, s::Symbol) = ParIndexed(n, s) @inline Base.getindex(n::ParSource, i) = ParIndexed(n, i) -@inline Base.indexed_iterate(n::P, idx, start = 1) where P <: Union{ParSource, ParIndexed} = (ParIndexed(n, idx), idx + 1) +@inline Base.indexed_iterate(n::P, idx, start = 1) where {P<:Union{ParSource,ParIndexed}} = + (ParIndexed(n, idx), idx + 1) -@inline Base.getproperty(v::ParIndexed{I, n}, s::Symbol) where {I, n} = ParIndexed(v, s) -@inline Base.getindex(v::ParIndexed{I, n}, i) where {I, n} = ParIndexed(v, i) -@inline Base.indexed_iterate(v::ParIndexed{I, n}, idx, start = 1) where {I, n} = (ParIndexed(v, idx), idx + 1) +@inline Base.getproperty(v::ParIndexed{I,n}, s::Symbol) where {I,n} = ParIndexed(v, s) +@inline Base.getindex(v::ParIndexed{I,n}, i) where {I,n} = ParIndexed(v, i) +@inline Base.indexed_iterate(v::ParIndexed{I,n}, idx, start = 1) where {I,n} = + (ParIndexed(v, idx), idx + 1) @inline Base.getindex(n::VarSource, i) = Var(i) @@ -144,7 +146,8 @@ struct Identity end @inline (v::ParameterNode{I})(::Identity, x, ::Nothing) where {I<:AbstractNode} = NaN @inline (v::ParSource)(i, x, θ) = i -@inline (v::ParIndexed{I,n})(i, x, θ) where {I,n} = @inbounds getfield(getfield(v, :inner)(i, x, θ), n) +@inline (v::ParIndexed{I,n})(i, x, θ) where {I,n} = + @inbounds getfield(getfield(v, :inner)(i, x, θ), n) (v::ParIndexed)(i::Identity, x, θ) = NaN # despecialized (v::ParSource)(i::Identity, x, θ) = NaN # despecialized diff --git a/src/simdfunction.jl b/src/simdfunction.jl index 00f48d5..6fd382e 100644 --- a/src/simdfunction.jl +++ b/src/simdfunction.jl @@ -25,7 +25,7 @@ struct SIMDFunction{F,C1,C2} end @inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F,C1,C2} = sf.f(i, x, θ) -@inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F <: Real,C1,C2} = sf.f +@inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F<:Real,C1,C2} = sf.f """ SIMDFunction(gen::Base.Generator, o0 = 0, o1 = 0, o2 = 0) diff --git a/test/NLPTest/luksan_struct.jl b/test/NLPTest/luksan_struct.jl index f69942b..856023d 100644 --- a/test/NLPTest/luksan_struct.jl +++ b/test/NLPTest/luksan_struct.jl @@ -1,5 +1,5 @@ struct I2 - i::Tuple{Int, Int} + i::Tuple{Int,Int} end struct I1 @@ -9,10 +9,15 @@ end function _exa_luksan_struct_model(backend, N; M = 1) c = ExaCore(backend = backend) - data = [I1(I2((i,j))) for i = 1:N, j = 1:M] + data = [I1(I2((i, j))) for i = 1:N, j = 1:M] x = variable(c, N, M; start = [luksan_vlcek_x0(i.i.i[1]) for i in data]) - s = constraint(c, luksan_vlcek_con1(x, i.i.i[1], i.i.i[2]) for i in data[1:end-2,:]) - constraint!(c, s, (i.i.i[1], i.i.i[2]) => luksan_vlcek_con2(x, i.i.i[1], i.i.i[2]) for i in data[1:end-2,:]) + s = constraint(c, luksan_vlcek_con1(x, i.i.i[1], i.i.i[2]) for i in data[1:(end-2), :]) + constraint!( + c, + s, + (i.i.i[1], i.i.i[2]) => luksan_vlcek_con2(x, i.i.i[1], i.i.i[2]) for + i in data[1:(end-2), :] + ) objective(c, luksan_vlcek_obj(x, i, j) for i = 2:N, j = 1:M) return ExaModel(c; prod = true), (x,), (s,)