File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -351,10 +351,32 @@ end
351351 println (" Simplified: " , simplified_expr)
352352
353353 #=
354- These examples demonstrate some of the key features of `Expression` objects.
355- They provide a powerful way to represent, evaluate, and manipulate
356- mathematical expressions in DynamicExpressions.
354+ `AbstractExpression` types also have many operators in `Base` defined, which
355+ will automatically look up the matching index in the stored [`OperatorEnum`](@ref).
356+ This means we can combine expressions like so:
357357 =#
358+ xs = [Expression (Node {Float64} (; feature= i); operators, variable_names) for i in 1 : 5 ]
359+
360+ xs[1 ] + xs[2 ]
361+ #=
362+ This gives us an easy way to quickly construct expressions with minimal memory overhead,
363+ and fast evaluation speed:
364+ =#
365+ ex = xs[1 ] * 2.1 - exp (3 * xs[2 ])
366+
367+ # Evaluation:
368+ X = randn (rng, 5 , 2 )
369+ ex (X)
370+
371+ # Or, if we have loaded Zygote, we can differentiate with respect
372+ # to the variables:
373+ using Zygote
374+ ex' (X)
375+
376+ # Or the constants of the expression:
377+ ex' (X; variable= Val (false ))
378+
379+ # Which can be used for optimization.
358380
359381 # literate_end
360382end
You can’t perform that action at this time.
0 commit comments