- Notifications
You must be signed in to change notification settings - Fork 36
Add overloads for sum #264
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
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #264 +/- ## ========================================== + Coverage 90.19% 90.22% +0.03% ========================================== Files 52 52 Lines 10694 10706 +12 ========================================== + Hits 9645 9660 +15 + Misses 1049 1046 -3
Continue to review full report at Codecov.
|
source/mir/math/sum.d Outdated
| } | ||
| | ||
| /// | ||
| sumType!(CommonType!T) sum(T...)(T r) |
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.
Why this overload is required?
| I added two overloads as part of this PR. This one is for when you do `sum(1, 2, 3)` and also `sum(1f, 2, 3)`. The other one is for when you do `sum!float(1, 2, 3)` or `sum!float(1f, 2f, 3f)`. The main difference is that it means the user does not have to provide the type. I wouldn't say it is required. It is a quality-of-life enhancement. The ability to call functions like `f(1, 2, 3)` and have the same behavior as `f([1, 2, 3])` is part of D and I see no reason not to incorporate it if someone is willing to put in the work to add them. If they should not be added for `sum`, then they should be removed from other functions that I have added them for consistency. I think it is valuable to have this functionality for some of these numerical functions, but I would understand if you were not in favor of that. …On Mon, Jun 1, 2020 at 7:06 AM Ilya Yaroshenko ***@***.***> wrote: ***@***.**** commented on this pull request. ------------------------------ In source/mir/math/sum.d <#264 (comment)>: > @@ -1722,6 +1750,15 @@ template sum(Summation summation = Summation.appropriate) import core.lifetime: move; return .sum!(F, ResolveSummationType!(summation, Range, F))(r.move, seed); } + + /// + sumType!(CommonType!T) sum(T...)(T r) Why this overload is required? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#264 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADBFNST4KW6OMR4JDJTEEGLRUODTXANCNFSM4NPXBERQ> . |
The following works well without a variadic template. It is very preferred to avoid variadic templates of functions, the generates a lot of template bloat and hard to maintain. |
2a3a9e0 to 152cbd9 Compare | @9il Sounds good. I used One question I had as I was working on this is that I did not use |
Yes. But it would make sense to add |
* Add variadic overloads to sum * Add sum overloads * Remove sum variadic template * Remove prod/mean variadic templates
This reverts commit 960cb76.
This reverts commit 960cb76.
This reverts commit 4286816.
This reverts commit 4286816.
This PR adds the overloads for
sumthat exist forprodand some of the other statistical functions already.