Skip to content

[Feature]: Faster optimization of constants #199

@MilesCranmer

Description

@MilesCranmer

Feature Request

Right now, we are using a combination of get_constants to extract the constants from the tree, and set_constants! to put them back in. This is fast but it's not negligible.

What would be faster is to store the constant nodes in a vector of type Node{T}. Then, we can simply loop through the list and set the constants. This is because the node is not copied at any stage of the evaluation, so this sort of acts like pointers to the constant nodes.

We can do this once this merges: SymbolicML/DynamicExpressions.jl#27

constant_nodes = filter(t -> t.degree == 0 && t.constant, tree)
c0 = [t.val::T for t in constant_nodes]
# ...
for i in eachindex(c0)
    constant_nodes[i].val::T = c[i]
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions