public DoubleMapToObjAction(DoubleFunction<? extends U> mapper) { super(s -> s.mapToObj(requireNonNull(mapper)), Stream.class, MAP_TO); }
@Override public Stream<R> build(boolean parallel) { return previous().build(parallel).mapToObj(mapper); } }
@Override public <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) { return wrap(stream().mapToObj(mapper)); }
return IntStream.range(0, floatArray.length) .mapToDouble(i -> floatArray[i]) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element)) .collect(Collectors.toList()); double[] doubleArray = (double[]) o; return Arrays.stream(doubleArray) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("double"), element)) .collect(Collectors.toList());
return IntStream.range(0, floatArray.length) .mapToDouble(i -> floatArray[i]) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element, hiveFieldNames)) .collect(Collectors.toList()); double[] doubleArray = (double[]) o; return Arrays.stream(doubleArray) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("double"), element, hiveFieldNames)) .collect(Collectors.toList());
/** * A filter for a field based on several terms matching on any of them. * * @param fieldName The field name * @param values The terms */ public TermsQueryBuilder(String fieldName, double... values) { this(fieldName, values != null ? Arrays.stream(values).mapToObj(s -> s).collect(Collectors.toList()) : (Iterable<?>) null); }
/** * A filter for a field based on several terms matching on any of them. * * @param fieldName The field name * @param values The terms */ public TermsQueryBuilder(String fieldName, double... values) { this(fieldName, values != null ? Arrays.stream(values).mapToObj(s -> s).collect(Collectors.toList()) : (Iterable<?>) null); }
static String createSnippetFromObservations(Object o) { String snippet = "new " + o.getClass().getSimpleName() + "{ "; if (o instanceof int[]) { snippet += Arrays.stream((int[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } else if (o instanceof double[]) { snippet += Arrays.stream((double[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } else if (o instanceof long[]) { snippet += Arrays.stream((long[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } return snippet + "}"; }
public static SubsetSum of(final int n, final int k, final Random random) { return new SubsetSum( random.doubles() .limit(n) .mapToObj(d -> (int)((d - 0.5)*n)) .collect(ISeq.toISeq()), k ); }
private static ISeq<Phenotype<DoubleGene, Double>> population( final int min, final int max ) { return IntStream.rangeClosed(min, max) .mapToDouble(i -> (double)i) .mapToObj(PopulationConvergenceLimitTest::phenotype) .collect(ISeq.toISeq()); }
private static ISeq<Phenotype<DoubleGene, Double>> population( final int min, final int max ) { return IntStream.rangeClosed(min, max) .mapToDouble(i -> (double)i) .mapToObj(FitnessThresholdLimitTest::phenotype) .collect(ISeq.toISeq()); }
private static ISeq<Phenotype<DoubleGene, Double>> population( final int min, final int max ) { return IntStream.rangeClosed(min, max) .mapToDouble(i -> (double)i) .mapToObj(GeneConvergenceLimitTest::phenotype) .collect(ISeq.toISeq()); }
static ISeq<Vec<double[]>> circle(final int count, final Random random) { return random.doubles(count) .mapToObj(r -> { final double a = random.nextDouble()*2*PI; return Vec.of(r*sin(a), r*cos(a)); }) .collect(ISeq.toISeq()); }
static ISeq<Point2> front(final int count, final Random random) { return random.doubles(count) .mapToObj(x -> Point2.of(x, sqrt(1 - x*x))) .collect(ISeq.toISeq()); }
static ISeq<Vec<double[]>> frontMax( final double r, final int count, final Random random ) { return random.doubles(count) .map(a -> a*PI*0.5) .mapToObj(a -> Vec.of(r*sin(a), r*cos(a))) .collect(ISeq.toISeq()); }
static ISeq<Vec<double[]>> frontMin( final double r, final int count, final Random random ) { return random.doubles(count) .map(a -> a*PI*0.5 + PI) .mapToObj(a -> Vec.of(r*sin(a), r*cos(a))) .collect(ISeq.toISeq()); }
@Test public void acceptReverseMinMax() { final Random random = RandomRegistry.getRandom(); final double[] numbers = random.doubles().limit(1000).toArray(); final MinMax<Double> minMax = MinMax.of((a, b) -> b.compareTo(a)); Arrays.stream(numbers) .mapToObj(Double::valueOf) .forEach(minMax); Assert.assertEquals(minMax.getMin(), StatUtils.max(numbers)); Assert.assertEquals(minMax.getMax(), StatUtils.min(numbers)); }
static ISeq<Point2> circle(final int count, final Random random) { return random.doubles() .mapToObj(x -> Point2.of(x, random.nextDouble())) .filter(p -> p.x()*p.x() + p.y()*p.y() < 0.9) .limit(count) .collect(ISeq.toISeq()); } }
@Test public void toMinMaxNormal() { final Random random = RandomRegistry.getRandom(); final double[] numbers = random.doubles().limit(1000).toArray(); final MinMax<Double> minMax = Arrays.stream(numbers) .mapToObj(Double::valueOf) .collect(MinMax.toMinMax()); Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers)); Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers)); }
@Test public void acceptNormalMinMax() { final Random random = RandomRegistry.getRandom(); final double[] numbers = random.doubles().limit(1000).toArray(); final MinMax<Double> minMax = MinMax.of(); Arrays.stream(numbers) .mapToObj(Double::valueOf) .forEach(minMax); Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers)); Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers)); }