You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2009/01/02 15:44:04 UTC
[math] Shoud OpenIntToDoubleHashMap get return NaN instead of 0 for
key not found?
I am still working through this class and the sparse matrix class that
it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
changing this would cause problems, but the current setup (returning 0
for missing keys) limits usefulness of this class. I see how this is
convenient for sparse matrices; but I would see NaN as a more natural
return value for non-existent keys in the general case. Alternatively,
I guess we could add another method get(int key, double missingReturn).
Thoughts?
Phil
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of
0 for key not found?
Posted by Sujit Pal <su...@comcast.net>.
If OpenIntToDoubleHashMap returns NaN for non-existent keys, then the
Sparse Matrix could check for NaN to return 0 to its client.
-sujit
Phil Steitz wrote:
> I am still working through this class and the sparse matrix class that
> it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
> changing this would cause problems, but the current setup (returning 0
> for missing keys) limits usefulness of this class. I see how this is
> convenient for sparse matrices; but I would see NaN as a more natural
> return value for non-existent keys in the general case.
> Alternatively, I guess we could add another method get(int key,
> double missingReturn).
>
> Thoughts?
>
> Phil
>
> ---------------------------------------------------------------------
> 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: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of
0 for key not found?
Posted by Luc Maisonobe <Lu...@free.fr>.
Phil Steitz a écrit :
> sebb wrote:
>> On 02/01/2009, Luc Maisonobe <Lu...@free.fr> wrote:
>>
>>> Phil Steitz a écrit :
>>>
>>>
>>>> I am still working through this class and the sparse matrix class that
>>>>
>>> > it was extracted from (thanks, Ismael and Sugit!), so I am not
>>> sure if
>>> > changing this would cause problems, but the current setup
>>> (returning 0
>>> > for missing keys) limits usefulness of this class. I see how
>>> this is
>>> > convenient for sparse matrices; but I would see NaN as a more natural
>>> > return value for non-existent keys in the general case.
>>> Alternatively,
>>> > I guess we could add another method get(int key, double
>>> missingReturn).
>>> >
>>> > Thoughts?
>>>
>>>
>>> I had exactly the same thought while extracting the class.
>>> I also prefer to use Double.NaN for numbers that have never been
>>> initialized explicitly, but I also understand 0 is more logical in the
>>> special case of sparse matrices.
>>>
>>
>> +0 (I never used Math, but seems sensible)
>>
>>
>>> What about having a configurable value for missing entries ? It should
>>> probably be configured at construction time (with a default value to
>>> Double.NaN if not specified) and never changed afterwards. In the case
>>> of sparse matrices, we should configure this value to 0.0.
>>>
>>
>> +1 to never changing the value - making it final would be best for
>> thread safety.
>>
>>
> +1
OK. I've committed the change in trunk (r730801).
thanks for the advice.
Luc
>
> Phil
>>> Luc
>>>
>>>
>>> >
>>> > Phil
>>> >
>>> > ---------------------------------------------------------------------
>>> > 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
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of
0 for key not found?
Posted by Phil Steitz <ph...@gmail.com>.
sebb wrote:
> On 02/01/2009, Luc Maisonobe <Lu...@free.fr> wrote:
>
>> Phil Steitz a écrit :
>>
>>
>>> I am still working through this class and the sparse matrix class that
>>>
>> > it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
>> > changing this would cause problems, but the current setup (returning 0
>> > for missing keys) limits usefulness of this class. I see how this is
>> > convenient for sparse matrices; but I would see NaN as a more natural
>> > return value for non-existent keys in the general case. Alternatively,
>> > I guess we could add another method get(int key, double missingReturn).
>> >
>> > Thoughts?
>>
>>
>> I had exactly the same thought while extracting the class.
>> I also prefer to use Double.NaN for numbers that have never been
>> initialized explicitly, but I also understand 0 is more logical in the
>> special case of sparse matrices.
>>
>
> +0 (I never used Math, but seems sensible)
>
>
>> What about having a configurable value for missing entries ? It should
>> probably be configured at construction time (with a default value to
>> Double.NaN if not specified) and never changed afterwards. In the case
>> of sparse matrices, we should configure this value to 0.0.
>>
>
> +1 to never changing the value - making it final would be best for
> thread safety.
>
>
+1
Phil
>> Luc
>>
>>
>> >
>> > Phil
>> >
>> > ---------------------------------------------------------------------
>> > 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
>>
>>
>>
>
> ---------------------------------------------------------------------
> 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: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of 0 for key not found?
Posted by sebb <se...@gmail.com>.
On 02/01/2009, Luc Maisonobe <Lu...@free.fr> wrote:
> Phil Steitz a écrit :
>
> > I am still working through this class and the sparse matrix class that
> > it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
> > changing this would cause problems, but the current setup (returning 0
> > for missing keys) limits usefulness of this class. I see how this is
> > convenient for sparse matrices; but I would see NaN as a more natural
> > return value for non-existent keys in the general case. Alternatively,
> > I guess we could add another method get(int key, double missingReturn).
> >
> > Thoughts?
>
>
> I had exactly the same thought while extracting the class.
> I also prefer to use Double.NaN for numbers that have never been
> initialized explicitly, but I also understand 0 is more logical in the
> special case of sparse matrices.
+0 (I never used Math, but seems sensible)
> What about having a configurable value for missing entries ? It should
> probably be configured at construction time (with a default value to
> Double.NaN if not specified) and never changed afterwards. In the case
> of sparse matrices, we should configure this value to 0.0.
+1 to never changing the value - making it final would be best for
thread safety.
>
> Luc
>
>
> >
> > Phil
> >
> > ---------------------------------------------------------------------
> > 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [math] Shoud OpenIntToDoubleHashMap get return NaN instead of
0 for key not found?
Posted by Luc Maisonobe <Lu...@free.fr>.
Phil Steitz a écrit :
> I am still working through this class and the sparse matrix class that
> it was extracted from (thanks, Ismael and Sugit!), so I am not sure if
> changing this would cause problems, but the current setup (returning 0
> for missing keys) limits usefulness of this class. I see how this is
> convenient for sparse matrices; but I would see NaN as a more natural
> return value for non-existent keys in the general case. Alternatively,
> I guess we could add another method get(int key, double missingReturn).
>
> Thoughts?
I had exactly the same thought while extracting the class.
I also prefer to use Double.NaN for numbers that have never been
initialized explicitly, but I also understand 0 is more logical in the
special case of sparse matrices.
What about having a configurable value for missing entries ? It should
probably be configured at construction time (with a default value to
Double.NaN if not specified) and never changed afterwards. In the case
of sparse matrices, we should configure this value to 0.0.
Luc
>
> Phil
>
> ---------------------------------------------------------------------
> 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