Search in sources :

Example 1 with DoubleValue

use of org.apache.flink.types.DoubleValue in project flink by apache.

the class GraphKeyTypeTransformTest method testFromDoubleValue.

@Test
public void testFromDoubleValue() throws Exception {
    TranslateFunction<DoubleValue, LongValueWithProperHashCode> translator = new DoubleValueToLongValueWithProperHashCode();
    Assert.assertEquals(new LongValueWithProperHashCode(0L), translator.translate(new DoubleValue(Double.longBitsToDouble(0L)), longValueWithProperHashCode));
    Assert.assertEquals(new LongValueWithProperHashCode(Long.MIN_VALUE), translator.translate(new DoubleValue(Double.longBitsToDouble(Long.MIN_VALUE)), longValueWithProperHashCode));
    Assert.assertEquals(new LongValueWithProperHashCode(Long.MAX_VALUE), translator.translate(new DoubleValue(Double.longBitsToDouble(Long.MAX_VALUE)), longValueWithProperHashCode));
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue) LongValueToDoubleValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToDoubleValue) DoubleValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleValueToLongValueWithProperHashCode) UnsignedShortValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortValueToLongValueWithProperHashCode) DoubleToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleToLongValueWithProperHashCode) UnsignedByteValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteValueToLongValueWithProperHashCode) UnsignedIntToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedIntToLongValueWithProperHashCode) DoubleValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleValueToLongValueWithProperHashCode) StringToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringToLongValueWithProperHashCode) UnsignedFloatToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatToLongValueWithProperHashCode) LongValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToLongValueWithProperHashCode) StringValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringValueToLongValueWithProperHashCode) UnsignedByteToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteToLongValueWithProperHashCode) UnsignedFloatValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatValueToLongValueWithProperHashCode) UnsignedShortToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortToLongValueWithProperHashCode) Test(org.junit.Test)

Example 2 with DoubleValue

use of org.apache.flink.types.DoubleValue in project flink by apache.

the class DoubleValueSerializerTest method getTestData.

@Override
protected DoubleValue[] getTestData() {
    Random rnd = new Random(874597969123412341L);
    Double rndDouble = rnd.nextDouble() * Double.MAX_VALUE;
    return new DoubleValue[] { new DoubleValue(0), new DoubleValue(1), new DoubleValue(-1), new DoubleValue(Double.MAX_VALUE), new DoubleValue(Double.MIN_VALUE), new DoubleValue(rndDouble), new DoubleValue(-rndDouble), new DoubleValue(Double.NaN), new DoubleValue(Double.NEGATIVE_INFINITY), new DoubleValue(Double.POSITIVE_INFINITY) };
}
Also used : Random(java.util.Random) DoubleValue(org.apache.flink.types.DoubleValue)

Example 3 with DoubleValue

use of org.apache.flink.types.DoubleValue in project flink by apache.

the class DoubleValueArrayComparatorTest method getSortedTestData.

@Override
protected DoubleValueArray[] getSortedTestData() {
    DoubleValueArray lva0 = new DoubleValueArray();
    DoubleValueArray lva1 = new DoubleValueArray();
    lva1.add(new DoubleValue(5));
    DoubleValueArray lva2 = new DoubleValueArray();
    lva2.add(new DoubleValue(5));
    lva2.add(new DoubleValue(10));
    return new DoubleValueArray[] { lva0, lva1 };
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue)

Example 4 with DoubleValue

use of org.apache.flink.types.DoubleValue in project flink by apache.

the class DoubleValueArrayTest method testUnboundedArray.

@Test
public void testUnboundedArray() {
    int count = 4096;
    ValueArray<DoubleValue> lva = new DoubleValueArray();
    // add several elements
    for (int i = 0; i < count; i++) {
        assertFalse(lva.isFull());
        assertEquals(i, lva.size());
        assertTrue(lva.add(new DoubleValue(i)));
        assertEquals(i + 1, lva.size());
    }
    // array never fills
    assertFalse(lva.isFull());
    assertEquals(count, lva.size());
    // verify the array values
    int idx = 0;
    for (DoubleValue lv : lva) {
        assertEquals(idx++, lv.getValue(), 0.000001);
    }
    // add element past end of array
    assertTrue(lva.add(new DoubleValue(count)));
    assertTrue(lva.addAll(lva));
    // test copy
    assertEquals(lva, lva.copy());
    // test copyTo
    DoubleValueArray lvaTo = new DoubleValueArray();
    lva.copyTo(lvaTo);
    assertEquals(lva, lvaTo);
    // test mark/reset
    int size = lva.size();
    lva.mark();
    assertTrue(lva.add(new DoubleValue()));
    assertEquals(size + 1, lva.size());
    lva.reset();
    assertEquals(size, lva.size());
    // test clear
    lva.clear();
    assertEquals(0, lva.size());
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue) Test(org.junit.Test)

Example 5 with DoubleValue

use of org.apache.flink.types.DoubleValue in project flink by apache.

the class DoubleValueArraySerializerTest method getTestData.

@Override
protected DoubleValueArray[] getTestData() {
    int defaultElements = DoubleValueArray.DEFAULT_CAPACITY_IN_BYTES / DoubleValueArray.ELEMENT_LENGTH_IN_BYTES;
    Random rnd = new Random(874597969123412341L);
    int rndLong = rnd.nextInt();
    DoubleValueArray lva0 = new DoubleValueArray();
    DoubleValueArray lva1 = new DoubleValueArray();
    lva1.addAll(lva0);
    lva1.add(new DoubleValue(0));
    DoubleValueArray lva2 = new DoubleValueArray();
    lva2.addAll(lva1);
    lva2.add(new DoubleValue(1));
    DoubleValueArray lva3 = new DoubleValueArray();
    lva3.addAll(lva2);
    lva3.add(new DoubleValue(-1));
    DoubleValueArray lva4 = new DoubleValueArray();
    lva4.addAll(lva3);
    lva4.add(new DoubleValue(Double.MAX_VALUE));
    DoubleValueArray lva5 = new DoubleValueArray();
    lva5.addAll(lva4);
    lva5.add(new DoubleValue(Double.MIN_VALUE));
    DoubleValueArray lva6 = new DoubleValueArray();
    lva6.addAll(lva5);
    lva6.add(new DoubleValue(rndLong));
    DoubleValueArray lva7 = new DoubleValueArray();
    lva7.addAll(lva6);
    lva7.add(new DoubleValue(-rndLong));
    DoubleValueArray lva8 = new DoubleValueArray();
    lva8.addAll(lva7);
    for (int i = 0; i < 1.5 * defaultElements; i++) {
        lva8.add(new DoubleValue(i));
    }
    lva8.addAll(lva8);
    return new DoubleValueArray[] { lva0, lva1, lva2, lva3, lva4, lva5, lva6, lva7, lva8 };
}
Also used : Random(java.util.Random) DoubleValue(org.apache.flink.types.DoubleValue)

Aggregations

DoubleValue (org.apache.flink.types.DoubleValue)20 Test (org.junit.Test)12 LongValue (org.apache.flink.types.LongValue)5 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 EitherTypeInfo (org.apache.flink.api.java.typeutils.EitherTypeInfo)4 Random (java.util.Random)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 StringValue (org.apache.flink.types.StringValue)3 DoubleSumAggregator (org.apache.flink.api.common.aggregators.DoubleSumAggregator)2 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 LongValueToDoubleValue (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToDoubleValue)2 Either (org.apache.flink.types.Either)2 Left (org.apache.flink.types.Either.Left)2 Right (org.apache.flink.types.Either.Right)2 IntValue (org.apache.flink.types.IntValue)2 ArrayList (java.util.ArrayList)1 TestInputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView)1 TestOutputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView)1 DoubleValueSerializer (org.apache.flink.api.common.typeutils.base.DoubleValueSerializer)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1