当前位置: 首页>>代码示例>>Java>>正文


Java Arrays.parallelPrefix方法代码示例

本文整理汇总了Java中java.util.Arrays.parallelPrefix方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.parallelPrefix方法的具体用法?Java Arrays.parallelPrefix怎么用?Java Arrays.parallelPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Arrays的用法示例。


在下文中一共展示了Arrays.parallelPrefix方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: simpleMovingAverage

import java.util.Arrays; //导入方法依赖的package包/类
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>
}
 
开发者ID:jinyi233,项目名称:https-github.com-RichardWarburton-java-8-Lambdas-exercises,代码行数:12,代码来源:ArrayExamples.java

示例2: testParallelPrefixForInt

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
    int[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsInt(sequentialResult[index  - 1], sequentialResult[index]);
    }

    int[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ParallelPrefix.java

示例3: testParallelPrefixForLong

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="longSet")
public void testParallelPrefixForLong(long[] data, int fromIndex, int toIndex, LongBinaryOperator op) {
    long[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsLong(sequentialResult[index  - 1], sequentialResult[index]);
    }

    long[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    long[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ParallelPrefix.java

示例4: testParallelPrefixForDouble

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="doubleSet")
public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) {
    double[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsDouble(sequentialResult[index  - 1], sequentialResult[index]);
    }

    double[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ParallelPrefix.java

示例5: testParallelPrefixForStringr

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="stringSet")
public void testParallelPrefixForStringr(String[] data , int fromIndex, int toIndex, BinaryOperator<String> op) {
    String[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.apply(sequentialResult[index  - 1], sequentialResult[index]);
    }

    String[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertEquals(parallelResult, sequentialResult);

    String[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertEquals(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:ParallelPrefix.java

示例6: testParallelPrefixForInt

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="intSet")
public void testParallelPrefixForInt(int[] data, int fromIndex, int toIndex, IntBinaryOperator op) {
    int[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsInt(sequentialResult[index  - 1], sequentialResult[index]);
    }

    int[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertArraysEqual(parallelResult, sequentialResult);

    int[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ParallelPrefix.java

示例7: testParallelPrefixForLong

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="longSet")
public void testParallelPrefixForLong(long[] data, int fromIndex, int toIndex, LongBinaryOperator op) {
    long[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsLong(sequentialResult[index  - 1], sequentialResult[index]);
    }

    long[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertArraysEqual(parallelResult, sequentialResult);

    long[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ParallelPrefix.java

示例8: testParallelPrefixForDouble

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="doubleSet")
public void testParallelPrefixForDouble(double[] data, int fromIndex, int toIndex, DoubleBinaryOperator op) {
    double[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.applyAsDouble(sequentialResult[index  - 1], sequentialResult[index]);
    }

    double[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertArraysEqual(parallelResult, sequentialResult);

    double[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ParallelPrefix.java

示例9: testParallelPrefixForStringr

import java.util.Arrays; //导入方法依赖的package包/类
@Test(dataProvider="stringSet")
public void testParallelPrefixForStringr(String[] data , int fromIndex, int toIndex, BinaryOperator<String> op) {
    String[] sequentialResult = data.clone();
    for (int index = fromIndex + 1; index < toIndex; index++) {
        sequentialResult[index ] = op.apply(sequentialResult[index  - 1], sequentialResult[index]);
    }

    String[] parallelResult = data.clone();
    Arrays.parallelPrefix(parallelResult, fromIndex, toIndex, op);
    assertArraysEqual(parallelResult, sequentialResult);

    String[] parallelRangeResult = Arrays.copyOfRange(data, fromIndex, toIndex);
    Arrays.parallelPrefix(parallelRangeResult, op);
    assertArraysEqual(parallelRangeResult, Arrays.copyOfRange(sequentialResult, fromIndex, toIndex));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ParallelPrefix.java


注:本文中的java.util.Arrays.parallelPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。