Skip to content

Commit

Permalink
Merge pull request #32 from SymbolicML/fix-types-in-recursion
Browse files Browse the repository at this point in the history
Fix weird return value from `index_constants!`
  • Loading branch information
MilesCranmer committed May 9, 2023
2 parents 946dee5 + dd81086 commit a6fe9b1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/EquationUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,29 @@ end

function index_constants(tree::Node, left_index::Int)::NodeIndex
index_tree = NodeIndex()
index_constants(tree, index_tree, left_index)
index_constants!(tree, index_tree, left_index)
return index_tree
end

# Count how many constants to the left of this node, and put them in a tree
function index_constants(tree::Node, index_tree::NodeIndex, left_index::Int)
function index_constants!(tree::Node, index_tree::NodeIndex, left_index::Int)
if tree.degree == 0
if tree.constant
index_tree.constant_index = left_index + 1
end
elseif tree.degree == 1
index_tree.constant_index = count_constants(tree.l)
index_tree.l = NodeIndex()
index_constants(tree.l, index_tree.l, left_index)
index_constants!(tree.l, index_tree.l, left_index)
else
index_tree.l = NodeIndex()
index_tree.r = NodeIndex()
index_constants(tree.l, index_tree.l, left_index)
index_constants!(tree.l, index_tree.l, left_index)
index_tree.constant_index = count_constants(tree.l)
left_index_here = left_index + index_tree.constant_index
index_constants(tree.r, index_tree.r, left_index_here)
index_constants!(tree.r, index_tree.r, left_index_here)
end
return nothing
end

end

0 comments on commit a6fe9b1

Please sign in to comment.