You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Arne Ploese <ap...@gmx.de> on 2013/04/09 19:56:20 UTC

[math] RealVector with visibility protected|public conflict

Hi,

in class org.apache.commons.math3.linear.RealVector there is the
embedded class Entry which is protected, but it is exposed by method
public Iterator<Entry> iterator() ...

My solution: 
1. make class Entry public
2. make class RealVector implement Iterable<RealVector<Entry>>

so one can do this:

for (RealVector.Entry e : v) {
  if (Double.isNaN(e.getValue()) || 
      Double.isInfinite(e.getValue())) {
    throw new RuntimeException("roots: inputs must not contain Inf or
NaN");
  }
}

JIRA + diff???

Arne


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


Re: [math] RealVector with visibility protected|public conflict

Posted by Gilles <gi...@harfang.homelinux.org>.
On Thu, 11 Apr 2013 16:45:42 +0200, Arne Ploese wrote:
> Am Donnerstag, den 11.04.2013, 16:08 +0200 schrieb Gilles:
>> Hello.
>>
>> >
>> > in class org.apache.commons.math3.linear.RealVector there is the
>> > embedded class Entry which is protected, but it is exposed by 
>> method
>> > public Iterator<Entry> iterator() ...
>>
>> Good catch. Thanks.
>>
>> >
>> > My solution:
>> > 1. make class Entry public
>> > 2. make class RealVector implement Iterable<RealVector<Entry>>
>> >
>> > so one can do this:
>> >
>> > for (RealVector.Entry e : v) {
>> >   if (Double.isNaN(e.getValue()) ||
>> >       Double.isInfinite(e.getValue())) {
>> >     throw new RuntimeException("roots: inputs must not contain Inf 
>> or
>> > NaN");
>> >   }
>> > }
>>
>> IMO, exposing an "Entry" is a mistake: From a user point-of-view, a
>> "RealVector" should be a collection of "[Dd]ouble".
>> IIUC, the "Entry" was meant to allow storage or iteration 
>> optimizations
>> in subclasses.
>> I think that the current "iterator()" method must be deprecated and
>> removed; in its place, there should be a
>>
>>    protected Iterator<Entry> entryIterator()
>>
>> and a new
>>
>>    public Iterator<Double> iterator()
>>
>> (that would use the above method), such that "RealVector" would
>> implement "Iterable<Double>", as is appropriate for this concept.
>>
>> Eventually, your use-case would become:
>> -----
>>    for (Double e : v) {
>>      if (e.isNaN() ||
>>          e.isInfinite()) {
>>        throw new RuntimeException("inputs must not contain Inf or 
>> NaN");
>>      }
>>    }
>> -----
> For me it would be handy to have a RealVector isNaNOrInfinite to 
> avoid
> one iteration - I mean handy not necessary.
>

There is a JIRA issue about refactoring both matrix and vector APIs.
We are probably not going to add new methods until the whole issue is 
tackled.

Gilles


>>
>> > JIRA + diff???
>>
>> A bug report mentioning the inconsistency is welcome.
>> A diff is not necessary until we agree on the way to go.
>>


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


Re: [math] RealVector with visibility protected|public conflict

Posted by Arne Ploese <ap...@gmx.de>.
Am Donnerstag, den 11.04.2013, 16:08 +0200 schrieb Gilles:
> Hello.
> 
> >
> > in class org.apache.commons.math3.linear.RealVector there is the
> > embedded class Entry which is protected, but it is exposed by method
> > public Iterator<Entry> iterator() ...
> 
> Good catch. Thanks.
> 
> >
> > My solution:
> > 1. make class Entry public
> > 2. make class RealVector implement Iterable<RealVector<Entry>>
> >
> > so one can do this:
> >
> > for (RealVector.Entry e : v) {
> >   if (Double.isNaN(e.getValue()) ||
> >       Double.isInfinite(e.getValue())) {
> >     throw new RuntimeException("roots: inputs must not contain Inf or
> > NaN");
> >   }
> > }
> 
> IMO, exposing an "Entry" is a mistake: From a user point-of-view, a
> "RealVector" should be a collection of "[Dd]ouble".
> IIUC, the "Entry" was meant to allow storage or iteration optimizations
> in subclasses.
> I think that the current "iterator()" method must be deprecated and
> removed; in its place, there should be a
> 
>    protected Iterator<Entry> entryIterator()
> 
> and a new
> 
>    public Iterator<Double> iterator()
> 
> (that would use the above method), such that "RealVector" would
> implement "Iterable<Double>", as is appropriate for this concept.
> 
> Eventually, your use-case would become:
> -----
>    for (Double e : v) {
>      if (e.isNaN() ||
>          e.isInfinite()) {
>        throw new RuntimeException("inputs must not contain Inf or NaN");
>      }
>    }
> -----
For me it would be handy to have a RealVector isNaNOrInfinite to avoid
one iteration - I mean handy not necessary.


> 
> > JIRA + diff???
> 
> A bug report mentioning the inconsistency is welcome.
> A diff is not necessary until we agree on the way to go.
> 
> 
> Thanks,
> Gilles
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 

Arne


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


Re: [math] RealVector with visibility protected|public conflict

Posted by Gilles <gi...@harfang.homelinux.org>.
Hello.

>
> in class org.apache.commons.math3.linear.RealVector there is the
> embedded class Entry which is protected, but it is exposed by method
> public Iterator<Entry> iterator() ...

Good catch. Thanks.

>
> My solution:
> 1. make class Entry public
> 2. make class RealVector implement Iterable<RealVector<Entry>>
>
> so one can do this:
>
> for (RealVector.Entry e : v) {
>   if (Double.isNaN(e.getValue()) ||
>       Double.isInfinite(e.getValue())) {
>     throw new RuntimeException("roots: inputs must not contain Inf or
> NaN");
>   }
> }

IMO, exposing an "Entry" is a mistake: From a user point-of-view, a
"RealVector" should be a collection of "[Dd]ouble".
IIUC, the "Entry" was meant to allow storage or iteration optimizations
in subclasses.
I think that the current "iterator()" method must be deprecated and
removed; in its place, there should be a

   protected Iterator<Entry> entryIterator()

and a new

   public Iterator<Double> iterator()

(that would use the above method), such that "RealVector" would
implement "Iterable<Double>", as is appropriate for this concept.

Eventually, your use-case would become:
-----
   for (Double e : v) {
     if (e.isNaN() ||
         e.isInfinite()) {
       throw new RuntimeException("inputs must not contain Inf or NaN");
     }
   }
-----

> JIRA + diff???

A bug report mentioning the inconsistency is welcome.
A diff is not necessary until we agree on the way to go.


Thanks,
Gilles


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