From c99ed6cecb3d83fbf6fafafd8d3036fd948d8264 Mon Sep 17 00:00:00 2001 From: fjebaker Date: Thu, 22 Feb 2024 14:21:11 +0000 Subject: [PATCH 1/3] ci: bump julia version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ee1eafe..e0fece8b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: ['1.9'] + julia-version: ['1.10'] os: [ubuntu-latest] steps: From acf69727a52f5a5aa810f9fe815d1a68a7cd509b Mon Sep 17 00:00:00 2001 From: fjebaker Date: Thu, 22 Feb 2024 14:21:49 +0000 Subject: [PATCH 2/3] fix: better type stability in frozen diff cache --- src/abstract-models.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstract-models.jl b/src/abstract-models.jl index 2e2fd1c6..4cd4a576 100644 --- a/src/abstract-models.jl +++ b/src/abstract-models.jl @@ -364,7 +364,7 @@ function make_diff_parameter_cache( # embed current parameter values inside of the dual cache # else all frozens will be zero - get_tmp(diffcache, ForwardDiff.Dual(1.0)) .= vals + get_tmp(diffcache, ForwardDiff.Dual(one(eltype(vals)))) .= vals ParameterCache(free_mask, diffcache) end From cf2918f0aabe6149bf014fa9961377852bc66832 Mon Sep 17 00:00:00 2001 From: fjebaker Date: Thu, 22 Feb 2024 14:22:38 +0000 Subject: [PATCH 3/3] fix: mitigate mul! problems by duplicating vector --- src/fitting/cache.jl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/fitting/cache.jl b/src/fitting/cache.jl index 1c4b6444..67bf7960 100644 --- a/src/fitting/cache.jl +++ b/src/fitting/cache.jl @@ -4,10 +4,11 @@ _invoke_and_transform!(cache::AbstractFittingCache, domain, params) = error("Not implemented for $(typeof(cache))") # one of these for each (mulit)model / data pair -struct SpectralCache{M,O,T,P,TransformerType} <: AbstractFittingCache +struct SpectralCache{M,O,T,K,P,TransformerType} <: AbstractFittingCache model::M model_output::O calculated_objective::T + output_cache::K parameter_cache::P transfomer!!::TransformerType function SpectralCache( @@ -19,15 +20,29 @@ struct SpectralCache{M,O,T,P,TransformerType} <: AbstractFittingCache param_diff_cache_size = nothing, ) where {M,XfmT} model_output = DiffCache(construct_objective_cache(layout, model, domain)) - calc_obj = similar(objective) - calc_obj .= 0 + # fix for https://github.com/fjebaker/SpectralFitting.jl/issues/79 + # output must be a vector but can only give matrix to `mul!`, so we need to + # unfortunately duplicate the array to ensure we have both types + calc_obj = zeros(eltype(objective), (length(objective), 1)) calc_obj_cache = DiffCache(calc_obj) + # vector chache + output = similar(objective) + output .= 0 + output_cache = DiffCache(output) param_cache = make_diff_parameter_cache(model; param_diff_cache_size = param_diff_cache_size) - new{M,typeof(model_output),typeof(calc_obj_cache),typeof(param_cache),XfmT}( + new{ + M, + typeof(model_output), + typeof(calc_obj_cache), + typeof(output_cache), + typeof(param_cache), + XfmT, + }( model, model_output, calc_obj_cache, + output_cache, param_cache, transformer, ) @@ -60,7 +75,9 @@ function _invoke_and_transform!(cache::SpectralCache, domain, params) output = invokemodel!(model_output, domain, cache.model, parameters) cache.transfomer!!(calc_obj, domain, output) - calc_obj + output_vector = get_tmp(cache.output_cache, params) + output_vector .= calc_obj + output_vector end struct FittingConfig{ImplType,CacheType,P,D,O}