You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I drafted a reasonably simple and more generic bymap version that works for arbitrary inputs that contain Particles inside.
It assumes (and asserts) all Particles have the same number of particles and iterates over them.
In the end, it gathers all results from applying f to arguments stripped of Particles, and transforms all numeric arguments there into Particles, keeping non-numbers from the first output. Assumes that all f results are consistent, have the same structure.
import MonteCarloMeasurements as MCM
using AccessorsExtra
functionbymap₊(f, args...)
Ns =@getall args |>RecursiveOfType(MCM.AbstractParticles) |>length(_.particles)
N =uniqueonly(Ns)
vals =map(1:N) do i
curargs =@modify(args |>RecursiveOfType(MCM.AbstractParticles)) do p
p.particles[i]
endf(curargs...)
end
v =first(vals)
numoptics = AccessorsExtra.flat_concatoptic(v, RecursiveOfType(Number))
valps =map(o -> MCM.Particles(o.(vals)), AccessorsExtra._optics(numoptics))
returnsetall(v, numoptics, valps)
end
x = (MCM.Particles(randn(1024)), (a=MCM.Particles(randn(1024)), b=123))
bymap₊(x) do x
vals = (x[1], x[2].a)
(;x[2].b, i=argmax(vals))
end# returns:# (b = 123.0 ± 0.0, i = 1.52 ± 0.5)
I'm not proposing to include it here, but wonder if you have some suggestions/recommendations on the specific semantics given your experience with bymap/Workspace. This bymap₊ is supposed to be much easier to use than the workspace thing, and applicable in many cases.
The text was updated successfully, but these errors were encountered:
I drafted a reasonably simple and more generic
bymap
version that works for arbitrary inputs that containParticles
inside.It assumes (and asserts) all
Particles
have the same number of particles and iterates over them.In the end, it gathers all results from applying
f
to arguments stripped of Particles, and transforms all numeric arguments there intoParticles
, keeping non-numbers from the first output. Assumes that allf
results are consistent, have the same structure.I'm not proposing to include it here, but wonder if you have some suggestions/recommendations on the specific semantics given your experience with bymap/Workspace. This
bymap₊
is supposed to be much easier to use than the workspace thing, and applicable in many cases.The text was updated successfully, but these errors were encountered: