Tabnine Logo
Arrays.parallelPrefix
Code IndexAdd Tabnine to your IDE (free)

How to use
parallelPrefix
method
in
java.util.Arrays

Best Java code snippets using java.util.Arrays.parallelPrefix (Showing top 7 results out of 315)

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);
 }
}
java.utilArraysparallelPrefix

Popular methods of Arrays

  • asList
    Returns a List of the objects in the specified array. The size of the List cannot be modified, i.e.
  • toString
    Returns a string representation of the contents of the specified array. The string representation co
  • equals
    Returns true if the two specified arrays of booleans areequal to one another. Two arrays are conside
  • sort
    Sorts the specified range of the array into ascending order. The range to be sorted extends from the
  • copyOf
    Copies the specified array, truncating or padding with false (if necessary) so the copy has the spec
  • fill
    Assigns the specified boolean value to each element of the specified array of booleans.
  • stream
  • hashCode
    Returns a hash code based on the contents of the specified array. For any two boolean arrays a and
  • copyOfRange
    Copies the specified range of the specified array into a new array. The initial index of the range (
  • binarySearch
    Searches the specified array of shorts for the specified value using the binary search algorithm. Th
  • deepEquals
    Returns true if the two specified arrays are deeply equal to one another. Unlike the #equals(Object[
  • deepToString
  • deepEquals,
  • deepToString,
  • deepHashCode,
  • setAll,
  • parallelSort,
  • parallelSetAll,
  • spliterator,
  • checkBinarySearchBounds,
  • checkOffsetAndCount,
  • checkStartAndEnd

Popular in Java

  • Creating JSON documents from java classes using gson
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • startActivity (Activity)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • JButton (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now