Skip to content

Commit 97429e4

Browse files
committed
ParTable: getindex() returns NamedTuple
so the downstream code doesn't rely on the order of tuple elements
1 parent ec9fa98 commit 97429e4

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

src/frontend/specification/ParameterTable.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ ParameterTableRow = @NamedTuple begin
126126
end
127127

128128
Base.getindex(partable::ParameterTable, i::Integer) = (
129-
partable.columns[:from][i],
130-
partable.columns[:parameter_type][i],
131-
partable.columns[:to][i],
132-
partable.columns[:free][i],
133-
partable.columns[:value_fixed][i],
134-
partable.columns[:param][i],
129+
from = partable.columns[:from][i],
130+
parameter_type = partable.columns[:parameter_type][i],
131+
to = partable.columns[:to][i],
132+
free = partable.columns[:free][i],
133+
value_fixed = partable.columns[:value_fixed][i],
134+
param = partable.columns[:param][i],
135135
)
136136

137137
Base.length(partable::ParameterTable) = length(partable.columns[:param])

src/frontend/specification/RAMMatrices.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,41 +172,39 @@ function RAMMatrices(
172172
# handle constants
173173
constants = Vector{RAMConstant}()
174174

175-
for i in 1:length(partable)
176-
from, parameter_type, to, free, value_fixed, param = partable[i]
177-
178-
row_ind = positions[to]
179-
col_ind = from != Symbol("1") ? positions[from] : nothing
180-
181-
if !free
182-
if (parameter_type == :) && (from == Symbol("1"))
183-
push!(constants, RAMConstant(:M, row_ind, value_fixed))
184-
elseif (parameter_type == :)
175+
for r in partable
176+
row_ind = positions[r.to]
177+
col_ind = r.from != Symbol("1") ? positions[r.from] : nothing
178+
179+
if !r.free
180+
if (r.parameter_type == :) && (r.from == Symbol("1"))
181+
push!(constants, RAMConstant(:M, row_ind, r.value_fixed))
182+
elseif r.parameter_type == :
185183
push!(
186184
constants,
187-
RAMConstant(:A, CartesianIndex(row_ind, col_ind), value_fixed),
185+
RAMConstant(:A, CartesianIndex(row_ind, col_ind), r.value_fixed),
188186
)
189-
elseif (parameter_type == :)
187+
elseif r.parameter_type == :
190188
push!(
191189
constants,
192-
RAMConstant(:S, CartesianIndex(row_ind, col_ind), value_fixed),
190+
RAMConstant(:S, CartesianIndex(row_ind, col_ind), r.value_fixed),
193191
)
194192
else
195-
error("Unsupported parameter type: $(parameter_type)")
193+
error("Unsupported parameter type: $(r.parameter_type)")
196194
end
197195
else
198-
par_ind = params_index[param]
199-
if (parameter_type == :) && (from == Symbol("1"))
196+
par_ind = params_index[r.param]
197+
if (r.parameter_type == :) && (r.from == Symbol("1"))
200198
push!(M_ind[par_ind], row_ind)
201-
elseif parameter_type == :
199+
elseif r.parameter_type == :
202200
push!(A_ind[par_ind], row_ind + (col_ind - 1) * n_node)
203-
elseif parameter_type == :
201+
elseif r.parameter_type == :
204202
push!(S_ind[par_ind], row_ind + (col_ind - 1) * n_node)
205203
if row_ind != col_ind
206204
push!(S_ind[par_ind], col_ind + (row_ind - 1) * n_node)
207205
end
208206
else
209-
error("Unsupported parameter type: $(parameter_type)")
207+
error("Unsupported parameter type: $(r.parameter_type)")
210208
end
211209
end
212210
end

0 commit comments

Comments
 (0)