org.apache.flink.types.FloatValue Java Examples
The following examples show how to use
org.apache.flink.types.FloatValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValueArrayFactory.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Produce a {@code ValueArray} for the given {@code Value} type with the * given bounded size. * * @param cls {@code Value} class * @param bytes limit the array to the given number of bytes * @return {@code ValueArray} for given {@code Value} class */ @SuppressWarnings("unchecked") public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls, int bytes) { if (ByteValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ByteValueArray(bytes); } else if (CharValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new CharValueArray(bytes); } else if (DoubleValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new DoubleValueArray(bytes); } else if (FloatValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new FloatValueArray(bytes); } else if (IntValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new IntValueArray(bytes); } else if (LongValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new LongValueArray(bytes); } else if (NullValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new NullValueArray(bytes); } else if (ShortValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ShortValueArray(bytes); } else if (StringValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new StringValueArray(bytes); } else { throw new IllegalArgumentException("Unable to create bounded ValueArray for type " + cls); } }
Example #2
Source File: AdamicAdar.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Tuple4<IntValue, T, T, FloatValue>> out) throws Exception { int groupCount = 0; int groupSpans = 1; groupSpansValue.setValue(groupSpans); for (Tuple3<T, T, FloatValue> edge : values) { output.f1 = edge.f0; output.f2 = edge.f1; output.f3 = edge.f2; out.collect(output); if (++groupCount == GROUP_SIZE) { groupCount = 0; groupSpansValue.setValue(++groupSpans); } } }
Example #3
Source File: FloatValueComparatorTest.java From flink with Apache License 2.0 | 6 votes |
@Override protected FloatValue[] getSortedTestData() { Random rnd = new Random(874597969123412338L); float rndFloat = rnd.nextFloat(); if (rndFloat < 0) { rndFloat = -rndFloat; } if (rndFloat == Float.MAX_VALUE) { rndFloat -= 3; } if (rndFloat <= 2) { rndFloat += 3; } return new FloatValue[]{ new FloatValue(-rndFloat), new FloatValue(-1.0F), new FloatValue(0.0F), new FloatValue(2.0F), new FloatValue(rndFloat), new FloatValue(Float.MAX_VALUE)}; }
Example #4
Source File: ValueArrayFactory.java From flink with Apache License 2.0 | 6 votes |
/** * Produce a {@code ValueArray} for the given {@code Value} type with the * given bounded size. * * @param cls {@code Value} class * @param bytes limit the array to the given number of bytes * @return {@code ValueArray} for given {@code Value} class */ @SuppressWarnings("unchecked") public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls, int bytes) { if (ByteValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ByteValueArray(bytes); } else if (CharValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new CharValueArray(bytes); } else if (DoubleValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new DoubleValueArray(bytes); } else if (FloatValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new FloatValueArray(bytes); } else if (IntValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new IntValueArray(bytes); } else if (LongValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new LongValueArray(bytes); } else if (NullValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new NullValueArray(bytes); } else if (ShortValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ShortValueArray(bytes); } else if (StringValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new StringValueArray(bytes); } else { throw new IllegalArgumentException("Unable to create bounded ValueArray for type " + cls); } }
Example #5
Source File: ValueArrayFactory.java From flink with Apache License 2.0 | 6 votes |
/** * Produce a {@code ValueArray} for the given {@code Value} type. * * @param cls {@code Value} class * @return {@code ValueArray} for given {@code Value} class */ @SuppressWarnings("unchecked") public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls) { if (ByteValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ByteValueArray(); } else if (CharValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new CharValueArray(); } else if (DoubleValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new DoubleValueArray(); } else if (FloatValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new FloatValueArray(); } else if (IntValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new IntValueArray(); } else if (LongValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new LongValueArray(); } else if (NullValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new NullValueArray(); } else if (ShortValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new ShortValueArray(); } else if (StringValue.class.isAssignableFrom(cls)) { return (ValueArray<T>) new StringValueArray(); } else { throw new IllegalArgumentException("Unable to create unbounded ValueArray for type " + cls); } }
Example #6
Source File: FloatValueSummaryAggregatorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Helper method for summarizing a list of values. * * <p>This method breaks the rule of "testing only one thing" by aggregating * and combining a bunch of different ways. */ @Override protected NumericColumnSummary<Float> summarize(Float... values) { FloatValue[] floatValues = new FloatValue[values.length]; for (int i = 0; i < values.length; i++) { if (values[i] != null) { floatValues[i] = new FloatValue(values[i]); } } return new AggregateCombineHarness<FloatValue, NumericColumnSummary<Float>, ValueSummaryAggregator.FloatValueSummaryAggregator>() { @Override protected void compareResults(NumericColumnSummary<Float> result1, NumericColumnSummary<Float> result2) { Assert.assertEquals(result1.getMin(), result2.getMin(), 0.0f); Assert.assertEquals(result1.getMax(), result2.getMax(), 0.0f); Assert.assertEquals(result1.getMean(), result2.getMean(), 1e-10d); Assert.assertEquals(result1.getVariance(), result2.getVariance(), 1e-9d); Assert.assertEquals(result1.getStandardDeviation(), result2.getStandardDeviation(), 1e-10d); } }.summarize(floatValues); }
Example #7
Source File: AdamicAdar.java From flink with Apache License 2.0 | 6 votes |
@Override public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Tuple4<IntValue, T, T, FloatValue>> out) throws Exception { int groupCount = 0; int groupSpans = 1; groupSpansValue.setValue(groupSpans); for (Tuple3<T, T, FloatValue> edge : values) { output.f1 = edge.f0; output.f2 = edge.f1; output.f3 = edge.f2; out.collect(output); if (++groupCount == GROUP_SIZE) { groupCount = 0; groupSpansValue.setValue(++groupSpans); } } }
Example #8
Source File: AdamicAdar.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Result<T>> out) throws Exception { double sum = 0; Tuple3<T, T, FloatValue> edge = null; for (Tuple3<T, T, FloatValue> next : values) { edge = next; sum += next.f2.getValue(); } if (sum >= minimumScore) { output.setVertexId0(edge.f0); output.setVertexId1(edge.f1); output.setAdamicAdarScore((float) sum); out.collect(output); } }
Example #9
Source File: GraphKeyTypeTransformTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testToFloatValue() throws Exception { TranslateFunction<LongValue, FloatValue> translator = new LongValueToUnsignedFloatValue(); Assert.assertEquals(new FloatValue(Float.intBitsToFloat(0)), translator.translate(new LongValue(0L), floatValue)); Assert.assertEquals(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)), translator.translate(new LongValue((long) Integer.MAX_VALUE + 1), floatValue)); Assert.assertEquals(new FloatValue(Float.intBitsToFloat(-1)), translator.translate(new LongValue(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1), floatValue)); }
Example #10
Source File: AdamicAdar.java From flink with Apache License 2.0 | 5 votes |
@Override public Tuple3<T, LongValue, FloatValue> map(Vertex<T, LongValue> value) throws Exception { output.f0 = value.f0; output.f1 = value.f1; long degree = value.f1.getValue(); // when the degree is one the logarithm is zero so avoid dividing by this value float inverseLogDegree = (degree == 1) ? 0.0f : 1.0f / (float) Math.log(value.f1.getValue()); output.f2.setValue(inverseLogDegree); return output; }
Example #11
Source File: CSVReaderTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithValueType() throws Exception { CsvReader reader = getCsvReader(); DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items = reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class); TypeInformation<?> info = items.getType(); Assert.assertEquals(true, info.isTupleType()); Assert.assertEquals(Tuple8.class, info.getTypeClass()); }
Example #12
Source File: AdamicAdar.java From flink with Apache License 2.0 | 5 votes |
@Override public void reduce(Iterable<Tuple4<IntValue, T, T, FloatValue>> values, Collector<Tuple3<T, T, FloatValue>> out) throws Exception { int visitedCount = 0; for (Tuple4<IntValue, T, T, FloatValue> edge : values) { output.f1 = edge.f2; output.f2 = edge.f3; for (int i = 0; i < visitedCount; i++) { output.f0 = visited.get(i); out.collect(output); } if (visitedCount < GROUP_SIZE) { if (!initialized) { initialized = true; for (int i = 0; i < GROUP_SIZE; i++) { visited.add(edge.f2.copy()); } } else { edge.f2.copyTo(visited.get(visitedCount)); } visitedCount += 1; } } }
Example #13
Source File: GraphKeyTypeTransformTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testFromFloatValue() throws Exception { TranslateFunction<FloatValue, LongValueWithProperHashCode> translator = new UnsignedFloatValueToLongValueWithProperHashCode(); Assert.assertEquals(new LongValueWithProperHashCode(0L), translator.translate(new FloatValue(Float.intBitsToFloat(0)), longValueWithProperHashCode)); Assert.assertEquals(new LongValueWithProperHashCode((long) Integer.MAX_VALUE + 1), translator.translate(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)), longValueWithProperHashCode)); Assert.assertEquals(new LongValueWithProperHashCode(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1), translator.translate(new FloatValue(Float.intBitsToFloat(-1)), longValueWithProperHashCode)); }
Example #14
Source File: CsvReaderITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testValueTypes() throws Exception { final String inputData = "ABC,true,1,2,3,4,5.0,6.0\nBCD,false,1,2,3,4,5.0,6.0"; final String dataPath = createInputData(inputData); final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> data = env.readCsvFile(dataPath).types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class); List<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> result = data.collect(); expected = inputData; compareResultAsTuples(result, expected); }
Example #15
Source File: ValueArrayTypeInfo.java From flink with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public TypeSerializer<ValueArray<T>> createSerializer(ExecutionConfig executionConfig) { Preconditions.checkNotNull(type, "TypeInformation type class is required"); if (ByteValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new ByteValueArraySerializer(); } else if (CharValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new CharValueArraySerializer(); } else if (DoubleValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new DoubleValueArraySerializer(); } else if (FloatValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new FloatValueArraySerializer(); } else if (IntValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new IntValueArraySerializer(); } else if (LongValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new LongValueArraySerializer(); } else if (NullValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new NullValueArraySerializer(); } else if (ShortValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new ShortValueArraySerializer(); } else if (StringValue.class.isAssignableFrom(type)) { return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new StringValueArraySerializer(); } else { throw new InvalidTypesException("No ValueArray class exists for " + type); } }
Example #16
Source File: FloatValueArray.java From flink with Apache License 2.0 | 5 votes |
@Override public void copyTo(ValueArray<FloatValue> target) { FloatValueArray other = (FloatValueArray) target; other.position = position; other.mark = mark; other.ensureCapacity(position); System.arraycopy(data, 0, other.data, 0, position); }
Example #17
Source File: GraphKeyTypeTransform.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse) throws Exception { if (reuse == null) { reuse = new LongValueWithProperHashCode(); } reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue())); return reuse; }
Example #18
Source File: FloatValueArrayComparatorTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected FloatValueArray[] getSortedTestData() { FloatValueArray lva0 = new FloatValueArray(); FloatValueArray lva1 = new FloatValueArray(); lva1.add(new FloatValue(5)); FloatValueArray lva2 = new FloatValueArray(); lva2.add(new FloatValue(5)); lva2.add(new FloatValue(10)); return new FloatValueArray[]{ lva0, lva1 }; }
Example #19
Source File: FloatValueParserTest.java From flink with Apache License 2.0 | 5 votes |
@Override public FloatValue[] getValidTestResults() { return new FloatValue[] { new FloatValue(0f), new FloatValue(0.0f), new FloatValue(123.4f), new FloatValue(0.124f), new FloatValue(.623f), new FloatValue(1234f), new FloatValue(-12.34f), new FloatValue(Float.MAX_VALUE), new FloatValue(Float.MIN_VALUE), new FloatValue(Float.NEGATIVE_INFINITY), new FloatValue(Float.POSITIVE_INFINITY), new FloatValue(Float.NaN), new FloatValue(1.234E2f), new FloatValue(1.234e3f), new FloatValue(1.234E-2f), new FloatValue(1239f) }; }
Example #20
Source File: GraphKeyTypeTransform.java From flink with Apache License 2.0 | 5 votes |
@Override public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse) throws Exception { if (reuse == null) { reuse = new LongValueWithProperHashCode(); } reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue())); return reuse; }
Example #21
Source File: AdamicAdar.java From flink with Apache License 2.0 | 5 votes |
@Override public void reduce(Iterable<Tuple4<IntValue, T, T, FloatValue>> values, Collector<Tuple3<T, T, FloatValue>> out) throws Exception { int visitedCount = 0; for (Tuple4<IntValue, T, T, FloatValue> edge : values) { output.f1 = edge.f2; output.f2 = edge.f3; for (int i = 0; i < visitedCount; i++) { output.f0 = visited.get(i); out.collect(output); } if (visitedCount < GROUP_SIZE) { if (!initialized) { initialized = true; for (int i = 0; i < GROUP_SIZE; i++) { visited.add(edge.f2.copy()); } } else { edge.f2.copyTo(visited.get(visitedCount)); } visitedCount += 1; } } }
Example #22
Source File: CSVReaderTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithValueType() throws Exception { CsvReader reader = getCsvReader(); DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items = reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class); TypeInformation<?> info = items.getType(); Assert.assertEquals(true, info.isTupleType()); Assert.assertEquals(Tuple8.class, info.getTypeClass()); }
Example #23
Source File: ToNullValueTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTranslation() throws Exception { NullValue reuse = NullValue.getInstance(); assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new DoubleValue(), reuse)); assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new FloatValue(), reuse)); assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new IntValue(), reuse)); assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new LongValue(), reuse)); assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new StringValue(), reuse)); }
Example #24
Source File: ValueArrayTypeInfo.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public TypeComparator<ValueArray<T>> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) { Preconditions.checkNotNull(type, "TypeInformation type class is required"); if (ByteValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new ByteValueArrayComparator(sortOrderAscending); } else if (CharValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new CharValueArrayComparator(sortOrderAscending); } else if (DoubleValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new DoubleValueArrayComparator(sortOrderAscending); } else if (FloatValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new FloatValueArrayComparator(sortOrderAscending); } else if (IntValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new IntValueArrayComparator(sortOrderAscending); } else if (LongValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new LongValueArrayComparator(sortOrderAscending); } else if (NullValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new NullValueArrayComparator(sortOrderAscending); } else if (ShortValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new ShortValueArrayComparator(sortOrderAscending); } else if (StringValue.class.isAssignableFrom(type)) { return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new StringValueArrayComparator(sortOrderAscending); } else { throw new InvalidTypesException("No ValueArray class exists for " + type); } }
Example #25
Source File: AdamicAdar.java From flink with Apache License 2.0 | 5 votes |
@Override public void flatMap(Tuple4<IntValue, T, T, FloatValue> value, Collector<Tuple4<IntValue, T, T, FloatValue>> out) throws Exception { int spans = value.f0.getValue(); for (int idx = 0; idx < spans; idx++) { value.f0.setValue(idx); out.collect(value); } }
Example #26
Source File: GraphKeyTypeTransformTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testFromFloatValue() throws Exception { TranslateFunction<FloatValue, LongValueWithProperHashCode> translator = new UnsignedFloatValueToLongValueWithProperHashCode(); Assert.assertEquals(new LongValueWithProperHashCode(0L), translator.translate(new FloatValue(Float.intBitsToFloat(0)), longValueWithProperHashCode)); Assert.assertEquals(new LongValueWithProperHashCode((long) Integer.MAX_VALUE + 1), translator.translate(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)), longValueWithProperHashCode)); Assert.assertEquals(new LongValueWithProperHashCode(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1), translator.translate(new FloatValue(Float.intBitsToFloat(-1)), longValueWithProperHashCode)); }
Example #27
Source File: GraphKeyTypeTransform.java From flink with Apache License 2.0 | 5 votes |
@Override public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse) throws Exception { if (reuse == null) { reuse = new LongValueWithProperHashCode(); } reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue())); return reuse; }
Example #28
Source File: FloatValueComparator.java From flink with Apache License 2.0 | 4 votes |
@Override public boolean equalToReference(FloatValue candidate) { return candidate.equals(this.reference); }
Example #29
Source File: FloatValueSerializer.java From flink with Apache License 2.0 | 4 votes |
@Override public FloatValue createInstance() { return new FloatValue(); }
Example #30
Source File: FloatValueComparator.java From flink with Apache License 2.0 | 4 votes |
@Override public TypeComparator<FloatValue> duplicate() { return new FloatValueComparator(ascendingComparison); }