Unverified Commit 70778a8c authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #114 from LCSB-BioCore/mk-fix-piecewise

fix argument order and count for piecewise function
parents 4e68f3f3 951e776d
......@@ -4,14 +4,15 @@ authors = ["Mirek Kratochvil <miroslav.kratochvil@uni.lu>", "LCSB R3 team <lcsb-
version = "0.5.5"
[deps]
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
SBML_jll = "bb12108a-f4ef-5f88-8ef3-0b33ff7017f1"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
[compat]
julia = "1.5"
Symbolics = "0.1.21, 1"
julia = "1.5"
[extras]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
......
......@@ -3,6 +3,7 @@ module SBML
using SBML_jll, Libdl
using SparseArrays
using Symbolics
using IfElse
include("types.jl")
include("structs.jl")
......
......@@ -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,
......@@ -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
IfElse.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)
......@@ -103,7 +114,7 @@ function Base.convert(
convert_time = (x::SBML.MathTime) -> Num(Variable(Symbol(x.id))).val,
convert_const = (x::SBML.MathConst) -> Num(default_symbolics_constants[x.id]),
)
conv(x::SBML.MathApply) = eval(allowed_sym(x.fn, mapping))(conv.(x.args)...)
conv(x::SBML.MathApply) = Num(eval(allowed_sym(x.fn, mapping))(conv.(x.args)...))
conv(x::SBML.MathTime) = convert_time(x)
conv(x::SBML.MathConst) = convert_const(x)
conv(x::SBML.MathIdent) = Num(Variable(Symbol(x.id))).val
......
......@@ -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),
],
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment