本文整理了Java中java.util.Arrays.parallelPrefix()
方法的一些代码示例,展示了Arrays.parallelPrefix()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays.parallelPrefix()
方法的具体详情如下:
包路径:java.util.Arrays
类名称:Arrays
方法名:parallelPrefix
暂无
代码示例来源: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: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
long[] nums = new long[SIZE];
Arrays.setAll(nums, n -> n);
Arrays.parallelPrefix(nums, Long::sum);
System.out.println("First 20: " + nums[19]);
System.out.println("First 200: " + nums[199]);
System.out.println("All: " + nums[nums.length-1]);
}
}
代码示例来源:origin: stackoverflow.com
double[] array=new double[n+1];
Arrays.parallelSetAll(array, index -> index==0? 1: x/index);
Arrays.parallelPrefix(array, (a,b) -> a*b);
// we could do the last step as prefix op as well:
//Arrays.parallelPrefix(array, Double::sum);
//double exp=array[n];
// but a straight forward summing is better:
double exp=Arrays.stream(array).parallel().sum();
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
int[] nums = new Count.Pint().array(10);
show(nums);
System.out.println(Arrays.stream(nums)
.reduce(Integer::sum).getAsInt());
Arrays.parallelPrefix(nums, Integer::sum);
show(nums);
System.out.println(Arrays.stream(
new Count.Pint().array(6))
.reduce(Integer::sum).getAsInt());
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(CHECK);
Long[] aL = new Long[SZ+1];
Arrays.parallelSetAll(aL, i -> (long)i);
Summing.timeTest("Long Array Stream Reduce",
CHECK, () ->
Arrays.stream(aL).reduce(0L, Long::sum));
Summing.timeTest("Long Basic Sum", CHECK, () ->
basicSum(aL));
// Destructive summation:
Summing.timeTest("Long parallelPrefix",CHECK, ()-> {
Arrays.parallelPrefix(aL, Long::sum);
return aL[aL.length - 1];
});
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
System.out.println(CHECK);
long[] la = new long[SZ+1];
Arrays.parallelSetAll(la, i -> i);
Summing.timeTest("Array Stream Sum", CHECK, () ->
Arrays.stream(la).sum());
Summing.timeTest("Parallel", CHECK, () ->
Arrays.stream(la).parallel().sum());
Summing.timeTest("Basic Sum", CHECK, () ->
basicSum(la));
// Destructive summation:
Summing.timeTest("parallelPrefix", CHECK, () -> {
Arrays.parallelPrefix(la, Long::sum);
return la[la.length - 1];
});
}
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
String[] strings = new Rand.String(1).array(8);
show(strings);
Arrays.parallelPrefix(strings, (a, b) -> a + b);
show(strings);
}
}
内容来源于网络,如有侵权,请联系作者删除!