-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix multiplication of particles and quantity #159
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #159 +/- ##
==========================================
- Coverage 89.59% 89.33% -0.27%
==========================================
Files 20 20
Lines 1153 1153
==========================================
- Hits 1033 1030 -3
- Misses 120 123 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Seems to work for me, thanks! |
QT = Base.promote_op($op, T, typeof(y)) | ||
$PT{QT,N}($(op).(p.particles, y)) | ||
end | ||
|
||
# Below is just the reverse signature of above | ||
function Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Quantity, N} | ||
function Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Number, N} | ||
QT = Base.promote_op($op, typeof(y), T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why these promote_op calls are needed at all?
Seems like
Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Number, N} = $PT($(op).(y, p.particles))
would work exactly the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, indeed – it cannot infer the 2nd argument, number of particles.
Still, it's generally recommended to avoid explicitly calling inference (promote_op
) whenever possible, and the approach used elsewhere in this package is cleaner, eg
MonteCarloMeasurements.jl/src/register_primitive.jl
Lines 44 to 46 in 814ca57
function ($m.$f)(p::$PT{T,N},a::Real...) where {T,N} | |
res = ($m.$f).(p.particles, MonteCarloMeasurements.maybe_particles.(a)...) # maybe_particles introduced to handle >2 arg operators | |
return $PT{eltype(res),N}(res) |
function Base.$f(y::Quantity, p::$PT{T,N}) where {T, N}
res = $(op).(y, p.particles)
$PT{eltype(res), N}(res)
end
closes #152