Skip to content

Commit 426cdf9

Browse files
committed
broadcast MultipleSetters instead of map
fixes #82
1 parent c9c7b6c commit 426cdf9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/parameter_indexing.jl

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

206206
function (ms::MultipleSetters)(prob, val)
207-
map((s!, v) -> s!(prob, v), ms.setters, val)
207+
broadcast((s!, v) -> s!(prob, v), ms.setters, val)
208208
end
209209

210210
for (t1, t2) in [

test/parameter_indexing_test.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ for pType in [Vector, Tuple]
3535
([1, [:b, :c]], [p[1], p[2:3]], [new_p[1], new_p[2:3]], false),
3636
([1, (:b, :c)], [p[1], (p[2], p[3])], [new_p[1], (new_p[2], new_p[3])], false),
3737
((1, [:b, :c]), (p[1], p[2:3]), (new_p[1], new_p[2:3]), true),
38-
((1, (:b, :c)), (p[1], (p[2], p[3])), (new_p[1], (new_p[2], new_p[3])), true)
38+
((1, (:b, :c)), (p[1], (p[2], p[3])), (new_p[1], (new_p[2], new_p[3])), true),
39+
([:a, :b], p[1:2], 42, true),
3940
]
4041
get = getp(sys, sym)
4142
set! = setp(sys, sym)
@@ -58,13 +59,13 @@ for pType in [Vector, Tuple]
5859
end
5960
@test fi.counter[] == 1
6061

61-
@test get(fi) == newval
62+
@test all(get(fi) .== newval)
6263
set!(fi, oldval)
6364
@test get(fi) == oldval
6465
@test fi.counter[] == 2
6566

6667
fi.ps[sym] = newval
67-
@test get(fi) == newval
68+
@test all(get(fi) .== newval)
6869
@test fi.counter[] == 3
6970
fi.ps[sym] = oldval
7071
@test get(fi) == oldval
@@ -79,7 +80,7 @@ for pType in [Vector, Tuple]
7980
else
8081
set!(p, newval)
8182
end
82-
@test get(p) == newval
83+
@test all(get(p) .== newval)
8384
set!(p, oldval)
8485
@test get(p) == oldval
8586
@test fi.counter[] == 4
@@ -99,6 +100,11 @@ for pType in [Vector, Tuple]
99100
end
100101
end
101102

103+
# check throws if setp dimensions do not match
104+
fi = FakeIntegrator(sys, [1.0, 2.0, 3.0], Ref(0))
105+
@test_throws DimensionMismatch setp(fi, 1:2)(fi, [-1.0, -2.0, -3.0])
106+
@test_throws DimensionMismatch setp(fi, 1:3)(fi, [-1.0, -2.0])
107+
102108
struct FakeSolution
103109
sys::SymbolCache
104110
u::Vector{Vector{Float64}}

0 commit comments

Comments
 (0)