public DoubleBoxedAction() { super(s -> s.boxed(), Stream.class, BOXED); }
/** * Returns the current coordinate. * * @return A list of numbers describing the coordinate. */ public List<Double> getCoordinate() { return stream( coordinate ).boxed().collect( Collectors.toList() ); }
/** * Returns the last element of the specified stream, or {@link OptionalDouble#empty} if the stream * is empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see DoubleStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalDouble findLast(DoubleStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Double> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalDouble.of(boxedLast.get()) : OptionalDouble.empty(); }
/** * Create new {@link Weights} given {@code weights} as {@code int}. * * @param weights must not be {@literal null}. * @return the {@link Weights} for {@code weights}. */ public static Weights of(int... weights) { Assert.notNull(weights, "Weights must not be null!"); return new Weights(Arrays.stream(weights).mapToDouble(value -> value).boxed().collect(Collectors.toList())); }
/** * Creates equal {@link Weights} for a number of input sets {@code count} with a weight of one. * * @param count number of input sets. Must be greater or equal to zero. * @return equal {@link Weights} for a number of input sets with a weight of one. */ public static Weights fromSetCount(int count) { Assert.isTrue(count >= 0, "Count of input sorted sets must be greater or equal to zero!"); return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).boxed().collect(Collectors.toList())); }
/** * Create new {@link Weights} given {@code weights} as {@code double}. * * @param weights must not be {@literal null}. * @return the {@link Weights} for {@code weights}. */ public static Weights of(double... weights) { Assert.notNull(weights, "Weights must not be null!"); return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList())); }
/** * Returns the last element of the specified stream, or {@link OptionalDouble#empty} if the stream * is empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see DoubleStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalDouble findLast(DoubleStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Double> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalDouble.of(boxedLast.get()) : OptionalDouble.empty(); }
/** * Returns the last element of the specified stream, or {@link OptionalDouble#empty} if the stream * is empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see DoubleStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalDouble findLast(DoubleStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Double> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalDouble.of(boxedLast.get()) : OptionalDouble.empty(); }
private Double[] box(double[] values) { return DoubleStream.of(values).boxed().toArray(Double[]::new); } }
@Override public Stream<Double> boxed() { return wrap(stream().boxed()); }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code false}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).rejects(1.75, 1.80, 1.85); * * // assertion fails because of 1.90 size: * assertThat(tallSize).rejects(1.80, 1.85, 1.90);</code></pre> * * @param values values that the actual {@code Predicate} should reject. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} accepts one of the given values. */ public DoublePredicateAssert rejects(double... values) { if (values.length == 1) return rejectsInternal(values[0]); return rejectsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); } }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code true}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).accepts(1.95, 2.00, 2.05); * * // assertion fails: * assertThat(tallSize).accepts(1.85, 1.95, 2.05);</code></pre> * * @param values values that the actual {@code Predicate} should accept. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} does not accept all given values. */ public DoublePredicateAssert accepts(double... values) { if (values.length == 1) return acceptsInternal(values[0]); return acceptsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); }
private Set<Value> randomDoubles( double min, double max ) { return ThreadLocalRandom.current() .doubles( nodesToCreate, min, max ) .boxed() .map( Values::of ) .collect( toSet() ); }
/** * Returns the last element of the specified stream, or {@link OptionalDouble#empty} if the stream * is empty. * * <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This * method's runtime will be between O(log n) and O(n), performing better on <a * href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a> * streams. * * @see DoubleStream#findFirst() * @throws NullPointerException if the last element of the stream is null */ public static OptionalDouble findLast(DoubleStream stream) { // findLast(Stream) does some allocation, so we might as well box some more java.util.Optional<Double> boxedLast = findLast(stream.boxed()); return boxedLast.isPresent() ? OptionalDouble.of(boxedLast.get()) : OptionalDouble.empty(); }
/** {@inheritDoc} */ @Override protected <V, K> boolean learnLabels(DatasetBuilder<K, V> builder, IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Double> lExtractor) { Set<Double> uniqLabels = builder.build( envBuilder, new EmptyContextBuilder<>(), new LabeledDatasetPartitionDataBuilderOnHeap<>(featureExtractor, lExtractor)) .compute((IgniteFunction<LabeledVectorSet<Double, LabeledVector>, Set<Double>>)x -> Arrays.stream(x.labels()).boxed().collect(Collectors.toSet()), (a, b) -> { if (a == null) return b; if (b == null) return a; a.addAll(b); return a; } ); if (uniqLabels != null && uniqLabels.size() == 2) { ArrayList<Double> lblsArr = new ArrayList<>(uniqLabels); externalFirstCls = lblsArr.get(0); externalSecondCls = lblsArr.get(1); return true; } else return false; }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code true}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).accepts(1.95, 2.00, 2.05); * * // assertion fails: * assertThat(tallSize).accepts(1.85, 1.95, 2.05);</code></pre> * * @param values values that the actual {@code Predicate} should accept. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} does not accept all given values. */ public DoublePredicateAssert accepts(double... values) { if (values.length == 1) return acceptsInternal(values[0]); return acceptsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code false}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).rejects(1.75, 1.80, 1.85); * * // assertion fails because of 1.90 size: * assertThat(tallSize).rejects(1.80, 1.85, 1.90);</code></pre> * * @param values values that the actual {@code Predicate} should reject. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} accepts one of the given values. */ public DoublePredicateAssert rejects(double... values) { if (values.length == 1) return rejectsInternal(values[0]); return rejectsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); } }
private List<Comparable> primitiveArrayToList(FieldSpec.DataType dataType, Object sortedValues) { List<Comparable> valueList; switch (dataType) { case INT: valueList = Arrays.stream((int[]) sortedValues).boxed().collect(Collectors.toList()); break; case LONG: valueList = Arrays.stream((long[]) sortedValues).boxed().collect(Collectors.toList()); break; case FLOAT: // Stream not available for float. valueList = new ArrayList<>(); for (float value : ((float[]) sortedValues)) { valueList.add(value); } break; case DOUBLE: valueList = Arrays.stream((double[]) sortedValues).boxed().collect(Collectors.toList()); break; default: throw new IllegalArgumentException("Illegal data type for mutable dictionary: " + dataType); } return valueList; } }
private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs) { assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueDoubles(maxError, inputs)); // test scalars List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList()); SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page); assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99); }
private void assertPercentilesWithinError(String type, SqlVarbinary binary, double error, List<? extends Number> rows, double[] percentiles) { List<Double> boxedPercentiles = Arrays.stream(percentiles).sorted().boxed().collect(toImmutableList()); List<Number> lowerBounds = boxedPercentiles.stream().map(percentile -> getLowerBound(error, rows, percentile)).collect(toImmutableList()); List<Number> upperBounds = boxedPercentiles.stream().map(percentile -> getUpperBound(error, rows, percentile)).collect(toImmutableList()); // Ensure that the lower bound of each item in the distribution is not greater than the chosen quantiles functionAssertions.assertFunction( format( "zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, lowerbound) -> value >= lowerbound)", binary.toString().replaceAll("\\s+", " "), type, ARRAY_JOINER.join(boxedPercentiles), ARRAY_JOINER.join(lowerBounds)), METADATA.getType(parseTypeSignature("array(boolean)")), Collections.nCopies(percentiles.length, true)); // Ensure that the upper bound of each item in the distribution is not less than the chosen quantiles functionAssertions.assertFunction( format( "zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, upperbound) -> value <= upperbound)", binary.toString().replaceAll("\\s+", " "), type, ARRAY_JOINER.join(boxedPercentiles), ARRAY_JOINER.join(upperBounds)), METADATA.getType(parseTypeSignature("array(boolean)")), Collections.nCopies(percentiles.length, true)); }