@@ -740,8 +740,6 @@ rcum_promote_type(op, ::Type{T}) where {T} = rcum_promote_type(op, T,T)
740
740
# any AbstractArray here, but it's not clear how that would be possible
741
741
rcum_promote_type (op, :: Type{Array{T,N}} ) where {T,N} = Array{rcum_promote_type (op,T), N}
742
742
743
- rcum_convert (:: Type{T} , x) where {T} = convert (T,x)
744
- rcum_convert (:: Type{T} , c:: Char ) where {T <: AbstractString } = T (string (c))
745
743
# accumulate_pairwise slightly slower then accumulate, but more numerically
746
744
# stable in certain situations (e.g. sums).
747
745
# it does double the number of operations compared to accumulate,
@@ -768,7 +766,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
768
766
n = length (li)
769
767
n == 0 && return result
770
768
i1 = first (li)
771
- @inbounds result[i1] = v1 = v[i1]
769
+ @inbounds result[i1] = v1 = reduce_first (op, v[i1])
772
770
n == 1 && return result
773
771
_accumulate_pairwise! (op, result, v, v1, i1+ 1 , n- 1 )
774
772
return result
@@ -1022,7 +1020,7 @@ function accumulate!(op, B, A, dim::Integer)
1022
1020
# register usage and will be slightly faster
1023
1021
ind1 = inds_t[1 ]
1024
1022
@inbounds for I in CartesianIndices (tail (inds_t))
1025
- tmp = rcum_convert ( eltype (B) , A[first (ind1), I])
1023
+ tmp = reduce_first (op , A[first (ind1), I])
1026
1024
B[first (ind1), I] = tmp
1027
1025
for i_1 = first (ind1)+ 1 : last (ind1)
1028
1026
tmp = op (tmp, A[i_1, I])
@@ -1072,7 +1070,7 @@ end
1072
1070
# Copy the initial element in each 1d vector along dimension `dim`
1073
1071
ii = first (ind)
1074
1072
@inbounds for J in R2, I in R1
1075
- B[I, ii, J] = rcum_convert ( eltype (B) , A[I, ii, J])
1073
+ B[I, ii, J] = reduce_first (op , A[I, ii, J])
1076
1074
end
1077
1075
# Accumulate
1078
1076
@inbounds for J in R2, i in first (ind)+ 1 : last (ind), I in R1
@@ -1120,7 +1118,7 @@ function _accumulate1!(op, B, v1, A::AbstractVector, dim::Integer)
1120
1118
inds == linearindices (B) || throw (DimensionMismatch (" linearindices of A and B don't match" ))
1121
1119
dim > 1 && return copyto! (B, A)
1122
1120
i1 = inds[1 ]
1123
- cur_val = rcum_convert ( eltype (B) , v1)
1121
+ cur_val = reduce_first (op , v1)
1124
1122
B[i1] = cur_val
1125
1123
@inbounds for i in inds[2 : end ]
1126
1124
cur_val = op (cur_val, A[i])
0 commit comments