Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

Update build function documentation

Open ArnoStrouwen opened this issue 2 years ago • 4 comments

https://symbolics.juliasymbolics.org/dev/manual/build_function/ seems to be written back when there was only scalar. How does build function now work for functions that contain vector/matrix operations? Sentences like "If ex is an array of > 1500 non-zero expressions then ShardedForm(80, 4) is used." are not applicable if the ex is not scalarized?

ArnoStrouwen avatar May 31 '22 11:05 ArnoStrouwen

I'm not sure what build_function does on symbolic arrays right now, @shashi is it complete enough to start documenting there?

ChrisRackauckas avatar May 31 '22 12:05 ChrisRackauckas

julia> using Symbolics

julia> @variables a[1:2]
1-element Vector{Symbolics.Arr{Num, 1}}:
 a[1:2]

julia> b = 1/2*a.^2
(broadcast(*, 0.5, broadcast(literal_pow, Base.RefValue{typeof(^)}(^), a, Base.RefValue{Val{2}}(Val{2}()))))[1:2]

julia> Symbolics.build_function(b,a)
:(function (a,)
      #= C:\Users\arno\.julia\packages\SymbolicUtils\v2ZkM\src\code.jl:349 =#
      #= C:\Users\arno\.julia\packages\SymbolicUtils\v2ZkM\src\code.jl:350 =#
      #= C:\Users\arno\.julia\packages\SymbolicUtils\v2ZkM\src\code.jl:351 =#
      (broadcast)(*, 0.5, (broadcast)(Base.literal_pow, Base.RefValue{typeof(^)}(^), a, Base.RefValue{Val{2}}(Val{2}())))
  end)

julia> eval(Symbolics.build_function(b,a))([1,2,3])
3-element Vector{Float64}:
 0.5
 2.0
 4.5

ArnoStrouwen avatar May 31 '22 13:05 ArnoStrouwen

what is the status of this issue? I am currently dealing with the ambiguity of the return value of build_function as described above (vs what is described in the documentation: https://symbolics.juliasymbolics.org/stable/tutorials/symbolic_functions/)

aarontrowbridge avatar Jun 16 '22 18:06 aarontrowbridge

Yes it won't switch to ShardedForm if it's not scalarized.

shashi avatar Jul 25 '22 19:07 shashi