Skip to content

Commit 228524e

Browse files
committed
Use mapreduce
1 parent 28c0186 commit 228524e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/mh-core.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ function q(
132132
t::Transition,
133133
t_cond::Transition
134134
)
135-
return sum(map(i -> q(spl.proposal[i], t.params[i], t_cond.params[i]), 1:length(spl.proposal)))
135+
# mapreduce with multiple iterators requires Julia 1.2 or later
136+
return mapreduce(+, 1:length(spl.proposal)) do i
137+
q(spl.proposal[i], t.params[i], t_cond.params[i])
138+
end
136139
end
137140

138141
function q(
@@ -148,14 +151,10 @@ function q(
148151
t::Transition,
149152
t_cond::Transition
150153
)
151-
ks = keys(t.params)
152-
total = 0.0
153-
154-
for k in ks
155-
total += q(spl.proposal[k], t.params[k], t_cond.params[k])
154+
# mapreduce with multiple iterators requires Julia 1.2 or later
155+
return mapreduce(+, keys(t.params)) do k
156+
q(spl.proposal[k], t.params[k], t_cond.params[k])
156157
end
157-
158-
return total
159158
end
160159

161160
# Define the first step! function, which is called at the

0 commit comments

Comments
 (0)