sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1801338 - in /sis/branches/JDK8/core/sis-utility/src: main/java/org/apache/sis/math/ main/java/org/apache/sis/util/resources/ test/java/org/apache/sis/math/
Date Sat, 08 Jul 2017 23:07:28 GMT
Author: desruisseaux
Date: Sat Jul  8 23:07:27 2017
New Revision: 1801338

URL: http://svn.apache.org/viewvc?rev=1801338&view=rev
Log:
More efficient compression of vectors when requested.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/PackedVector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/SequenceVector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
[UTF-8] Sat Jul  8 23:07:27 2017
@@ -80,92 +80,77 @@ abstract class ArrayVector<E extends Num
     }
 
     /**
-     * Returns a vector with the same data than this vector but encoded in a more compact
way,
-     * or {@code this} if this method can not do better than current {@code Vector} instance.
-     */
-    @Override
-    public final Vector compress(final double tolerance) {
-        final Vector vec = super.compress(tolerance);
-        if (vec == this && !isEmpty()) {
-            if (isInteger()) {
-                /*
-                 * For integer values, verify if we can pack the data into a smaller type.
-                 * We will use a vector backed by IntegerList in order to use only the amount
of bits needed,
-                 * unless that amount is exactly the number of bits of a primitive type (8,
16, 32 or 64) in
-                 * which case using one of the specialized class in this ArrayVector is more
performant.
-                 */
-                final NumberRange<?> range = range();
-                if (range != null && !range.isEmpty() && range.getMinDouble()
>= Long.MIN_VALUE
-                                                      && range.getMaxDouble() <=
Long.MAX_VALUE)
-                {
-                    final long min      = range.getMinValue().longValue();
-                    final long max      = range.getMaxValue().longValue();
-                    final long delta    = Math.subtractExact(max, min);
-                    final int  bitCount = Long.SIZE - Long.numberOfLeadingZeros(delta);
-                    if (bitCount != Numbers.primitiveBitCount(getElementType())) {
-                        switch (bitCount) {
-                            case Byte.SIZE: {
-                                final boolean isSigned = (min >= Byte.MIN_VALUE &&
max <= Byte.MAX_VALUE);
-                                if (isSigned || (min >= 0 && max <= 0xFF))
{
-                                    final byte[] array = new byte[size()];
-                                    for (int i=0; i < array.length; i++) {
-                                        array[i] = (byte) intValue(i);
-                                    }
-                                    return isSigned ? new Bytes(array) : new UnsignedBytes(array);
-                                }
-                                break;
-                            }
-                            case Short.SIZE: {
-                                final boolean isSigned = (min >= Short.MIN_VALUE &&
max <= Short.MAX_VALUE);
-                                if (isSigned || (min >= 0 && max <= 0xFFFF))
{
-                                    final short[] array = new short[size()];
-                                    for (int i=0; i < array.length; i++) {
-                                        array[i] = (short) intValue(i);
-                                    }
-                                    return isSigned ? new Shorts(array) : new UnsignedShorts(array);
-                                }
-                                break;
-                            }
-                            case Integer.SIZE: {
-                                final boolean isSigned = (min >= Integer.MIN_VALUE &&
max <= Integer.MAX_VALUE);
-                                if (isSigned || (min >= 0 && max <= 0xFFFFFFFF))
{
-                                    final int[] array = new int[size()];
-                                    for (int i=0; i < array.length; i++) {
-                                        array[i] = (int) longValue(i);
-                                    }
-                                    return isSigned ? new Integers(array) : new UnsignedIntegers(array);
-                                }
-                                break;
-                            }
-                            // The Long.SIZE case should never happen because of the 'bitCount'
check before the switch.
-                        }
-                        return new PackedVector(this, min, Math.toIntExact(delta));
-                    }
-                }
-            } else if (!Float.class.equals(getElementType())) {
-                /*
-                 * For floating point types, verify if values are equivalent to 'float' values.
-                 * There is two different ways to pad extra fraction digits in 'double' values:
-                 * with zero fraction digits in base 2 representation (the standard Java
cast),
-                 * or with zero fraction digits in base 10 representation.
-                 */
-                final int length = size();
-                int i = 0;
-                double v;
-                do if (i >= length) {
-                    return new Floats(floatValues());
-                } while (!(Math.abs((v = doubleValue(i++)) - (float) v) > tolerance));
   // Use '!' for accepting NaN.
-                /*
-                 * Same try than above loop, but now using base 10 representation.
-                 * This is a more costly computation.
-                 */
-                i = 0;
-                do if (i >= length) {
-                    return new Decimal(floatValues());
-                } while (!(Math.abs((v = doubleValue(i++)) - DecimalFunctions.floatToDouble((float)
v)) > tolerance));
+     * Returns a vector with the same data than the given vector but encoded in a more compact
way,
+     * or {@code null} if this method can not do better than the given {@code Vector} instance.
+     * This method shall be invoked only for vector of integer values (this is not verified).
+     */
+    static Vector compress(final Vector source, final long min, final long max) {
+        boolean isSigned = (min >= Byte.MIN_VALUE && max <= Byte.MAX_VALUE);
+        if (isSigned || (min >= 0 && max <= 0xFF)) {
+            if (source instanceof Bytes) return null;
+            final byte[] array = new byte[source.size()];
+            for (int i=0; i < array.length; i++) {
+                array[i] = (byte) source.intValue(i);
+            }
+            return isSigned ? new Bytes(array) : new UnsignedBytes(array);
+        }
+        isSigned = (min >= Short.MIN_VALUE && max <= Short.MAX_VALUE);
+        if (isSigned || (min >= 0 && max <= 0xFFFF)) {
+            if (source instanceof Shorts) return null;
+            final short[] array = new short[source.size()];
+            for (int i=0; i < array.length; i++) {
+                array[i] = (short) source.intValue(i);
+            }
+            return isSigned ? new Shorts(array) : new UnsignedShorts(array);
+        }
+        isSigned = (min >= Integer.MIN_VALUE && max <= Integer.MAX_VALUE);
+        if (isSigned || (min >= 0 && max <= 0xFFFFFFFF)) {
+            if (source instanceof Integers) return null;
+            final int[] array = new int[source.size()];
+            for (int i=0; i < array.length; i++) {
+                array[i] = (int) source.longValue(i);
             }
+            return isSigned ? new Integers(array) : new UnsignedIntegers(array);
         }
-        return vec;
+        if (!(source instanceof Longs) && !(source instanceof Floats) &&
!(source instanceof Doubles)) {
+            final long[] array = new long[source.size()];
+            for (int i=0; i < array.length; i++) {
+                array[i] = source.longValue(i);
+            }
+            return new Longs(array);
+        }
+        return null;
+    }
+
+    /**
+     * Returns a vector with the same data than the given vector but encoded in a more compact
way,
+     * or {@code null} if this method can not do better than the given {@code Vector} instance.
+     * This method shall be invoked only for vector of floating point values (this is not
verified).
+     */
+    static Vector compress(final Vector source, final double tolerance) {
+        if (!Float.class.equals(source.getElementType())) {
+            /*
+             * For floating point types, verify if values are equivalent to 'float' values.
+             * There is two different ways to pad extra fraction digits in 'double' values:
+             * with zero fraction digits in base 2 representation (the standard Java cast),
+             * or with zero fraction digits in base 10 representation.
+             */
+            final int length = source.size();
+            int i = 0;
+            double v;
+            do if (i >= length) {
+                return new Floats(source.floatValues());
+            } while (!(Math.abs((v = source.doubleValue(i++)) - (float) v) > tolerance));
   // Use '!' for accepting NaN.
+            /*
+             * Same try than above loop, but now using base 10 representation.
+             * This is a more costly computation.
+             */
+            i = 0;
+            do if (i >= length) {
+                return new Decimal(source.floatValues());
+            } while (!(Math.abs((v = source.doubleValue(i++)) - DecimalFunctions.floatToDouble((float)
v)) > tolerance));
+        }
+        return null;
     }
 
     /**
@@ -411,6 +396,11 @@ abstract class ArrayVector<E extends Num
             return Long.class;
         }
 
+        /** Values in this vector are guaranteed to be integers. */
+        @Override public final boolean isInteger() {
+            return true;
+        }
+
         /** Returns the string representation at the given index. */
         @Override public String stringValue(final int index) {
             return Long.toString(array[index]);
@@ -492,6 +482,11 @@ abstract class ArrayVector<E extends Num
             return Integer.class;
         }
 
+        /** Values in this vector are guaranteed to be integers. */
+        @Override public final boolean isInteger() {
+            return true;
+        }
+
         /** Returns the string representation at the given index. */
         @Override public String stringValue(final int index) {
             return Integer.toString(array[index]);
@@ -577,6 +572,11 @@ abstract class ArrayVector<E extends Num
             return Short.class;
         }
 
+        /** Values in this vector are guaranteed to be integers. */
+        @Override public final boolean isInteger() {
+            return true;
+        }
+
         /** Returns the string representation at the given index. */
         @Override public String stringValue(final int index) {
             return Short.toString(array[index]);
@@ -637,6 +637,11 @@ abstract class ArrayVector<E extends Num
             return Byte.class;
         }
 
+        /** Values in this vector are guaranteed to be integers. */
+        @Override public final boolean isInteger() {
+            return true;
+        }
+
         /** Returns the string representation at the given index. */
         @Override public String stringValue(final int index) {
             return Byte.toString(array[index]);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/PackedVector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/PackedVector.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/PackedVector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/PackedVector.java
[UTF-8] Sat Jul  8 23:07:27 2017
@@ -18,6 +18,7 @@ package org.apache.sis.math;
 
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.collection.IntegerList;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -33,7 +34,13 @@ final class PackedVector extends ArrayVe
     /**
      * For cross-version compatibility.
      */
-    private static final long serialVersionUID = 2025113345434607526L;
+    private static final long serialVersionUID = 5097586732924434042L;
+
+    /**
+     * Minimal length for creating a packed vector.
+     * This is an arbitrary value that may change in any future version.
+     */
+    static final int MINIMAL_SIZE = 8;
 
     /**
      * The compressed list of integer values. This list can store values from 0 to {@code
delta} inclusive.
@@ -41,6 +48,11 @@ final class PackedVector extends ArrayVe
     private final IntegerList data;
 
     /**
+     * The value by which to multiply the {@linkplain #data} before to add the {@linkplain
#offset}.
+     */
+    private final long increment;
+
+    /**
      * The offset to add to the {@link #data} in order to get the values to return.
      */
     private final long offset;
@@ -48,20 +60,84 @@ final class PackedVector extends ArrayVe
     /**
      * Creates a new compressed vector initialized to a copy of the data provided by the
given vector.
      *
-     * @param  source  the vector to copy.
-     * @param  offset  the minimal value in the source vector.
-     * @param  delta   the maximal value in the source vector minus {@code offset}.
-     */
-    PackedVector(final Vector source, final long offset, final int delta) {
-        this.offset = offset;
+     * @param  source     the vector to copy.
+     * @param  increment  the common divisor of all (sample minus offset) values.
+     * @param  offset     the minimal value in the source vector.
+     * @param  delta      the maximal value in the source vector minus {@code offset} divided
by {@code increment}.
+     */
+    private PackedVector(final Vector source, final long increment, final long offset, final
int delta) {
+        this.increment = increment;
+        this.offset    = offset;
         final int length = source.size();
         data = new IntegerList(length, delta, true);
         for (int i=0; i<length; i++) {
-            data.setInt(i, Math.toIntExact(source.longValue(i) - offset));
+            data.setInt(i, Math.toIntExact((source.longValue(i) - offset) / increment));
         }
     }
 
     /**
+     * Creates a new compressed vector initialized to a copy of the data provided by the
given vector.
+     * All values in the given vector shall be assignable to the {@code long} type (this
is not verified).
+     *
+     * @param  source  the vector to copy.
+     * @param  min     the minimal value in the given vector, inclusive.
+     * @param  max     the maximal value in the given vector, inclusive.
+     * @return the compressed vector, or {@code null} if the vector can not or should not
be compressed.
+     */
+    static PackedVector compress(final Vector source, final long min, final long max) {
+        long delta = max - min;
+        if (delta > 0) {                                    // Negative if (max - min)
overflow.
+            long inc = delta;
+            final int length = source.size();
+            if (length >= MINIMAL_SIZE) {
+                for (int i=0; i<length; i++) {
+                    long t = source.longValue(i) - min;
+                    if (t < 0) return null;                 // May happen if the given
'min' value is wrong.
+                    if ((t % inc) != 0) {
+                        do {
+                            final long r = (inc % t);       // Search for greatest common
divisor with Euclid's algorithm.
+                            inc = t;
+                            t = r;
+                        } while (t != 0);
+                        if (inc == 1) {
+                            /*
+                             * If we reach this point, the increment is of no use for compressing
data.
+                             * If in addition the minimal number of bits required for storing
all values:
+                             *
+                             *     numBits = Long.SIZE - Long.numberOfLeadingZeros(delta);
+                             *
+                             * is equal to the number of bits of a primitive type (byte,
short, int or long)
+                             * and all values are in the range of that primitive type, then
there is nothing
+                             * to win compared to an array of that primitive type.
+                             */
+                            final long high = Long.highestOneBit(delta);
+                            if ((high & ((1L << (Byte   .SIZE - 1)) |
+                                         (1L << (Short  .SIZE - 1)) |
+                                         (1L << (Integer.SIZE - 1)) |
+                                         (1L << (Long   .SIZE - 1)))) != 0)
+                            {
+                                long limit = high - 1;                  // Maximal value
of signed integers.
+                                if (min >= 0) {
+                                    limit |= high;                      // Maximal value
of unsigned integers.
+                                    if (limit < 0) return null;         // Overflow the
'long' primitve type.
+                                }
+                                if (max <= limit && min >= ~limit) {    //
Really tild (~), not minus (-).
+                                    return null;                        // All values in
range of primitive type.
+                                }
+                            }
+                            break;                                      // No need to check
other values.
+                        }
+                    }
+                }
+                delta /= inc;
+                if (delta > Integer.MAX_VALUE) return null;
+                return new PackedVector(source, inc, min, (int) delta);
+            }
+        }
+        return null;
+    }
+
+    /**
      * Type of elements fixed to {@code Long} even if the actual storage used by this class
is more compact.
      * The reason for the {@code Long} type is that this class can return any value in the
{@code Long} range,
      * because of the {@link #offset}.
@@ -100,7 +176,7 @@ final class PackedVector extends ArrayVe
      */
     @Override
     public long longValue(final int index) {
-        return data.getInt(index) + offset;
+        return data.getInt(index) * increment + offset;
     }
 
     /**
@@ -125,8 +201,19 @@ final class PackedVector extends ArrayVe
     @Override
     public Number set(final int index, final Number value) {
         verifyType(value.getClass(), Numbers.LONG);
-        final Number old = get(index);
-        data.setInt(index, Math.toIntExact(Math.subtractExact(value.longValue(), offset)));
-        return old;
+        long v = value.longValue();
+        if (v >= offset) {
+            v -= offset;
+            if ((v % increment) == 0) {
+                v /= increment;
+                if (v <= data.maximalValue()) {
+                    final Number old = get(index);
+                    data.setInt(index, (int) v);
+                    modCount++;
+                    return old;
+                }
+            }
+        }
+        throw new IllegalArgumentException(Errors.format(Errors.Keys.CanNotStoreInVector_1,
value));
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/SequenceVector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/SequenceVector.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/SequenceVector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/SequenceVector.java
[UTF-8] Sat Jul  8 23:07:27 2017
@@ -90,7 +90,7 @@ abstract class SequenceVector extends Ve
      */
     @Override
     public final Number set(final int index, final Number value) {
-        throw new UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableObject_1,
"Vector"));
+        throw new UnsupportedOperationException(Errors.format(Errors.Keys.CanNotStoreInVector_1,
value));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java [UTF-8]
Sat Jul  8 23:07:27 2017
@@ -447,7 +447,7 @@ public abstract class Vector extends Abs
      * @throws UnsupportedOperationException if this vector is read-only.
      * @throws IndexOutOfBoundsException if the given index is out of bounds.
      * @throws NumberFormatException if the previous value was stored as a {@code String}
and can not be parsed.
-     * @throws ArithmeticException if this vector uses some {@linkplain #compress(double)
compression} technic
+     * @throws IllegalArgumentException if this vector uses some {@linkplain #compress(double)
compression} technic
      *         and the given value is out of range for that compression.
      */
     @Override
@@ -985,8 +985,8 @@ public abstract class Vector extends Abs
      *
      * <div class="section">When to use</div>
      * It is usually not worth to compress small arrays. Performance-critical arrays may
not be compressed neither.
-     * This method is best suited for arrays that may potentially be large and for which
the cost of reading that
-     * array is small compared to the calculation performed with the values.
+     * This method is best suited for vectors that may potentially be large and for which
the cost of fetching
+     * values in that vector is small compared to the calculation performed with the values.
      *
      * @param  tolerance  maximal difference allowed between original and compressed vectors
(can be zero).
      * @return a more compact vector with the same data than this vector, or {@code this}.
@@ -1003,11 +1003,38 @@ public abstract class Vector extends Abs
          * returns null if the array contains NaN. Note that for array of integers, 'isNaN(int)'
is very
          * efficient and the loop will stop immediately after the first iteration.
          */
-        for (int i=0; i<length; i++) {
-            if (!isNaN(i)) return this;
+        int i = 0;
+        do if (i >= length) {
+            final Double NaN = Numerics.valueOf(Double.NaN);
+            return new SequenceVector.Doubles(getElementType(), NaN, NaN, length);
+        } while (isNaN(i++));
+        /*
+         * Try to copy the values in a more compact format.
+         * We will use a vector backed by IntegerList in order to use only the amount of
bits needed,
+         * unless that amount is exactly the number of bits of a primitive type (8, 16, 32
or 64) in
+         * which case using one of the specialized classes in this ArrayVector is more performant.
+         */
+        final NumberRange<?> range = range();
+        if (range != null && !range.isEmpty()) {
+            final Number min = range.getMinValue();
+            final Number max = range.getMaxValue();
+            final boolean isInteger = (min.doubleValue() >= Long.MIN_VALUE &&
+                                       max.doubleValue() <= Long.MAX_VALUE &&
+                                       isInteger());                                // May
scan the vector.
+            Vector vec;
+            if (isInteger) {
+                vec = PackedVector.compress(this, min.longValue(), max.longValue());
+                if (vec == null) {
+                    vec = ArrayVector.compress(this, min.longValue(), max.longValue());
+                }
+            } else {
+                vec = ArrayVector.compress(this, tolerance);
+            }
+            if (vec != null) {
+                return vec;
+            }
         }
-        final Double NaN = Numerics.valueOf(Double.NaN);
-        return new SequenceVector.Doubles(getElementType(), NaN, NaN, length);
+        return this;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Sat Jul  8 23:07:27 2017
@@ -151,6 +151,11 @@ public final class Errors extends Indexe
         public static final short CanNotSetPropertyValue_1 = 15;
 
         /**
+         * Can not store the {0} value in this vector.
+         */
+        public static final short CanNotStoreInVector_1 = 175;
+
+        /**
          * Can not transform envelope.
          */
         public static final short CanNotTransformEnvelope = 16;

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Sat Jul  8 23:07:27 2017
@@ -41,6 +41,7 @@ CanNotReadPropertyInFile_2        = Can
 CanNotRepresentInFormat_2         = Can not represent \u201c{1}\u201d in a strictly standard-compliant
{0} format.
 CanNotSetParameterValue_1         = Can not set a value for parameter \u201c{0}\u201d.
 CanNotSetPropertyValue_1          = Can not set a value for property \u201c{0}\u201d.
+CanNotStoreInVector_1             = Can not store the {0} value in this vector.
 CanNotTransformEnvelope           = Can not transform envelope.
 CanNotWriteFile_2                 = Can not write \u201c{1}\u201d as a file in the {0} format.
 CircularReference                 = Circular reference.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Sat Jul  8 23:07:27 2017
@@ -38,6 +38,7 @@ CanNotReadPropertyInFile_2        = Ne p
 CanNotRepresentInFormat_2         = Ne peut pas repr\u00e9senter \u00ab\u202f{1}\u202f\u00bb
dans un format {0} strictement conforme.
 CanNotSetParameterValue_1         = Ne peut pas d\u00e9finir une valeur pour le param\u00e8tre
\u00ab\u202f{0}\u202f\u00bb.
 CanNotSetPropertyValue_1          = Ne peut pas d\u00e9finir une valeur pour la propri\u00e9t\u00e9
\u00ab\u202f{0}\u202f\u00bb.
+CanNotStoreInVector_1             = Ne peut pas stocker la valeur {0} dans ce vecteur.
 CanNotTransformEnvelope           = Ne peut pas transformer l\u2019enveloppe.
 CanNotWriteFile_2                 = Ne peut pas \u00e9crire \u00ab\u202f{1}\u202f\u00bb comme
un fichier au format {0}.
 CircularReference                 = R\u00e9f\u00e9rence circulaire.

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java?rev=1801338&r1=1801337&r2=1801338&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/math/VectorTest.java [UTF-8]
Sat Jul  8 23:07:27 2017
@@ -370,14 +370,16 @@ public final strictfp class VectorTest e
          */
         vec =  Vector.create(new double[] {30, 120, -50, -120}, false);
         assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
         assertEquals("elementType", Byte.class, compressed.getElementType());
         assertFalse("isUnsigned()", compressed.isUnsigned());
         assertContentEquals(vec, compressed);
         /*
-         * Values that can be compressed as unsigned signed bytes.
+         * Values that can be compressed as unsigned bytes.
          */
         vec =  Vector.create(new float[] {30, 120, 250, 1}, false);
         assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
         assertEquals("elementType", Byte.class, compressed.getElementType());
         assertTrue("isUnsigned()", compressed.isUnsigned());
         assertContentEquals(vec, compressed);
@@ -386,6 +388,7 @@ public final strictfp class VectorTest e
          */
         vec =  Vector.create(new long[] {32000, 120, -25000, 14}, false);
         assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
         assertEquals("elementType", Short.class, compressed.getElementType());
         assertFalse("isUnsigned()", compressed.isUnsigned());
         assertContentEquals(vec, compressed);
@@ -394,14 +397,36 @@ public final strictfp class VectorTest e
          */
         vec =  Vector.create(new float[] {3, 60000, 25, 4}, false);
         assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
         assertEquals("elementType", Short.class, compressed.getElementType());
         assertTrue("isUnsigned()", compressed.isUnsigned());
         assertContentEquals(vec, compressed);
         /*
          * Values that can be compressed in a PackedVector.
          * Values below require less bits than the 'byte' type.
+         * Note that we need at least PackedVector.MINIMAL_SIZE data for enabling this test.
          */
-        vec =  Vector.create(new double[] {30, 27, 93, 72, -8}, false);
+        vec =  Vector.create(new double[] {30, 27, 93, 72, -8, -3, 12, 4, 29, -5}, false);
+        assertTrue(vec.size() >= PackedVector.MINIMAL_SIZE);
+        assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", PackedVector.class, compressed);
+        assertContentEquals(vec, compressed);
+        /*
+         * Vector that could be compressed in a PackedVector, but without advantage
+         * because the number of bits required for storing the values is exactly 8.
+         */
+        vec =  Vector.create(new double[] {200, 100, 20, 80, 180, 10, 11, 12}, false);
+        assertTrue(vec.size() >= PackedVector.MINIMAL_SIZE);
+        assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
+        assertEquals("elementType", Byte.class, compressed.getElementType());
+        assertTrue("isUnsigned()", compressed.isUnsigned());
+        assertContentEquals(vec, compressed);
+        /*
+         * Vector that can be compressed in a PackedVector as bytes with a factor of 20.
+         */
+        vec =  Vector.create(new double[] {200, 100, 20, 80, 180, 2000, 500, 120}, false);
+        assertTrue(vec.size() >= PackedVector.MINIMAL_SIZE);
         assertNotSame(vec, compressed = vec.compress(0));
         assertInstanceOf("vector.compress(0)", PackedVector.class, compressed);
         assertContentEquals(vec, compressed);
@@ -410,6 +435,7 @@ public final strictfp class VectorTest e
          */
         vec =  Vector.create(new double[] {3.10, 60.59, -25.32, 4.78}, false);
         assertNotSame(vec, compressed = vec.compress(0));
+        assertInstanceOf("vector.compress(0)", ArrayVector.class, compressed);
         assertEquals("elementType", Float.class, compressed.getElementType());
         assertFalse("isUnsigned()", compressed.isUnsigned());
         assertContentEquals(vec, compressed);



Mime
View raw message