-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Consider the functions f1 and f2:
using MonteCarloMeasurements
using Unitful
function f1(Vi)
if Vi ≤ 0.0
return 0.0
elseif Vi ≥ 1.0
return 1.0
else
Vi
end
end
function f2(Vi)
if Vi ≤ 0.0u"V"
return 0.0u"V"
elseif Vi ≥ 1.0u"V"
return 1.0u"V"
else
return Vi
end
end
then f1(0.0..1.0) succeeds, but f1(-0.5..1.5) fails. This is understandable as the second distribution spans the discontinuities. If I then register_primitive(f1) and subsequently execute f1(-0.5..1.5), it succeeds and inspection of the result shows it is as I expect.
However, if I try the same thing with f2 (which I intend to be the exact same function except that now I’m using Unitful and everything should be in units compatible with u"V"), f2 fails, regardless of register_primitive(f2). Specifically f2((0.0..1.0)u"V") works, but f2((-0.5..1.5)u"V") always fails.
@simeonschaub diagnosed this "The problem here is that (-0.5..1.5)u"V" is creating an object of type Quantity{Particles}, whereas register_primitive only overloads f2 for Particles, so that second method never gets called."
See https://discourse.julialang.org/t/problem-combining-unitful-and-montecarlomeasurements/35418