Skip to content

Commit cefe510

Browse files
committed
broadcast MultipleSetters instead of map
fixes #82
1 parent e7dd822 commit cefe510

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/parameter_indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ struct MultipleSetters{S} <: AbstractSetIndexer
609609
end
610610

611611
function (ms::MultipleSetters)(prob, val)
612-
map((s!, v) -> s!(prob, v), ms.setters, val)
612+
broadcast((s!, v) -> s!(prob, v), ms.setters, val)
613613
end
614614

615615
for (t1, t2) in [

test/parameter_indexing_test.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ for sys in [
5454
([1, [:b, :c]], [p[1], p[2:3]], [new_p[1], new_p[2:3]], false),
5555
([1, (:b, :c)], [p[1], (p[2], p[3])], [new_p[1], (new_p[2], new_p[3])], false),
5656
((1, [:b, :c]), (p[1], p[2:3]), (new_p[1], new_p[2:3]), true),
57-
((1, (:b, :c)), (p[1], (p[2], p[3])), (new_p[1], (new_p[2], new_p[3])), true)
57+
((1, (:b, :c)), (p[1], (p[2], p[3])), (new_p[1], (new_p[2], new_p[3])), true),
58+
([:a, :b], p[1:2], 42, true),
5859
]
5960
get = getp(sys, sym)
6061
set! = setp(sys, sym)
@@ -77,13 +78,13 @@ for sys in [
7778
end
7879
@test fi.counter[] == 1
7980

80-
@test get(fi) == newval
81+
@test all(get(fi) .== newval)
8182
set!(fi, oldval)
8283
@test get(fi) == oldval
8384
@test fi.counter[] == 2
8485

8586
fi.ps[sym] = newval
86-
@test get(fi) == newval
87+
@test all(get(fi) .== newval)
8788
@test fi.counter[] == 3
8889
fi.ps[sym] = oldval
8990
@test get(fi) == oldval
@@ -98,7 +99,7 @@ for sys in [
9899
else
99100
set!(p, newval)
100101
end
101-
@test get(p) == newval
102+
@test all(get(p) .== newval)
102103
set!(p, oldval)
103104
@test get(p) == oldval
104105
@test fi.counter[] == 4
@@ -150,6 +151,12 @@ end
150151

151152
Base.getindex(mpo::MyParameterObject, i) = mpo.p[i]
152153

154+
# check throws if setp dimensions do not match
155+
sys = SymbolCache([:x, :y, :z], [:a, :b, :c, :d], [:t])
156+
fi = FakeIntegrator(sys, [1.0, 2.0, 3.0], 0.0, Ref(0))
157+
@test_throws DimensionMismatch setp(fi, 1:2)(fi, [-1.0, -2.0, -3.0])
158+
@test_throws DimensionMismatch setp(fi, 1:3)(fi, [-1.0, -2.0])
159+
153160
struct FakeSolution
154161
sys::SymbolCache
155162
u::Vector{Vector{Float64}}

0 commit comments

Comments
 (0)