From 98a845f99541e6ece591a3c0528cdf400a39ff88 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 24 Jun 2020 17:23:39 -0700 Subject: [PATCH] Document that reduce may exploit commutativity --- base/reduce.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/base/reduce.jl b/base/reduce.jl index c73caaeac7a973..93c015c54dfca8 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -270,6 +270,10 @@ In general, it will be necessary to provide `init` to work with empty collection intermediate collection needs to be created. See documentation for [`reduce`](@ref) and [`map`](@ref). +Known commutativity of the operation `op` such as `+` and `max` may be exploited in the +implementation. It means that the elements of `itr` may be accessed out of order and +the order in which `f` is called is implementation-defined. + !!! compat "Julia 1.2" `mapreduce` with multiple iterators requires Julia 1.2 or later. @@ -440,6 +444,9 @@ use non-associative operations like `-` because it is undefined whether `reduce( should be evaluated as `(1-2)-3` or `1-(2-3)`. Use [`foldl`](@ref) or [`foldr`](@ref) instead for guaranteed left or right associativity. +Known commutativity of the operation `op` such as `+` and `max` may be exploited in the +implementation. It means that the elements of `itr` may be accessed in out-of-order. + Some operations accumulate error. Parallelism will be easier if the reduction can be executed in groups. Future versions of Julia might change the algorithm. Note that the elements are not reordered if you use an ordered collection.