SymbolicML / DynamicExpressions.jl

Ridiculously fast symbolic expressions
https://symbolicml.org/DynamicExpressions.jl/dev
Apache License 2.0
92 stars 12 forks source link

what's special about variable name `operators`? #21

Closed Moelf closed 1 year ago

Moelf commented 1 year ago

in all the examples we define a variable operators but don't use it explicitly, can we document it or make an explicit API?

MilesCranmer commented 1 year ago

Good point, it does seem a bit hacky. It's actually calling eval_tree_array(tree, X, operators). But when you define an OperatorEnum with define_helper_functions=true (default), it creates a definition for (tree::Node)(X::AbstractArray{T}) based on the OperatorEnum.

However it's probably unsafe to emphasize this API. A better one would just be:

(tree::Node)(X::AbstractArray{T}, operators::OperatorEnum)

which means you would never have an instance of using the wrong operators with a given tree (since the tree is just an enum - if you update the operators, it will change the definition of the tree!).

MilesCranmer commented 1 year ago

(The variable name operators does not matter, by the way - calling OperatorEnum() is what sets up the default behavior of the evaluation methods, if you're using this convenience API)

MilesCranmer commented 1 year ago

This is the code in question: https://github.com/SymbolicML/DynamicExpressions.jl/blob/7835abfbeefd93fe18ae53befe63b1470de99ade/src/OperatorEnumConstruction.jl#L9-L31