[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-18 Thread Dawid Weiss (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13395487#comment-13395487
 ] 

Dawid Weiss commented on LUCENE-4148:
-

I didn't check _TestUtil, to be honest -- I think it did have a bug with range 
overflow passed to nextInt (which is not a problem in practice, but was my 
example on how randomized testing can explore unexpected things). 

Anyway, as for randomLongBetween -- here you'd need to be more careful about 
double's representation so simple scaling won't work (there are ranges of 
double that transform to NaNs for example). I am not so strong in numerical 
analysis to be able to prove something is a correct solution to the problem. My 
(naive) take at this would be to calculate the range and then if split into a 
few cases:

1) if it doesn't exceed a positive int, use nextInt()
2) if it doesn't exceed a positive long, use nextLong()
3) if it does exceed positive long, use BigDecimal? :) 

Maybe this can be done faster without keeping the uniform distribution 
requirement so strong (i.e. use a modulo from a combination of two concatenated 
longs as BigDecimal or something like that).

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-18 Thread Dawid Weiss (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13395992#comment-13395992
 ] 

Dawid Weiss commented on LUCENE-4148:
-

This looks good to me, although I'm wondering how much randomness do we really 
need -- those BigIntegers are worrying. I think this can be improved later if 
somebody wishes to dive into it.

Btw. an interesting random number generator -- 

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial
 Attachments: LUCENE-4148.patch


 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-17 Thread Adrien Grand (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13393632#comment-13393632
 ] 

Adrien Grand commented on LUCENE-4148:
--

It seems to me that {{min}} and {{max}} are inclusive in both methods.

@Dawid could RandomInts have a similar method to generate longs? Something like 
{code}
  public static long randomLongBetween(Random r, long min, long max);
{code}

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-15 Thread Dawid Weiss (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13295713#comment-13295713
 ] 

Dawid Weiss commented on LUCENE-4148:
-

Try RandomInts from randomizedtesting, it does what you need:
{code}
  /** 
   * A random integer from codemin/code to codemax/code (inclusive).
   */
  public static int randomIntBetween(Random r, int min, int max) {
assert max = min : max must be = min:  + min + ,  + max;
long range = (long) max - (long) min;
if (range  Integer.MAX_VALUE) {
  return min + r.nextInt(1 + (int) range);
} else {
  return min + (int) Math.round(r.nextDouble() * range);
}
  } 
{code}

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-15 Thread Robert Muir (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13295715#comment-13295715
 ] 

Robert Muir commented on LUCENE-4148:
-

can we just switch _TestUtil.nextInt to use this then?

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-15 Thread Adrien Grand (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13295720#comment-13295720
 ] 

Adrien Grand commented on LUCENE-4148:
--

bq. Try RandomInts from randomizedtesting

Thanks, it fixes the problem for large range of ints, but I would also like to 
be able to generate random longs ( Integer.MAX_VALUE) in a fixed range. For 
{{PackedInts}}, I always need longs between 0 and a power of 2, but I thought 
it would be more useful to add a general-purpose {{long nextLong(Random, long, 
long)}} to {{_TestUtil}}.

Since {{Random.nextLong(long)}} doesn't exist, it would be tempting to 
implement it by ourselves by using the same logic as {{Random.nextInt(int)}}, 
but I am afraid there would be copyright issues, so we should probably do it 
otherwise (?).

By the way, the code of {{randomIntBetween}} makes me curious, are all values 
as likely when the range of values is {{= Integer.MAX_VALUE}} (ie. when the 
else block gets executed)?

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-4148) _TestUtil should be able to generate random longs

2012-06-15 Thread Dawid Weiss (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanelfocusedCommentId=13295765#comment-13295765
 ] 

Dawid Weiss commented on LUCENE-4148:
-

@Robert: sure we could (noting the subtle difference that the range is 
inclusive on both min and max).

As for distribution... I think it should be uniform over all of the range's 
values assuming r.nextDouble() yields uniform value from [0,1]? It's simple 
scaling after all. I didn't really consider nuances of floating point 
representation here but I think within 2^32 a double should cover everything 
fairly well. 

 _TestUtil should be able to generate random longs
 -

 Key: LUCENE-4148
 URL: https://issues.apache.org/jira/browse/LUCENE-4148
 Project: Lucene - Java
  Issue Type: Improvement
  Components: general/test
Reporter: Adrien Grand
Priority: Trivial

 It would be helpful in TestPackedInts at least, in order to generate random 
 values (as a workaround, we currently generate a random int between 0 and 
 {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
 would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
 -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
 currently fails because the range of values is {{ Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org