Skip to content

Commit

Permalink
Merge pull request #654 from mimiframework/param-type-master
Browse files Browse the repository at this point in the history
Fix parameter type bug for non-time arrays
  • Loading branch information
davidanthoff authored Feb 28, 2020
2 parents 598ca04 + b0f379a commit 1f38a39
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/core/connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,6 @@ Add an array type parameter `name` with value `value` and `dims` dimensions to t
"""
function set_external_array_param!(obj::AbstractCompositeComponentDef,
name::Symbol, value::AbstractArray, dims)
numtype = Union{Missing, number_type(obj)}

if !(typeof(value) <: Array{numtype} || (value isa AbstractArray && eltype(value) <: numtype))
# Need to force a conversion (simple convert may alias in v0.6)
value = Array{numtype}(value)
end
param = ArrayModelParameter(value, dims === nothing ? Vector{Symbol}() : dims)
set_external_param!(obj, name, param)
end
Expand Down
4 changes: 3 additions & 1 deletion test/test_parametertypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ eval(expr) # Just a deprecation warning for v0.10, then will change to error in
f = Parameter{Array{Float64, 2}}()
g = Parameter{Int}(default=10.0) # value should be Int despite Float64 default
h = Parameter(default=10) # should be "numtype", despite Int default
j::Int = Parameter(index = [regions])

function run_timestep(p, v, d, t)
end
Expand All @@ -71,6 +72,7 @@ set_param!(m, :MyComp, :c, [4,5,6])
set_param!(m, :MyComp, :d, 0.5) # 32-bit float constant
set_param!(m, :MyComp, :e, [1,2,3,4])
set_param!(m, :MyComp, :f, reshape(1:16, 4, 4))
set_param!(m, :MyComp, :j, [1,2,3])

extpars = external_params(m)

Expand Down Expand Up @@ -103,7 +105,7 @@ update_param!(m, :d, 5) # should work, will convert to float
@test_throws ErrorException update_param!(m, :e, ones(10)) # wrong size
update_param!(m, :e, [4,5,6,7])

@test length(extpars) == 8
@test length(extpars) == 9
@test typeof(extpars[:a].values) == TimestepMatrix{FixedTimestep{2000, 1}, arrtype, 1}
@test typeof(extpars[:d].value) == numtype
@test typeof(extpars[:e].values) == Array{arrtype, 1}
Expand Down

0 comments on commit 1f38a39

Please sign in to comment.