commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: svn commit: r1517203 [2/2] - in /commons/proper/math/trunk/src: changes/ main/java/org/apache/commons/math3/analysis/differentiation/ main/java/org/apache/commons/math3/analysis/interpolation/ main/java/org/apache/commons/math3/analysis/polynomials/ ma...
Date Sun, 25 Aug 2013 16:03:56 GMT
On 8/25/13 7:47 AM, Gilles wrote:
> Hi.
>
>> [...]
>> +
>> +    /**
>> +     * Verifies that the iterator generates a lexicographically
>> +     * increasing sequence of b(n,k) arrays, each having length k
>> +     * and each array itself increasing.
>> +     *
>> +     * Note: the lexicographic order check only works for n < 10.
>
> What about not using a fixed base (cf. below)?

Thanks for the review!

Yes, I think below would work.  The key is the base, as you note. 
Or being less lazy and just actually directly implementing
lexicographic order check.  I did not see the need to test with n >
10; but I would be fine with the change below to allow it.

Phil
>
>> +     *
>> +     * @param iterator
>> +     * @param n size of universe
>> +     * @param k size of subsets
>> +     */
>> +    private void checkIterator(Iterator<int[]> iterator, int n,
>> int k) {
>> +        long lastLex = -1;
>> +        long length = 0;
>> +        while (iterator.hasNext()) {
>> +            final int[] iterate = iterator.next();
>> +            Assert.assertEquals(k, iterate.length);
>> +            final long curLex = lexNorm(iterate);
>                                     ^^^^^^^^^^^^^^^
> Replace with
>    final long curLex = lexNorm(iterate, n);
>
>> +            Assert.assertTrue(curLex > lastLex);
>> +            lastLex = curLex;
>> +            length++;
>> +            for (int i = 1; i < iterate.length; i++) {
>> +                Assert.assertTrue(iterate[i] > iterate[i - 1]);
>> +            }
>> +        }
>
>> [...]
>
>> +
>> +    /**
>> +     * Returns the value represented by the digits in the input
>> array in reverse order.
>> +     * For example [3,2,1] returns 123.
>> +     *
>> +     * @param iterate input array
>> +     * @return lexicographic norm
>> +     */
>> +    private long lexNorm(int[] iterate) {
>                                        ^^^
> Replace with
>   private long lexNorm(int[] iterate, int n)
>
>> +        long ret = 0;
>> +        for (int i = iterate.length - 1; i >= 0; i--) {
>> +            ret += iterate[i] * ArithmeticUtils.pow(10l, (long) i);
>                                                       ^^^^^^^^^^^^^^
> Replace with
>    ret += iterate[i] * ArithmeticUtils.pow(n, (long) i);
>
>> +        }
>> +        return ret;
>> +    }
>> +}
>
>> [...]
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message