[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    Re: [math] MATH-1229
From:       Phil Steitz <phil.steitz () gmail ! com>
Date:       2015-05-30 22:00:59
Message-ID: 556A331B.7050506 () gmail ! com
[Download RAW message or body]

On 5/30/15 2:21 PM, Gilles wrote:
> On Sat, 30 May 2015 13:55:56 -0700, Phil Steitz wrote:
> > On 5/30/15 10:26 AM, erans@apache.org wrote:
> > > Repository: commons-math
> > > Updated Branches:
> > > refs/heads/master 441687e5a -> 8be87e032
> > > 
> > > 
> > > MATH-1229
> > > 
> > > Set initial capacity to input array's size in order to avoid
> > > unnecessary resizing for inputs larger than than the default
> > > capacity.
> > > 
> > > 
> > > Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
> > > Commit:
> > > http://git-wip-us.apache.org/repos/asf/commons-math/commit/8be87e03
> > > Tree:
> > > http://git-wip-us.apache.org/repos/asf/commons-math/tree/8be87e03
> > > Diff:
> > > http://git-wip-us.apache.org/repos/asf/commons-math/diff/8be87e03
> > > 
> > > Branch: refs/heads/master
> > > Commit: 8be87e032a8c05622148357f30bdca3c614a669f
> > > Parents: 441687e
> > > Author: Gilles <erans@apache.org>
> > > Authored: Sat May 30 19:23:35 2015 +0200
> > > Committer: Gilles <erans@apache.org>
> > > Committed: Sat May 30 19:23:35 2015 +0200
> > > 
> > > 
> > > ----------------------------------------------------------------------
> > > 
> > > .../org/apache/commons/math4/util/ResizableDoubleArray.java    
> > > > 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > > 
> > > ----------------------------------------------------------------------
> > > 
> > > 
> > > 
> > > 
> > > http://git-wip-us.apache.org/repos/asf/commons-math/blob/8be87e03/src/main/java/org/apache/commons/math4/util/ResizableDoubleArray.java
> > >  
> > > 
> > > ----------------------------------------------------------------------
> > > 
> > > diff --git
> > > a/src/main/java/org/apache/commons/math4/util/ResizableDoubleArray.java
> > > b/src/main/java/org/apache/commons/math4/util/ResizableDoubleArray.java
> > > 
> > > index 09fd748..f5292c4 100644
> > > ---
> > > a/src/main/java/org/apache/commons/math4/util/ResizableDoubleArray.java
> > > 
> > > +++
> > > b/src/main/java/org/apache/commons/math4/util/ResizableDoubleArray.java
> > > 
> > > @@ -179,7 +179,6 @@ public class ResizableDoubleArray implements
> > > DoubleArray, Serializable {
> > > * The input array is copied, not referenced.
> > > * Other properties take default values:
> > > * <ul>
> > > -     *  <li>{@code initialCapacity = 16}</li>
> > > *  <li>{@code expansionMode = MULTIPLICATIVE}</li>
> > > *  <li>{@code expansionFactor = 2.0}</li>
> > > *  <li>{@code contractionCriterion = 2.5}</li>
> > > @@ -189,7 +188,9 @@ public class ResizableDoubleArray implements
> > > DoubleArray, Serializable {
> > > * @since 2.2
> > > */
> > > public ResizableDoubleArray(double[] initialArray) {
> > > -        this(DEFAULT_INITIAL_CAPACITY,
> > > +        this((initialArray == null || initialArray.length == 0 ?
> > 
> > +1 for the change here.  Good catch.  But I am wondering, might it
> > be better to use
> > 
> > initialArray.length < DEFAULT_INITIAL_CAPACITY in the test above?
> 
> It would not correspond to the documentation; and in some
> hypothetical
> use-cases, it might not be expected (e.g. if instantiating many
> arrays
> with sizes < DEFAULT_INITIAL_CAPACITY).

Yeah, the documentation would have to be changed to make it clear. 
It's also not a big deal because the default expansion mode is
multiplicative, so the effect of too small initial capacity will go
away fairly quickly.  I had not thought of the (strange but
possible) example you cite.  I guess its simpler to just leave it as is.

Phil
> Your suggestion could be useful in most actual use-cases...
> 
> Gilles
> 
> > 
> > Phil
> > 
> > 
> > > +              DEFAULT_INITIAL_CAPACITY :
> > > +              initialArray.length),
> > > DEFAULT_EXPANSION_FACTOR,
> > > DEFAULT_CONTRACTION_DELTA + DEFAULT_EXPANSION_FACTOR,
> > > DEFAULT_EXPANSION_MODE,
> > > 
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > 
> > 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic