JuliaMath / MeasureBase.jl

Other
26 stars 4 forks source link

`productmeasure(::Vector{<:Dirac})` #80

Open cscherrer opened 2 years ago

cscherrer commented 2 years ago

Currently, a product of Diracs works like this:

julia> productmeasure(Dirac.([1,2,3]))
ProductMeasure([Dirac(1), Dirac(2), Dirac(3)])

In some cases, we might prefer to write this as

Dirac([1, 2, 3])

This is much simpler, at the cost of an allocation.

For cases where we end up building an array of Diracs only to later take a product, we should look for ways to think ahead, so we can jump straight to this second representation. In this case we can often avoid the allocation.

I don't think there's a need to have a single canonical form for this. We can instead add some methods to deal with ProductMeasure{<:AbstractArray{<:Dirac}} and take advantage of this structure.

oschulz commented 2 years ago

I guess it makes sense to do such "contractions" where possible.