Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[donotmerge] investigate alternative fix to 2993aa6 #999

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/build_targets.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
using Symbolics, Test
using ReferenceTests

using SymbolicUtils

@eval SymbolicUtils function Base.hash(s::BasicSymbolic, salt::UInt)::UInt
E = exprtype(s)
if E === SYM
h = hash(nameof(s))
s = salt ⊻ SYM_SALT
Base.hash_uint(3s - h)
elseif E === ADD || E === MUL
!iszero(salt) && return hash(hash(s, zero(UInt)), salt)
h = s.hash[]
!iszero(h) && return h
hashoffset = isadd(s) ? ADD_SALT : SUB_SALT
h′ = hash(hashoffset, hash(s.coeff, hash(s.dict, salt)))
s.hash[] = h′
return h′
elseif E === DIV
return hash(s.num, hash(s.den, salt ⊻ DIV_SALT))
elseif E === POW
hash(s.exp, hash(s.base, salt ⊻ POW_SALT))
elseif E === TERM
!iszero(salt) && return hash(hash(s, zero(UInt)), salt)
h = s.hash[]
!iszero(h) && return h
op = operation(s)
oph = op isa Function ? nameof(op) : op
h′ = hashvec(arguments(s), hash(oph, salt))
s.hash[] = h′
return h′
else
error_on_type()
end
end

@variables t a x(t) y(t)
expr = [a*x - x*y,-3y + x*y]
@test_reference "target_functions/1.stan" Symbolics.build_function(expr,[x,y],[a],t,target = Symbolics.StanTarget())
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if GROUP == "All" || GROUP == "Core"
@safetestset "Build Function Test" begin include("build_function.jl") end
@safetestset "Build Function Array Test" begin include("build_function_arrayofarray.jl") end
@safetestset "Build Function Array Test Named Tuples" begin include("build_function_arrayofarray_named_tuples.jl") end
VERSION >= v"1.9" && @safetestset "Build Targets Test" begin include("build_targets.jl") end
@safetestset "Build Targets Test" begin include("build_targets.jl") end
@safetestset "Latexify Test" begin include("latexify.jl") end
@safetestset "Domain Test" begin include("domains.jl") end
@safetestset "SymPy Test" begin include("sympy.jl") end
Expand Down