From 51c3485d5f760d931f410acbfac0f4d760c0d27f Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 24 Jun 2020 17:23:39 -0700 Subject: [PATCH 1/2] 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 c73caaeac7a97..57d5169e9f862 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 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. From 97a65ca9c977d5112ad0d073308ccc6958e52035 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 25 Jun 2020 13:51:57 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Stefan Karpinski --- base/reduce.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/reduce.jl b/base/reduce.jl index 57d5169e9f862..5c7b8b9f1088b 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -271,7 +271,7 @@ intermediate collection needs to be created. See documentation for [`reduce`](@r [`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 +implementation. This 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" @@ -445,7 +445,7 @@ 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 out of order. +implementation. This means that the elements of `itr` may be accessed 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