SymbolicML / DynamicExpressions.jl

Ridiculously fast symbolic expressions
https://ai.damtp.cam.ac.uk/dynamicexpressions
Apache License 2.0
106 stars 15 forks source link

Use StaticArray for children #86

Open MilesCranmer opened 4 months ago

MilesCranmer commented 4 months ago

I think the generalization to more than 2 children would be best attempted with StaticArrays.MArray. So you could have a field

struct Node{T,N}
    degree::UInt8
    ...
    _children::MVector{Node{T,N},N}
end

The beauty of this is you could still have undefined values (https://discourse.julialang.org/t/how-to-initialize-an-empty-staticarray/69942/11?u=milescranmer) and the max number of children would still be a compile time constant.

And calling children(node) could return a Vector according to the degree of the node. (Though we would still want to have special methods for each degree).

Similarly, for OperatorEnum, it could be a tuple of tuples up to the maximum arity.

@gca30 interested to hear your thoughts