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

Passing parameter lists #30

Closed
magbenji opened this issue Dec 10, 2020 · 1 comment
Closed

Passing parameter lists #30

magbenji opened this issue Dec 10, 2020 · 1 comment

Comments

@magbenji
Copy link

I've been trying to get diffeqr to work a passed parameter list and I get the following:

f <- function(u,p,t) {
   with(as.list(p), {
   du1 = p1*(u[2]-u[1])
   du2 = u[1]*(p2-u[3]) - u[2]
  du3 = u[1]*u[2] - p3*u[3]
  return(list(c(du1,du2,du3)))
 })
}

u0 <- c(1.0,0.0,0.0)
tspan <- c(0.0,100.0)
p <- list(p1=10.0,p2=28.0,p3=8/3)
prob <- de$ODEProblem(f, u0, tspan, p)

Which produces this error:

Error: Error happens in Julia.
MethodError: Cannot convert an object of type Array{Float64,1} to an object of type Float64
Closest candidates are:
convert(::Type{T}, !Matched::ArrayInterface.StaticInt{N}) where {T<:Number, N} at /Users/bridenhour/.julia/packages/ArrayInterface/q5Rwc/src/static.jl:18
convert(::Type{T}, !Matched::VectorizationBase.LazyMulAdd{M,O,I}) where {M, O, I, T<:Number} at /Users/bridenhour/.julia/packages/VectorizationBase/AzQKz/src/lazymul.jl:17
convert(::Type{T}, !Matched::VectorizationBase.Vec{W,S}) where {T<:Number, S, W} at /Users/bridenhour/.julia/packages/VectorizationBase/AzQKz/src/llvm_intrin/conversion.jl:96
...
Stacktrace:
[1] setindex!(::Array{Float64,1}, ::Array{Float64,1}, ::Int64) at ./array.jl:847
[2] _unsafe_copyto!(::Array{Float64,1}, ::Int64, ::Array{Any,1}, ::Int64, ::Int64) at ./array.jl:257
[3] unsafe_copyto! at ./array.jl:311 [inlined]
[4] _copyto_impl! at ./array.jl:335 [inlined]
[5] copyto! at ./array.jl:321 [inlined]
[6]

@magbenji
Copy link
Author

I figured out that the error was being produced by calling return(list(c(...))); if you just use return(c(...)), things work as expected. The JIT compilation still fails with:

Error: Error happens in Julia.
KeyError: key 'p' not found
Stacktrace:
[1] getindex at ./dict.jl:467 [inlined]
[2] #6 at ./none:0 [inlined]
[3] iterate at ./generator.jl:47 [inlined]
[4] join(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Base.Generator{String,ModelingToolkit.var"#6#7"}, ::String) at ./strings/io.jl:294
[5] join(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Base.Generator{String,ModelingToolkit.var"#6#7"}) at ./strings/io.jl:293
[6] sprint(::Function, ::Base.Generator{String,ModelingToolkit.var"#6#7"}; context::Nothing, sizehint::Int64) at ./strings/io.jl:105
[7] sprint at ./strings/io.jl:101 [inlined]
[8] join at ./strings/io.jl:300 [inlined]
[9] map_subscripts at /Users/bridenhour/.julia/packages/ModelingToolkit/Q7n8K/src/variables.jl:16 [inlined]
[10] _broadcast_getindex_evalf at ./broadcast.jl:648 [inlined]
[11] _broadcast_getindex at ./broadcast.jl:621 [inlined]
[12] #19 at ./broadcast.jl:1046 [inlined]
[13] ntuple at ./ntuple.jl:41 [inlined]
[14] copy at ./

However, it sounded like failure of the JIT routine might have been expected when passing a list of parameters. I will mark this closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant