[PATCH] libstdc++: add uniform on sphere distribution
Marc Glisse
marc.glisse@inria.fr
Sat Aug 9 12:34:00 GMT 2014
On Sat, 9 Aug 2014, Ulrich Drepper wrote:
> On Sat, Aug 9, 2014 at 3:15 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> While there, do we want to also reject infinite norms?
>> I would have done: while (__sum < small || __sum > large)
>> but testing exactly for 0 and infinity seems good enough.
>
> I guess the squaring can theoretically overflow and produce infinity.
> It will never happen with the way we generate normally distributed
> numbers, though. These values are always so unlikely that it is OK
> that the algorithms cannot return them. If you insist I'll add a test
> for infinity.
Oh, a comment saying exactly what you just said would be fine with me (or
even nothing).
> The other change (which would eliminate the necessity for this test in
> a special case) is to use hypot for _Dimen==2. This might be a case
> common enough to warrant that little bit of extra text. I'll prepare
> a patch.
If you are going to specialize for dim 2, I imagine you won't be computing
normal distributions, you will only generate a point uniformy in a square
and reject it if it is not in the ball? (interestingly enough this is used
as a subroutine by the implementation of normal_distribution)
--
Marc Glisse
More information about the Libstdc++
mailing list