Add accurate arithmetic for summation, fix order of input particles

This commit is contained in:
Anton Reinhard
2023-09-07 15:15:21 +02:00
parent 0f78053ccf
commit d1666de432
14 changed files with 183 additions and 66 deletions

View File

@@ -5,12 +5,12 @@ function gen_code(graph::DAG)
sizehint!(code, length(graph.nodes))
nodeQueue = PriorityQueue{Node, Int}()
inputSyms = Vector{Symbol}()
inputSyms = Dict{String, Symbol}()
# use a priority equal to the number of unseen children -> 0 are nodes that can be added
for node in get_entry_nodes(graph)
enqueue!(nodeQueue, node => 0)
push!(inputSyms, Symbol("data_$(to_var_name(node.id))_in"))
push!(inputSyms, node.name => Symbol("data_$(to_var_name(node.id))_in"))
end
node = nothing
@@ -39,16 +39,26 @@ function gen_code(graph::DAG)
)
end
function execute(generated_code, input::Vector{Particle})
function execute(generated_code, input::Dict{ParticleType, Vector{Particle}})
(code, inputSymbols, outputSymbol) = generated_code
@assert length(input) == length(inputSymbols)
assignInputs = Vector{Expr}()
for i in 1:length(input)
for (name, symbol) in inputSymbols
type = nothing
if startswith("A", name)
type = A
elseif startswith("B", name)
type = B
else
type = C
end
index = parse(Int, name[2:end])
push!(
assignInputs,
Meta.parse(
"$(inputSymbols[i]) = ParticleValue(Particle($(input[i]).P0, $(input[i]).P1, $(input[i]).P2, $(input[i]).P3, $(input[i]).m), 1.0)",
"$(symbol) = ParticleValue(Particle($(input[type][index]).P0, $(input[type][index]).P1, $(input[type][index]).P2, $(input[type][index]).P3, $(type)), 1.0)",
),
)
end
@@ -61,17 +71,25 @@ function execute(generated_code, input::Vector{Particle})
return result
end
function execute(graph::DAG, input::Vector{Particle})
function execute(graph::DAG, input::Dict{ParticleType, Vector{Particle}})
(code, inputSymbols, outputSymbol) = gen_code(graph)
@assert length(input) == length(inputSymbols)
assignInputs = Vector{Expr}()
for i in 1:length(input)
for (name, symbol) in inputSymbols
type = nothing
if startswith(name, "A")
type = A
elseif startswith(name, "B")
type = B
else
type = C
end
index = parse(Int, name[2:end])
push!(
assignInputs,
Meta.parse(
"$(inputSymbols[i]) = ParticleValue(Particle($(input[i]).P0, $(input[i]).P1, $(input[i]).P2, $(input[i]).P3, $(input[i]).m), 1.0)",
"$(symbol) = ParticleValue(Particle($(input[type][index]).P0, $(input[type][index]).P1, $(input[type][index]).P2, $(input[type][index]).P3, $(type)), 1.0)",
),
)
end