-
-
Notifications
You must be signed in to change notification settings - Fork 463
Added a Distribution<usize> for Poisson #958
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Using the casting from f64 -> u64 -> usize.
Mimiced the approach for to_u64.
Hey, am I supposed to do something here or just wait for another review? |
Probably just wait. I am not a member of |
Thanks!
…On Sat, 4 Apr 2020 at 18:09, bjorn3 ***@***.***> wrote:
Probably just wait. I am not a member of rust-random.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#958 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIDVSGOA3ESUML6KM5O2WTRK5LSNANCNFSM4L22JCYQ>
.
|
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.
fn to_usize(self) -> Option<usize> { | ||
if self >= 0. && self <= ::core::usize::MAX as f32 { |
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.
This is incorrect for 32-bit platforms. Check this out.
This isn't your fault; to_u64
for f64
makes the same mistake. Hmm, even the TryFrom
in Rust 1.34 doesn't handle this conversion. I'm starting to hate this topic; seems simple but isn'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.
Ohh this issue. I don't know how to solve this aswell. The link didn't suggest a solution. I think this belongs in another PR, or something?
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.
Yes: #973
I'm a bit wary of sampling What is the motivation for adding this instead of letting the user deal with the conversion from a float? Should we also add support for the other integer types? |
Why is this useful? If you do want this then I'd suspect you want
|
I just thought that this was just a little missing detail to add. I don't think there should be implementation for all integer types, but for count-distributions, it |
As a rule, implementations for |
I think this does that. Do you mind checking? |
I think the API should be consistent with what it is supposed to reflect. A Poisson distribution have realisations that are I'd love to carry argue more for this, or even do more necessary work to make that happen. |
Actually, this seems fine as-is to me, except for the issue I raised. But maybe we should solve that separately. I'll open an issue. |
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.
let result: u64 = self.sample(rng); | ||
result as usize | ||
let result: N = self.sample(rng); | ||
result.to_usize().unwrap() |
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.
This may panic on 32-bit platforms. Maybe we should document that somewhere?
Unfortunately, this is incompatible with the choices in #987. We now require the user to perform the conversion from |
I just needed this and couldn't implement it in my own crate.
Using the casting from f64 -> u64 -> usize.
I'd like to hear suggestions and concerns, as I am unsure this is the best thing to do for this type of conversation.