You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Yogi Valani <ac...@city.ac.uk> on 2013/06/07 00:53:57 UTC

little speed improvement finding the Max Float

Hi I noticed that the function 'func' in MaxFloatFunction.java could be
refactored a little, so that the if statement is only evaluated once.Should
make it run a little faster over large arrays.

 Please share your thoughts on the change I have attached a patch file.

Many thanks

Re: little speed improvement finding the Max Float

Posted by Yogi Valani <ac...@city.ac.uk>.
Good point. And using NEGATIVE_INFINITY would also eliminate the need for a
comment.

Should/Shouldn't I create a JIRA for this?

Also I assume this is the same for MinFloatFunction


On Fri, Jun 7, 2013 at 3:31 PM, Yonik Seeley <yo...@lucidworks.com> wrote:

> Actually, NEGATIVE_INFINITY is the smallest value.
> Not sure we should open up a JIRA for every super-minor refactoring
> like this though...
>
> -Yonik
> http://lucidworks.com
>
>
> On Fri, Jun 7, 2013 at 10:29 AM, Erick Erickson <er...@gmail.com>
> wrote:
> > Looks good, the discussion at the link you provided hurts my head <G>...
> >
> > I'd recommend you go ahead and open up a JIRA and attach a patch...
> >
> > Best
> > Erick
> >
> > On Fri, Jun 7, 2013 at 10:24 AM, Yogi Valani <ac...@city.ac.uk> wrote:
> >> Erica thanks for the reply and the helpful comments (I will try and
> follow
> >> convention in the future).
> >>
> >> That change is much better. With regards to  Float.MIN_VALUE see
> >>
> http://stackoverflow.com/questions/9746850/min-value-of-float-in-java-is-positive-why
> >>
> >> How about we change the line and a comment stating why we use negative
> >> MAX_VALUE
> >>
> >>   float val = -Float.MAX_VALUE;  // NB. MIN_VALUE represents the
> smallest
> >> positive value and -MAX_VALUE represents the the mathematical minimum
> >>
> >> What do you think?
> >>
> >> Regards
> >>
> >> Yogi
> >>
> >>
> >>
> >> On Fri, Jun 7, 2013 at 11:55 AM, Erick Erickson <
> erickerickson@gmail.com>
> >> wrote:
> >>>
> >>> Thanks for looking at this...
> >>>
> >>> Couple of things:
> >>> 1> your code won't compile, the "doc" variable in the initialValue
> >>> method is undefined.
> >>> 2> on the "how to contribute" page, there should be links to style
> >>> files for Eclipse and IntelliJ
> >>>     For instance, indents should be two spaces.... Not a big deal, but
> >>> if you intend to get into
> >>>     more code it's worth the time to install it....
> >>>
> >>> What do you think about this alternative?
> >>>
> >>>   protected float func(int doc, FunctionValues[] valsArr) {
> >>>     if (valsArr.length == 0) return 0.0f;
> >>>     float val = Float.MIN_VALUE;
> >>>     for (FunctionValues vals : valsArr) {
> >>>       val = Math.max(vals.floatVal(doc), val);
> >>>     }
> >>>     return val;
> >>>   }
> >>>
> >>> Best
> >>> Erick
> >>>
> >>> On Thu, Jun 6, 2013 at 6:53 PM, Yogi Valani <ac...@city.ac.uk> wrote:
> >>> > Hi I noticed that the function 'func' in MaxFloatFunction.java could
> be
> >>> > refactored a little, so that the if statement is only evaluated
> >>> > once.Should
> >>> > make it run a little faster over large arrays.
> >>> >
> >>> >  Please share your thoughts on the change I have attached a patch
> file.
> >>> >
> >>> > Many thanks
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > ---------------------------------------------------------------------
> >>> > To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> >>> > For additional commands, e-mail: dev-help@lucene.apache.org
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> >>> For additional commands, e-mail: dev-help@lucene.apache.org
> >>>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: dev-help@lucene.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
>

Re: little speed improvement finding the Max Float

Posted by Yonik Seeley <yo...@lucidworks.com>.
Actually, NEGATIVE_INFINITY is the smallest value.
Not sure we should open up a JIRA for every super-minor refactoring
like this though...

-Yonik
http://lucidworks.com


On Fri, Jun 7, 2013 at 10:29 AM, Erick Erickson <er...@gmail.com> wrote:
> Looks good, the discussion at the link you provided hurts my head <G>...
>
> I'd recommend you go ahead and open up a JIRA and attach a patch...
>
> Best
> Erick
>
> On Fri, Jun 7, 2013 at 10:24 AM, Yogi Valani <ac...@city.ac.uk> wrote:
>> Erica thanks for the reply and the helpful comments (I will try and follow
>> convention in the future).
>>
>> That change is much better. With regards to  Float.MIN_VALUE see
>> http://stackoverflow.com/questions/9746850/min-value-of-float-in-java-is-positive-why
>>
>> How about we change the line and a comment stating why we use negative
>> MAX_VALUE
>>
>>   float val = -Float.MAX_VALUE;  // NB. MIN_VALUE represents the smallest
>> positive value and -MAX_VALUE represents the the mathematical minimum
>>
>> What do you think?
>>
>> Regards
>>
>> Yogi
>>
>>
>>
>> On Fri, Jun 7, 2013 at 11:55 AM, Erick Erickson <er...@gmail.com>
>> wrote:
>>>
>>> Thanks for looking at this...
>>>
>>> Couple of things:
>>> 1> your code won't compile, the "doc" variable in the initialValue
>>> method is undefined.
>>> 2> on the "how to contribute" page, there should be links to style
>>> files for Eclipse and IntelliJ
>>>     For instance, indents should be two spaces.... Not a big deal, but
>>> if you intend to get into
>>>     more code it's worth the time to install it....
>>>
>>> What do you think about this alternative?
>>>
>>>   protected float func(int doc, FunctionValues[] valsArr) {
>>>     if (valsArr.length == 0) return 0.0f;
>>>     float val = Float.MIN_VALUE;
>>>     for (FunctionValues vals : valsArr) {
>>>       val = Math.max(vals.floatVal(doc), val);
>>>     }
>>>     return val;
>>>   }
>>>
>>> Best
>>> Erick
>>>
>>> On Thu, Jun 6, 2013 at 6:53 PM, Yogi Valani <ac...@city.ac.uk> wrote:
>>> > Hi I noticed that the function 'func' in MaxFloatFunction.java could be
>>> > refactored a little, so that the if statement is only evaluated
>>> > once.Should
>>> > make it run a little faster over large arrays.
>>> >
>>> >  Please share your thoughts on the change I have attached a patch file.
>>> >
>>> > Many thanks
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
>>> > For additional commands, e-mail: dev-help@lucene.apache.org
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: dev-help@lucene.apache.org
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>

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


Re: little speed improvement finding the Max Float

Posted by Erick Erickson <er...@gmail.com>.
Looks good, the discussion at the link you provided hurts my head <G>...

I'd recommend you go ahead and open up a JIRA and attach a patch...

Best
Erick

On Fri, Jun 7, 2013 at 10:24 AM, Yogi Valani <ac...@city.ac.uk> wrote:
> Erica thanks for the reply and the helpful comments (I will try and follow
> convention in the future).
>
> That change is much better. With regards to  Float.MIN_VALUE see
> http://stackoverflow.com/questions/9746850/min-value-of-float-in-java-is-positive-why
>
> How about we change the line and a comment stating why we use negative
> MAX_VALUE
>
>   float val = -Float.MAX_VALUE;  // NB. MIN_VALUE represents the smallest
> positive value and -MAX_VALUE represents the the mathematical minimum
>
> What do you think?
>
> Regards
>
> Yogi
>
>
>
> On Fri, Jun 7, 2013 at 11:55 AM, Erick Erickson <er...@gmail.com>
> wrote:
>>
>> Thanks for looking at this...
>>
>> Couple of things:
>> 1> your code won't compile, the "doc" variable in the initialValue
>> method is undefined.
>> 2> on the "how to contribute" page, there should be links to style
>> files for Eclipse and IntelliJ
>>     For instance, indents should be two spaces.... Not a big deal, but
>> if you intend to get into
>>     more code it's worth the time to install it....
>>
>> What do you think about this alternative?
>>
>>   protected float func(int doc, FunctionValues[] valsArr) {
>>     if (valsArr.length == 0) return 0.0f;
>>     float val = Float.MIN_VALUE;
>>     for (FunctionValues vals : valsArr) {
>>       val = Math.max(vals.floatVal(doc), val);
>>     }
>>     return val;
>>   }
>>
>> Best
>> Erick
>>
>> On Thu, Jun 6, 2013 at 6:53 PM, Yogi Valani <ac...@city.ac.uk> wrote:
>> > Hi I noticed that the function 'func' in MaxFloatFunction.java could be
>> > refactored a little, so that the if statement is only evaluated
>> > once.Should
>> > make it run a little faster over large arrays.
>> >
>> >  Please share your thoughts on the change I have attached a patch file.
>> >
>> > Many thanks
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
>> > For additional commands, e-mail: dev-help@lucene.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: dev-help@lucene.apache.org
>>
>

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


Re: little speed improvement finding the Max Float

Posted by Yogi Valani <ac...@city.ac.uk>.
Erica thanks for the reply and the helpful comments (I will try and follow
convention in the future).

That change is much better. With regards to  Float.MIN_VALUE see
http://stackoverflow.com/questions/9746850/min-value-of-float-in-java-is-positive-why

How about we change the line and a comment stating why we use negative
MAX_VALUE

  float val = -Float.MAX_VALUE;  // NB. MIN_VALUE represents the smallest
positive value and -MAX_VALUE represents the the mathematical minimum

What do you think?

Regards

Yogi



On Fri, Jun 7, 2013 at 11:55 AM, Erick Erickson <er...@gmail.com>wrote:

> Thanks for looking at this...
>
> Couple of things:
> 1> your code won't compile, the "doc" variable in the initialValue
> method is undefined.
> 2> on the "how to contribute" page, there should be links to style
> files for Eclipse and IntelliJ
>     For instance, indents should be two spaces.... Not a big deal, but
> if you intend to get into
>     more code it's worth the time to install it....
>
> What do you think about this alternative?
>
>   protected float func(int doc, FunctionValues[] valsArr) {
>     if (valsArr.length == 0) return 0.0f;
>     float val = Float.MIN_VALUE;
>     for (FunctionValues vals : valsArr) {
>       val = Math.max(vals.floatVal(doc), val);
>     }
>     return val;
>   }
>
> Best
> Erick
>
> On Thu, Jun 6, 2013 at 6:53 PM, Yogi Valani <ac...@city.ac.uk> wrote:
> > Hi I noticed that the function 'func' in MaxFloatFunction.java could be
> > refactored a little, so that the if statement is only evaluated
> once.Should
> > make it run a little faster over large arrays.
> >
> >  Please share your thoughts on the change I have attached a patch file.
> >
> > Many thanks
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: dev-help@lucene.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
>

Re: little speed improvement finding the Max Float

Posted by Erick Erickson <er...@gmail.com>.
Thanks for looking at this...

Couple of things:
1> your code won't compile, the "doc" variable in the initialValue
method is undefined.
2> on the "how to contribute" page, there should be links to style
files for Eclipse and IntelliJ
    For instance, indents should be two spaces.... Not a big deal, but
if you intend to get into
    more code it's worth the time to install it....

What do you think about this alternative?

  protected float func(int doc, FunctionValues[] valsArr) {
    if (valsArr.length == 0) return 0.0f;
    float val = Float.MIN_VALUE;
    for (FunctionValues vals : valsArr) {
      val = Math.max(vals.floatVal(doc), val);
    }
    return val;
  }

Best
Erick

On Thu, Jun 6, 2013 at 6:53 PM, Yogi Valani <ac...@city.ac.uk> wrote:
> Hi I noticed that the function 'func' in MaxFloatFunction.java could be
> refactored a little, so that the if statement is only evaluated once.Should
> make it run a little faster over large arrays.
>
>  Please share your thoughts on the change I have attached a patch file.
>
> Many thanks
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org

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