Commit 5952eb6b authored by Rémi's avatar Rémi
Browse files

Read and write addergraphs

parent 127c2df8
name = "AdderGraphs"
uuid = "818587fb-0c22-4279-a2b9-8b16b5360b71"
version = "0.2.5"
version = "0.2.6"
......@@ -76,7 +76,7 @@ function read_addergraph(s::String)
end
node_inputs = Vector{Int}(abs.(node_inputs_signed))
node_subtraction = Vector{Bool}(abs.(div.(sign.(node_inputs_signed).-1, 2)))
push_node!(addergraph, AdderNode(node_value, [InputEdge(get_addernode_by_value(node_inputs[i]), node_input_shifts[i], node_subtraction[i]) for i in 1:length(node_subtraction)]))
push_node!(addergraph, AdderNode(node_value, [InputEdge(get_addernode_by_value(addergraph, node_inputs[i]), node_input_shifts[i], node_subtraction[i]) for i in 1:length(node_subtraction)]))
elseif startswith(val, "'O'")
push_output!(addergraph, parse(Int, split(val, ",")[2][2:(end-1)]))
end
......@@ -114,22 +114,13 @@ function write_addergraph(addergraph::AdderGraph)
end
end
end
if length(addergraph) != 0
adderstring *= ","
end
for addernodeind in length(addergraph):-1:1
addernode = get_nodes(addergraph)[addernodeind]
addernodes_index = get_previous_addernodes_index(addernode)
number_of_previous_nodes = length(addernodes_index)
adderstring *= "{'A',[$(get_value(addernode))],$(depth_by_value[get_value(addernode)])"
addernode_subtractions = get_subtractions(addernode)
for i in 1:number_of_previous_nodes
adderstring *= ",[$(addernode_subtractions[i] ? "-" : "")$(get_input_addernode_values(addernode)[i])],$(depth_by_value[get_input_addernode_values(addernode)[i]]),$(addernode.input_shifts[i])"
for addernode in get_nodes(addergraph)
adderstring *= ",{'A',[$(get_value(addernode))],$(depth_by_value[get_value(addernode)])"
for input_edge in get_input_edges(addernode)
adderstring *= ",[$((-1)^(is_negative_input(input_edge))*get_input_addernode_value(input_edge))],"
adderstring *= "$(depth_by_value[get_input_addernode_value(input_edge)]),$(get_input_shift(input_edge))"
end
adderstring *= "}"
if addernodeind != 1
adderstring *= ","
end
end
adderstring *= "}"
return adderstring
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment