From 28498040d159e91f0948a9c2fe94a93153843540 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Mon, 24 Nov 2025 17:14:38 +0100 Subject: [PATCH] make Gradient/Jacobian/Hessian-Config mutable these often get quite large and the fact that they are non-mutable means Julia copies them which is quite expensive --- src/config.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/config.jl b/src/config.jl index 3c6c97e3..3514c6ce 100644 --- a/src/config.jl +++ b/src/config.jl @@ -94,9 +94,9 @@ Base.eltype(::Type{DerivativeConfig{T,D}}) where {T,D} = eltype(D) # GradientConfig # ################## -struct GradientConfig{T,V,N,D} <: AbstractConfig{N} - seeds::NTuple{N,Partials{N,V}} - duals::D +mutable struct GradientConfig{T,V,N,D} <: AbstractConfig{N} + const seeds::NTuple{N,Partials{N,V}} + const duals::D end """ @@ -130,9 +130,9 @@ Base.eltype(::Type{GradientConfig{T,V,N,D}}) where {T,V,N,D} = Dual{T,V,N} # JacobianConfig # ################## -struct JacobianConfig{T,V,N,D} <: AbstractConfig{N} - seeds::NTuple{N,Partials{N,V}} - duals::D +mutable struct JacobianConfig{T,V,N,D} <: AbstractConfig{N} + const seeds::NTuple{N,Partials{N,V}} + const duals::D end """ @@ -195,9 +195,9 @@ Base.eltype(::Type{JacobianConfig{T,V,N,D}}) where {T,V,N,D} = Dual{T,V,N} # HessianConfig # ################# -struct HessianConfig{T,V,N,DG,DJ} <: AbstractConfig{N} - jacobian_config::JacobianConfig{T,V,N,DJ} - gradient_config::GradientConfig{T,Dual{T,V,N},N,DG} +mutable struct HessianConfig{T,V,N,DG,DJ} <: AbstractConfig{N} + const jacobian_config::JacobianConfig{T,V,N,DJ} + const gradient_config::GradientConfig{T,Dual{T,V,N},N,DG} end """