You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/06/06 08:00:17 UTC

[commons-rng] 04/11: RNG-75: Use SplitMix64.next()

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit aa246979feb8c880c60c972faf7c9ffb9174f4cd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri May 31 22:35:25 2019 +0100

    RNG-75: Use SplitMix64.next()
---
 .../java/org/apache/commons/rng/simple/internal/Long2IntArray.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
index d98a77c..2f7660c 100644
--- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
+++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
@@ -62,11 +62,11 @@ public class Long2IntArray implements Seed2ArrayConverter<Long, int[]> {
         int i = 0;
         // Handle an odd size
         if ((size & 1) == 1) {
-            out[i++] = NumberFactory.extractHi(rng.nextLong());
+            out[i++] = NumberFactory.extractHi(rng.next());
         }
         // Fill the remaining pairs
         while (i < size) {
-            final long v = rng.nextLong();
+            final long v = rng.next();
             out[i] = NumberFactory.extractHi(v);
             out[i + 1] = NumberFactory.extractLo(v);
             i += 2;


Re: [RNG] Re: [commons-rng] 04/11: RNG-75: Use SplitMix64.next()

Posted by Alex Herbert <al...@gmail.com>.
On 06/06/2019 16:07, Gilles Sadowski wrote:
> Hi.
>
> Not sure about the changes below.
> It seems to me that "nextLong()" ensures that a "long" is generated,
> while "next()" could, if the RNG type is later changed, return an "int"
> cast to "long" (i.e. half its bits set to zero).
>
> Regards,
> Gilles

Good spot. It was introduced when looking at a weird performance spike 
in the JMH timings for seed conversion. I do not think it was the 
problem and could be a bigger, different problem in the future.

I will fix this with a revert.

>
> Le jeu. 6 juin 2019 à 10:00, <ah...@apache.org> a écrit :
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> aherbert pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/commons-rng.git
>>
>> commit aa246979feb8c880c60c972faf7c9ffb9174f4cd
>> Author: Alex Herbert <ah...@apache.org>
>> AuthorDate: Fri May 31 22:35:25 2019 +0100
>>
>>      RNG-75: Use SplitMix64.next()
>> ---
>>   .../java/org/apache/commons/rng/simple/internal/Long2IntArray.java    | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> index d98a77c..2f7660c 100644
>> --- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> +++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> @@ -62,11 +62,11 @@ public class Long2IntArray implements Seed2ArrayConverter<Long, int[]> {
>>           int i = 0;
>>           // Handle an odd size
>>           if ((size & 1) == 1) {
>> -            out[i++] = NumberFactory.extractHi(rng.nextLong());
>> +            out[i++] = NumberFactory.extractHi(rng.next());
>>           }
>>           // Fill the remaining pairs
>>           while (i < size) {
>> -            final long v = rng.nextLong();
>> +            final long v = rng.next();
>>               out[i] = NumberFactory.extractHi(v);
>>               out[i + 1] = NumberFactory.extractLo(v);
>>               i += 2;
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [RNG] Re: [commons-rng] 04/11: RNG-75: Use SplitMix64.next()

Posted by Alex Herbert <al...@gmail.com>.
On 06/06/2019 16:07, Gilles Sadowski wrote:
> Hi.
>
> Not sure about the changes below.
> It seems to me that "nextLong()" ensures that a "long" is generated,
> while "next()" could, if the RNG type is later changed, return an "int"
> cast to "long" (i.e. half its bits set to zero).
>
> Regards,
> Gilles

Good spot. It was introduced when looking at a weird performance spike 
in the JMH timings for seed conversion. I do not think it was the 
problem and could be a bigger, different problem in the future.

I will fix this with a revert.

>
> Le jeu. 6 juin 2019 à 10:00, <ah...@apache.org> a écrit :
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> aherbert pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/commons-rng.git
>>
>> commit aa246979feb8c880c60c972faf7c9ffb9174f4cd
>> Author: Alex Herbert <ah...@apache.org>
>> AuthorDate: Fri May 31 22:35:25 2019 +0100
>>
>>      RNG-75: Use SplitMix64.next()
>> ---
>>   .../java/org/apache/commons/rng/simple/internal/Long2IntArray.java    | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> index d98a77c..2f7660c 100644
>> --- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> +++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
>> @@ -62,11 +62,11 @@ public class Long2IntArray implements Seed2ArrayConverter<Long, int[]> {
>>           int i = 0;
>>           // Handle an odd size
>>           if ((size & 1) == 1) {
>> -            out[i++] = NumberFactory.extractHi(rng.nextLong());
>> +            out[i++] = NumberFactory.extractHi(rng.next());
>>           }
>>           // Fill the remaining pairs
>>           while (i < size) {
>> -            final long v = rng.nextLong();
>> +            final long v = rng.next();
>>               out[i] = NumberFactory.extractHi(v);
>>               out[i + 1] = NumberFactory.extractLo(v);
>>               i += 2;
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[RNG] Re: [commons-rng] 04/11: RNG-75: Use SplitMix64.next()

Posted by Gilles Sadowski <gi...@gmail.com>.
Hi.

Not sure about the changes below.
It seems to me that "nextLong()" ensures that a "long" is generated,
while "next()" could, if the RNG type is later changed, return an "int"
cast to "long" (i.e. half its bits set to zero).

Regards,
Gilles

Le jeu. 6 juin 2019 à 10:00, <ah...@apache.org> a écrit :
>
> This is an automated email from the ASF dual-hosted git repository.
>
> aherbert pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-rng.git
>
> commit aa246979feb8c880c60c972faf7c9ffb9174f4cd
> Author: Alex Herbert <ah...@apache.org>
> AuthorDate: Fri May 31 22:35:25 2019 +0100
>
>     RNG-75: Use SplitMix64.next()
> ---
>  .../java/org/apache/commons/rng/simple/internal/Long2IntArray.java    | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
> index d98a77c..2f7660c 100644
> --- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
> +++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/internal/Long2IntArray.java
> @@ -62,11 +62,11 @@ public class Long2IntArray implements Seed2ArrayConverter<Long, int[]> {
>          int i = 0;
>          // Handle an odd size
>          if ((size & 1) == 1) {
> -            out[i++] = NumberFactory.extractHi(rng.nextLong());
> +            out[i++] = NumberFactory.extractHi(rng.next());
>          }
>          // Fill the remaining pairs
>          while (i < size) {
> -            final long v = rng.nextLong();
> +            final long v = rng.next();
>              out[i] = NumberFactory.extractHi(v);
>              out[i + 1] = NumberFactory.extractLo(v);
>              i += 2;
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org