Skip to content

Commit d0fee2c

Browse files
committed
ParTable ctor: allow providing columns data
1 parent b5a291e commit d0fee2c

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/frontend/specification/ParameterTable.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@ end
1313
### Constructors
1414
############################################################################################
1515

16-
# constuct an empty table
17-
function ParameterTable(;
16+
# construct a dictionary with the default partable columns
17+
# optionally pre-allocate data for nrows
18+
empty_partable_columns(nrows::Integer = 0) = Dict{Symbol, Vector}(
19+
:from => fill(Symbol(), nrows),
20+
:parameter_type => fill(Symbol(), nrows),
21+
:to => fill(Symbol(), nrows),
22+
:free => fill(true, nrows),
23+
:value_fixed => fill(NaN, nrows),
24+
:start => fill(NaN, nrows),
25+
:estimate => fill(NaN, nrows),
26+
:param => fill(Symbol(), nrows),
27+
)
28+
29+
# construct using the provided columns data or create and empty table
30+
function ParameterTable(
31+
columns::Dict{Symbol, Vector} = empty_partable_columns();
1832
observed_vars::Union{AbstractVector{Symbol}, Nothing} = nothing,
1933
latent_vars::Union{AbstractVector{Symbol}, Nothing} = nothing,
2034
)
21-
columns = Dict{Symbol, Any}(
22-
:from => Vector{Symbol}(),
23-
:parameter_type => Vector{Symbol}(),
24-
:to => Vector{Symbol}(),
25-
:free => Vector{Bool}(),
26-
:value_fixed => Vector{Float64}(),
27-
:start => Vector{Float64}(),
28-
:estimate => Vector{Float64}(),
29-
:param => Vector{Symbol}(),
30-
:start => Vector{Float64}(),
31-
)
32-
3335
return ParameterTable(columns,
3436
!isnothing(observed_vars) ? copy(observed_vars) : Vector{Symbol}(),
3537
!isnothing(latent_vars) ? copy(latent_vars) : Vector{Symbol}(),

src/frontend/specification/StenoGraphs.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ function ParameterTable(
4040
graph = unique(graph)
4141
n = length(graph)
4242

43-
partable = ParameterTable(latent_vars = latent_vars, observed_vars = observed_vars)
44-
from = resize!(partable.columns[:from], n)
45-
parameter_type = resize!(partable.columns[:parameter_type], n)
46-
to = resize!(partable.columns[:to], n)
47-
free = fill!(resize!(partable.columns[:free], n), true)
48-
value_fixed = fill!(resize!(partable.columns[:value_fixed], n), NaN)
49-
start = fill!(resize!(partable.columns[:start], n), NaN)
50-
params = fill!(resize!(partable.columns[:param], n), Symbol(""))
43+
columns = empty_partable_columns(n)
44+
from = columns[:from]
45+
parameter_type = columns[:parameter_type]
46+
to = columns[:to]
47+
free = columns[:free]
48+
value_fixed = columns[:value_fixed]
49+
start = columns[:start]
50+
params = columns[:param]
5151
# group = Vector{Symbol}(undef, n)
5252

5353
for (i, element) in enumerate(graph)
@@ -103,7 +103,7 @@ function ParameterTable(
103103
end
104104
end
105105

106-
return partable
106+
return ParameterTable(columns; latent_vars, observed_vars)
107107
end
108108

109109
############################################################################################

0 commit comments

Comments
 (0)