1- function _same_length (a) end
2- function _same_length (a, b, c:: Vararg{Any,N} ) where {N}
1+ _check_same_length (:: Any ) = nothing
2+
3+ function _check_same_length (a, b, c:: Vararg{Any,N} ) where {N}
34 if length (a) != length (b)
45 throw (
56 DimensionMismatch (
6- " one array has length $(length (a)) which does not match the length of the next one, $(length (b)) ." ,
7+ " one array has length $(length (a)) which does not match the " *
8+ " length of the next one, $(length (b)) ." ,
79 ),
810 )
911 end
10- return _same_length (b, c... )
12+ return _check_same_length (b, c... )
1113end
14+
1215reduce_op (op:: AddSubMul ) = add_sub_op (op)
13- reduce_op (op:: typeof (add_dot)) = +
16+
17+ reduce_op (:: typeof (add_dot)) = +
18+
1419neutral_element (:: typeof (+ ), T:: Type ) = zero (T)
20+
1521map_op (:: AddSubMul ) = *
22+
1623map_op (:: typeof (add_dot)) = LinearAlgebra. dot
24+
1725function promote_map_reduce (op:: Function , args:: Vararg{Any,N} ) where {N}
18- return T =
19- promote_operation (op, promote_operation (map_op (op), args... ), args... )
26+ return promote_operation (
27+ op,
28+ promote_operation (map_op (op), args... ),
29+ args... ,
30+ )
2031end
2132
2233function fused_map_reduce (op:: F , args:: Vararg{Any,N} ) where {F<: Function ,N}
23- _same_length (args... )
34+ _check_same_length (args... )
2435 T = promote_map_reduce (op, eltype .(args)... )
2536 accumulator = neutral_element (reduce_op (op), T)
2637 buffer = buffer_for (op, T, eltype .(args)... )
@@ -30,11 +41,12 @@ function fused_map_reduce(op::F, args::Vararg{Any,N}) where {F<:Function,N}
3041 end
3142 return accumulator
3243end
44+
3345function operate (:: typeof (sum), a:: AbstractArray )
3446 return mapreduce (
3547 identity,
3648 add!!,
37- a,
49+ a;
3850 init = zero (promote_operation (+ , eltype (a), eltype (a))),
3951 )
4052end
0 commit comments