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, [email protected] 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 <[email protected]>
>>> Authored: Sat May 30 19:23:35 2015 +0200
>>> Committer: Gilles <[email protected]>
>>> 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: [email protected]
>> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to