Skip to content

Conversation

@hfytr
Copy link
Collaborator

@hfytr hfytr commented Feb 5, 2026

This PR changes expressions to no longer re-evaluate on every reference, and instead pre-computes once for every call to jac_coord / hess_coord / etc.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic main) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/nlp.jl b/src/nlp.jl
index 8647755..4d4d618 100644
--- a/src/nlp.jl
+++ b/src/nlp.jl
@@ -18,10 +18,10 @@ end
 Base.show(io::IO, v::Variable) = print(
     io,
     """
-    Variable
+        Variable
 
-      x ∈ R^{$(join(size(v.size), " × "))}
-    """,
+          x ∈ R^{$(join(size(v.size), " × "))}
+        """,
 )
 
 struct Parameter{S, O} <: AbstractParameter
@@ -32,9 +32,9 @@ end
 Base.show(io::IO, v::Parameter) = print(
     io,
     """
-    Parameter
+        Parameter
 
-      θ ∈ R^{$(join(size(v.size), " × "))}
+          θ ∈ R^{$(join(size(v.size), " × "))}
     """,
 )
 struct Objective{R, F, I} <: AbstractObjective
@@ -45,11 +45,11 @@ end
 Base.show(io::IO, v::Objective) = print(
     io,
     """
-    Objective
+        Objective
 
-      min (...) + ∑_{p ∈ P} f(x,θ,p)
+          min (...) + ∑_{p ∈ P} f(x,θ,p)
 
-      where |P| = $(length(v.itr))
+          where |P| = $(length(v.itr))
     """,
 )
 
@@ -64,13 +64,13 @@ end
 Base.show(io::IO, v::Expression) = print(
     io,
     """
-    Expression
+        Expression
 
-      s.t. (...)
-           g♭ ≤ [g(x,θ,p)]_{p ∈ P} ≤ g♯
+          s.t. (...)
+               g♭ ≤ [g(x,θ,p)]_{p ∈ P} ≤ g♯
 
-      where |P| = $(length(v.itr))
-    """,
+          where |P| = $(length(v.itr))
+        """,
 )
 
 
@@ -83,13 +83,13 @@ end
 Base.show(io::IO, v::Constraint) = print(
     io,
     """
-    Constraint
+        Constraint
 
-      s.t. (...)
-           g♭ ≤ [g(x,θ,p)]_{p ∈ P} ≤ g♯
+          s.t. (...)
+               g♭ ≤ [g(x,θ,p)]_{p ∈ P} ≤ g♯
 
-      where |P| = $(length(v.itr))
-    """,
+          where |P| = $(length(v.itr))
+        """,
 )
 
 struct ExpressionAug{R, F, I} <: AbstractConstraint
@@ -109,13 +109,13 @@ end
 Base.show(io::IO, v::ConstraintAug) = print(
     io,
     """
-    Constraint Augmentation
+        Constraint Augmentation
 
-      s.t. (...)
-           g♭ ≤ (...) + ∑_{p ∈ P} h(x,θ,p) ≤ g♯
+          s.t. (...)
+               g♭ ≤ (...) + ∑_{p ∈ P} h(x,θ,p) ≤ g♯
 
-      where |P| = $(length(v.itr))
-    """,
+          where |P| = $(length(v.itr))
+        """,
 )
 
 """
@@ -228,15 +228,15 @@ depth(a::ExpressionNull) = 0
 Base.show(io::IO, c::ExaCore{T, VT, B}) where {T, VT, B} = print(
     io,
     """
-    An ExaCore
+        An ExaCore
 
-      Float type: ...................... $T
-      Array type: ...................... $VT
-      Backend: ......................... $B
+          Float type: ...................... $T
+          Array type: ...................... $VT
+          Backend: ......................... $B
 
-      number of objective patterns: .... $(depth(c.obj))
-      number of constraint patterns: ... $(depth(c.con))
-    """,
+          number of objective patterns: .... $(depth(c.obj))
+          number of constraint patterns: ... $(depth(c.con))
+        """,
 )
 
 struct ExaModel{T, VT, VI, E, O, C, EX, VII} <: NLPModels.AbstractNLPModel{T, VT}
@@ -797,16 +797,16 @@ Expression
 function subexpr(
         c::C,
         gen::I,
-    ) where {T, C <: ExaCore{T}, I<:Base.Iterators.Flatten}
-    ns=[]
+    ) where {T, C <: ExaCore{T}, I <: Base.Iterators.Flatten}
+    ns = []
     it = gen.it
     while typeof(it) <: Union{Base.Generator, Base.Iterators.Flatten}
         push!(ns, length(it))
         (it, _) = Base.iterate(it)
     end
-    subexpr(c, (nsi for nsi in ns), gen)
+    return subexpr(c, (nsi for nsi in ns), gen)
 end
-subexpr(c::C, gen::G) where {T, C <: ExaCore{T}, G<:Base.Generator} = subexpr(c, (length(gen.iter),), gen)
+subexpr(c::C, gen::G) where {T, C <: ExaCore{T}, G <: Base.Generator} = subexpr(c, (length(gen.iter),), gen)
 
 function subexpr(
         c::C,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant