Skip to content

Commit

Permalink
fix argument order and count for piecewise function
Browse files Browse the repository at this point in the history
Fixes #112
  • Loading branch information
exaexa committed Jul 10, 2021
1 parent 00b48fb commit b276ed4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const default_symbolics_mapping = Dict{String,Any}(
"ln" => :log,
"log" => :sbmlLog,
"lt" => :<,
"piecewise" => :(Core.ifelse),
"piecewise" => :(sbmlPiecewise),
"power" => :^,
"root" => :sbmlRoot,
"sech" => :sech,
Expand All @@ -56,6 +56,17 @@ const default_symbolics_mapping = Dict{String,Any}(
"tan" => :tan,
)

function sbmlPiecewise(args...)
if length(args) == 1
args[1]
elseif length(args) >= 3
Core.ifelse(args[2], args[1], sbmlPiecewise(args[3:end]...))
else
throw(AssertionError("malformed piecewise SBML function"))
end
end


sbmlLog(x) = log(x, 10)
sbmlLog(base, x) = log(base, x)

Expand Down
2 changes: 1 addition & 1 deletion test/symbolics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
test = SBML.MathApply(
"piecewise",
SBML.Math[
SBML.MathApply("lt", SBML.Math[SBML.MathVal(1), SBML.MathVal(0)]),
SBML.MathVal(123),
SBML.MathApply("lt", SBML.Math[SBML.MathVal(1), SBML.MathVal(0)]),
SBML.MathVal(456),
],
)
Expand Down

0 comments on commit b276ed4

Please sign in to comment.