Skip to content

Commit 0e815a8

Browse files
committed
update_partable!() cleanup + docstring
1 parent d0fee2c commit 0e815a8

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

src/frontend/specification/ParameterTable.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,35 @@ end
201201

202202
# update generic ---------------------------------------------------------------------------
203203

204+
"""
205+
update_partable!(partable::AbstractParameterTable, params::Vector{Symbol}, values, column)
206+
207+
Write parameter `values` into `column` of `partable`.
208+
209+
The `params` and `values` vectors define the pairs of value
210+
parameters, which are being matched to the `:param` column
211+
of the `partable`.
212+
"""
204213
function update_partable!(
205214
partable::ParameterTable,
206215
params::AbstractVector{Symbol},
207216
values::AbstractVector,
208-
column,
217+
column::Symbol,
209218
)
210-
new_col = Vector{eltype(vec)}(undef, length(partable))
211-
params_index = Dict(param => i for (i, param) in enumerate(params))
219+
length(params) == length(values) || throw(
220+
ArgumentError(
221+
"The length of `params` ($(length(params))) and their `values` ($(length(values))) must be the same",
222+
),
223+
)
224+
coldata = get!(() -> Vector{eltype(values)}(), partable.columns, column)
225+
resize!(coldata, length(partable))
226+
params_index = Dict(zip(params, eachindex(params)))
212227
for (i, param) in enumerate(partable.columns[:param])
213-
if !(param == :const)
214-
new_col[i] = values[params_index[param]]
215-
elseif param == :const
216-
new_col[i] = zero(eltype(values))
217-
end
228+
coldata[i] = param != :const ? values[params_index[param]] : zero(eltype(values))
218229
end
219-
push!(partable.columns, column => new_col)
220230
return partable
221231
end
222232

223-
"""
224-
update_partable!(partable::AbstractParameterTable, sem_fit::SemFit, vec, column)
225-
226-
Write `vec` to `column` of `partable`.
227-
228-
# Arguments
229-
- `vec::Vector`: has to be in the same order as the `model` parameters
230-
"""
231-
update_partable!(partable::AbstractParameterTable, sem_fit::SemFit, values, column) =
232-
update_partable!(partable, params(sem_fit), values, column)
233-
234233
# update estimates -------------------------------------------------------------------------
235234
"""
236235
update_estimate!(

0 commit comments

Comments
 (0)