/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableDoubleArray copyOf(DoubleStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. double[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableDoubleArray(array); }
/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableDoubleArray copyOf(DoubleStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. double[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableDoubleArray(array); }
public static double[] pairwiseScoreThresholds(Properties props) { String thresholdsProp = props.getProperty("coref.statistical.pairwiseScoreThresholds"); if (thresholdsProp != null) { String[] split = thresholdsProp.split(","); if (split.length == 4) { return Arrays.stream(split).mapToDouble(Double::parseDouble).toArray(); } } double threshold = PropertiesUtils.getDouble( props, "coref.statistical.pairwiseScoreThresholds", 0.35); return new double[] {threshold, threshold, threshold, threshold}; }
/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableDoubleArray copyOf(DoubleStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. double[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableDoubleArray(array); }
@Override public double[] execute() { try (final DoubleStream stream = buildPrevious()) { return stream.toArray(); } } }
/** * Creates {@link VectorGenerator} with vectors having feature values in according to * preudorandom producers. * * @param producers Feature value producers. * @return Vector generator. */ public static VectorGenerator vectorize(RandomProducer... producers) { A.notEmpty(producers, "producers"); return () -> VectorUtils.of(Arrays.stream(producers).mapToDouble(Supplier::get).toArray()); } }
private static IterableSubject assertThat(DoubleStream stream) { return Truth.assertThat(Doubles.asList(stream.toArray())); } }
/** * Builds VectorGeneratorsFamily instance. * * @param seed Seed. * @return Vector generators family. */ public VectorGeneratorsFamily build(long seed) { A.notEmpty(family, "family.size != 0"); double sumOfWeigts = weights.stream().mapToDouble(x -> x).sum(); double[] probs = weights.stream().mapToDouble(w -> w / sumOfWeigts).toArray(); List<VectorGenerator> mappedFamilily = family.stream().map(mapper).collect(Collectors.toList()); return new VectorGeneratorsFamily(mappedFamilily, new DiscreteRandomProducer(seed, probs)); } }
public Shape (GTFSFeed feed, String shape_id) { Map<Fun.Tuple2<String, Integer>, ShapePoint> points = feed.shape_points.subMap(new Fun.Tuple2(shape_id, null), new Fun.Tuple2(shape_id, Fun.HI)); Coordinate[] coords = points.values().stream() .map(point -> new Coordinate(point.shape_pt_lon, point.shape_pt_lat)) .toArray(i -> new Coordinate[i]); geometry = geometryFactory.createLineString(coords); shape_dist_traveled = points.values().stream().mapToDouble(point -> point.shape_dist_traveled).toArray(); } }
/** {@inheritDoc} */ @Override public Vector get() { Double t = randomProducer.get(); return VectorUtils.of(perDimensionGenerators.stream() .mapToDouble(f -> f.apply(t)).toArray()); } }
public static double[] constructDoublePrimitiveArray(int start, int length) { return IntStream.range(start, start + length).asDoubleStream().toArray(); } }
@Override public double[] toArray() { try { return stream().toArray(); } finally { close(); } }
private static double[] coordinatesAsArray( JsonNode element ) { return Iterables.stream( element.get( "coordinates" ) ) .mapToDouble( JsonNode::asDouble ) .toArray(); }
/** * Create {@link VectorGenerator} with vectors having feature values generated by random producer. * * @param vectorSize Generated vector size. * @return Vector generator. */ public default VectorGenerator vectorize(int vectorSize) { return () -> VectorUtils.of(IntStream.range(0, vectorSize).mapToDouble(x -> get()).toArray()); }
private SymbolStatsEstimate buildSymbolStatistics(List<Object> values, Session session, Type type) { List<Object> nonNullValues = values.stream() .filter(Objects::nonNull) .collect(toImmutableList()); if (nonNullValues.isEmpty()) { return SymbolStatsEstimate.zero(); } double[] valuesAsDoubles = nonNullValues.stream() .map(value -> toStatsRepresentation(metadata, session, type, value)) .filter(OptionalDouble::isPresent) .mapToDouble(OptionalDouble::getAsDouble) .toArray(); double lowValue = DoubleStream.of(valuesAsDoubles).min().orElse(Double.NEGATIVE_INFINITY); double highValue = DoubleStream.of(valuesAsDoubles).max().orElse(Double.POSITIVE_INFINITY); double valuesCount = values.size(); double nonNullValuesCount = nonNullValues.size(); long distinctValuesCount = nonNullValues.stream().distinct().count(); return SymbolStatsEstimate.builder() .setNullsFraction((valuesCount - nonNullValuesCount) / valuesCount) .setLowValue(lowValue) .setHighValue(highValue) .setDistinctValuesCount(distinctValuesCount) .build(); } }
private PointValue randomPoint( int index, int dimension ) { CoordinateReferenceSystem crs; if ( index % 2 == 0 ) { crs = dimension == 2 ? WGS84 : WGS84_3D; } else { crs = dimension == 2 ? Cartesian : Cartesian_3D; } return unsafePointValue( crs, random.doubles( dimension, Double.MIN_VALUE, Double.MAX_VALUE ).toArray() ); }
@Test public void basicEqualsReturnsFalseWhenOnlySecondObjectIsACharArray() { assertThat(ValueComparisonHelper .basicEquals(Arrays.stream(INT_ARRAY).asDoubleStream().toArray(), STRING.toCharArray())) .isFalse(); }
public void testStream() { ImmutableDoubleArray.of().stream().forEach(i -> fail()); ImmutableDoubleArray.of(0, 1, 3).subArray(1, 1).stream().forEach(i -> fail()); assertThat(ImmutableDoubleArray.of(0, 1, 3).stream().toArray()) .isEqualTo(new double[] {0, 1, 3}); }