Skip to content

Commit

Permalink
snap
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Apr 21, 2021
1 parent 5bb7ff7 commit 4e96d35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject cnuernber/dtype-next "7.10"
(defproject cnuernber/dtype-next "7.11-SNAPSHOT"
:description "A Clojure library designed to aid in the implementation of high performance algorithms and systems."
:url "http://github.com/cnuernber/dtype-next"
:license {:name "EPL-2.0"
Expand Down
19 changes: 18 additions & 1 deletion src/tech/v3/parallel/for.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns tech.v3.parallel.for
"Serial and parallel iteration strategies across iterators and index spaces."
(:require [tech.v3.datatype.errors :as errors])
(:import [java.util.concurrent ForkJoinPool Callable Future ForkJoinTask]
[java.util ArrayDeque PriorityQueue Comparator Spliterator Iterator
ArrayList List]
Expand Down Expand Up @@ -225,10 +226,26 @@
(if (convertible-to-iterator? item)
(doiter
value item
(.accept local-consumer value))))
(.accept local-consumer value))
(errors/throwf "Item is not iterable thus it cannot be consumed")))
consumer))


(defn indexed-consume!
"Consume (terminate) a sequence or stream. If the stream is parallel
then the consumer had better be threadsafe. Consumer in this case is
expected to be an clojure IFn and it will receive two arguments, a long
and the value."
[consumer item]
(let [iter (->iterator item)]
(loop [continue? (.hasNext iter)
idx 0]
(when continue?
(consumer idx (.next iter))
(recur (.hasNext iter) (unchecked-inc idx)))))
consumer)


(defn spliterator-map-reduce
"Given a spliterator, a function from spliterator to scalar and a
reduction function do an efficient parallelized reduction."
Expand Down

0 comments on commit 4e96d35

Please sign in to comment.