本文整理了Java中java.util.stream.IntStream.mapToDouble()
方法的一些代码示例,展示了IntStream.mapToDouble()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IntStream.mapToDouble()
方法的具体详情如下:
包路径:java.util.stream.IntStream
类名称:IntStream
方法名:mapToDouble
[英]Returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.
This is an intermediate operation.
[中]返回一个DoubleStream,其中包含将给定函数应用于该流元素的结果。
这是一个intermediate operation。
代码示例来源:origin: neo4j/neo4j
@SuppressWarnings( "unchecked" )
public static DoubleStream toDoubleStream( Object list )
{
if ( list == null )
{
return DoubleStream.empty();
}
else if ( list instanceof SequenceValue )
{
throw new IllegalArgumentException( "Need to implement support for SequenceValue in CompiledConversionUtils.toDoubleStream" );
}
else if ( list instanceof List )
{
return ((List) list).stream().mapToDouble( n -> ((Number) n).doubleValue() );
}
else if ( Object[].class.isAssignableFrom( list.getClass() ) )
{
return Arrays.stream( (Object[]) list ).mapToDouble( n -> ((Number) n).doubleValue() );
}
else if ( list instanceof float[] )
{
float[] array = (float[]) list;
return IntStream.range( 0, array.length ).mapToDouble( i -> array[i] );
}
else if ( list instanceof double[] )
{
return DoubleStream.of( (double[]) list );
}
throw new IllegalArgumentException( format( "Can not be converted to stream: %s", list.getClass().getName() ) );
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* 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()));
}
代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises
public static double[] simpleMovingAverage(double[] values, int n) {
double[] sums = Arrays.copyOf(values, values.length); // <1>
Arrays.parallelPrefix(sums, Double::sum); // <2>
int start = n - 1;
return IntStream.range(start, sums.length) // <3>
.mapToDouble(i -> {
double prefix = i == start ? 0 : sums[i - n];
return (sums[i] - prefix) / n; // <4>
})
.toArray(); // <5>
}
// END simpleMovingAverage
代码示例来源:origin: apache/ignite
/**
* 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());
}
代码示例来源:origin: jtablesaw/tablesaw
private AttributeDataset dataset(NumericColumn<?> responseCol, AttributeType type, List<Column<?>> variableCols) {
List<Column<?>> convertedVariableCols = variableCols.stream()
.map(col -> col.type() == ColumnType.STRING ? col : table.nCol(col.name()))
.collect(Collectors.toList());
Attribute responseAttribute = type == AttributeType.NOMINAL
? colAsNominalAttribute(responseCol) : new NumericAttribute(responseCol.name());
AttributeDataset dataset = new AttributeDataset(table.name(),
convertedVariableCols.stream().map(col -> colAsAttribute(col)).toArray(Attribute[]::new),
responseAttribute);
for (int i = 0; i < responseCol.size(); i++) {
final int r = i;
double[] x = IntStream.range(0, convertedVariableCols.size())
.mapToDouble(c -> getDouble(convertedVariableCols.get(c), dataset.attributes()[c], r))
.toArray();
dataset.add(x, responseCol.getDouble(r));
}
return dataset;
}
代码示例来源:origin: apache/nifi
return IntStream.range(0, floatArray.length)
.mapToDouble(i -> floatArray[i])
.mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element))
.collect(Collectors.toList());
return IntStream.range(0, booleanArray.length)
.map(i -> booleanArray[i] ? 1 : 0)
.mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("boolean"), element == 1))
代码示例来源:origin: apache/nifi
return IntStream.range(0, floatArray.length)
.mapToDouble(i -> floatArray[i])
.mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element, hiveFieldNames))
.collect(Collectors.toList());
return IntStream.range(0, booleanArray.length)
.map(i -> booleanArray[i] ? 1 : 0)
.mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("boolean"), element == 1, hiveFieldNames))
代码示例来源:origin: apache/tinkerpop
public static double clock(final int loops, final Runnable runnable) {
runnable.run(); // warm-up
return IntStream.range(0, loops).mapToDouble(i -> {
long t = System.nanoTime();
runnable.run();
return (System.nanoTime() - t) * 0.000001;
}).sum() / loops;
}
代码示例来源:origin: apache/tinkerpop
public static <S> Pair<Double, S> clockWithResult(final int loops, final Supplier<S> supplier) {
final S result = supplier.get(); // warm up
return Pair.with(IntStream.range(0, loops).mapToDouble(i -> {
long t = System.nanoTime();
supplier.get();
return (System.nanoTime() - t) * 0.000001;
}).sum() / loops, result);
}
}
代码示例来源:origin: com.simiacryptus/mindseye-test
/**
* Scan double stream.
*
* @return the double stream
*/
public DoubleStream scan() {
return IntStream.range(-1000, 1000).mapToDouble(x -> x / 300.0);
}
代码示例来源:origin: com.simiacryptus/mindseye-research
/**
* Dot double.
*
* @param a the a
* @param b the b
* @return the double
*/
public static double dot(double[] a, double[] b) {
return IntStream.range(0, a.length).mapToDouble(i -> a[i] * b[i]).sum();
}
代码示例来源:origin: com.simiacryptus/mindseye
/**
* Dot double.
*
* @param a the a
* @param b the b
* @return the double
*/
public static double dot(double[] a, double[] b) {
return IntStream.range(0, a.length).mapToDouble(i -> a[i] * b[i]).sum();
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-core
public static double clock(final int loops, final Runnable runnable) {
runnable.run(); // warm-up
return IntStream.range(0, loops).mapToDouble(i -> {
long t = System.nanoTime();
runnable.run();
return (System.nanoTime() - t) * 0.000001;
}).sum() / loops;
}
代码示例来源:origin: org.maochen.nlp/CoreNLP-NLP
private double[] reweight(final double[] x, final double[] weight, final double correctionD) {
return IntStream.range(0, x.length)
.mapToDouble(i -> weight[i] + model.learningRate * correctionD * x[i]) // Main Part, +1 strategy
.toArray();
}
代码示例来源:origin: MegaMek/megamek
protected String getASRangeString(double[] damage) {
return IntStream.range(0, damage.length).mapToDouble(i -> damage[i] / 10.0)
.mapToObj(d -> {
if (d > 0.5) {
return Integer.toString((int)Math.round(d));
} else if (d > 0) {
return "0*";
} else {
return "0";
}
}).collect(Collectors.joining("/"));
}
代码示例来源:origin: jenetics/jenetics
/**
* Returns a sequential stream of the alleles with this chromosome as its
* source.
*
* @since 4.3
*
* @return a sequential stream of alleles
*/
public DoubleStream doubleStream() {
return IntStream.range(0, length()).mapToDouble(this::doubleValue);
}
代码示例来源:origin: neo4j-contrib/neo4j-graph-algorithms
public double[] toArray() {
return IntStream.range(0, capacity)
.mapToDouble(this::get)
.toArray();
}
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-core
public static <S> Pair<Double, S> clockWithResult(final int loops, final Supplier<S> supplier) {
final S result = supplier.get(); // warm up
return Pair.with(IntStream.range(0, loops).mapToDouble(i -> {
long t = System.nanoTime();
supplier.get();
return (System.nanoTime() - t) * 0.000001;
}).sum() / loops, result);
}
}
代码示例来源:origin: com.simiacryptus/mindseye-research
/**
* Add double [ ].
*
* @param a the a
* @param b the b
* @return the double [ ]
*/
public static double[] add(double[] a, double[] b) {
return IntStream.range(0, a.length).mapToDouble(i -> a[i] + b[i]).toArray();
}
代码示例来源:origin: com.simiacryptus/mindseye-research
/**
* Dot double.
*
* @param a the a
* @param b the b
* @return the double
*/
public static double dot(@Nonnull final List<DoubleBuffer<UUID>> a, @Nonnull final List<DoubleBuffer<UUID>> b) {
assert a.size() == b.size();
return IntStream.range(0, a.size()).mapToDouble(i -> a.get(i).dot(b.get(i))).sum();
}
内容来源于网络,如有侵权,请联系作者删除!