@@ -696,8 +696,6 @@ rcum_promote_type(op, ::Type{T}) where {T} = rcum_promote_type(op, T,T)
696
696
# any AbstractArray here, but it's not clear how that would be possible
697
697
rcum_promote_type (op, :: Type{Array{T,N}} ) where {T,N} = Array{rcum_promote_type (op,T), N}
698
698
699
- rcum_convert (:: Type{T} , x) where {T} = convert (T,x)
700
- rcum_convert (:: Type{T} , c:: Char ) where {T <: AbstractString } = T (string (c))
701
699
# accumulate_pairwise slightly slower then accumulate, but more numerically
702
700
# stable in certain situations (e.g. sums).
703
701
# it does double the number of operations compared to accumulate,
@@ -724,7 +722,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
724
722
n = length (li)
725
723
n == 0 && return result
726
724
i1 = first (li)
727
- @inbounds result[i1] = v1 = v[i1]
725
+ @inbounds result[i1] = v1 = reduce_first (op, v[i1])
728
726
n == 1 && return result
729
727
_accumulate_pairwise! (op, result, v, v1, i1+ 1 , n- 1 )
730
728
return result
@@ -978,7 +976,7 @@ function accumulate!(op, B, A, dim::Integer)
978
976
# register usage and will be slightly faster
979
977
ind1 = inds_t[1 ]
980
978
@inbounds for I in CartesianIndices (tail (inds_t))
981
- tmp = rcum_convert ( eltype (B) , A[first (ind1), I])
979
+ tmp = reduce_first (op , A[first (ind1), I])
982
980
B[first (ind1), I] = tmp
983
981
for i_1 = first (ind1)+ 1 : last (ind1)
984
982
tmp = op (tmp, A[i_1, I])
@@ -1028,7 +1026,7 @@ end
1028
1026
# Copy the initial element in each 1d vector along dimension `dim`
1029
1027
ii = first (ind)
1030
1028
@inbounds for J in R2, I in R1
1031
- B[I, ii, J] = rcum_convert ( eltype (B) , A[I, ii, J])
1029
+ B[I, ii, J] = reduce_first (op , A[I, ii, J])
1032
1030
end
1033
1031
# Accumulate
1034
1032
@inbounds for J in R2, i in first (ind)+ 1 : last (ind), I in R1
@@ -1076,7 +1074,7 @@ function _accumulate1!(op, B, v1, A::AbstractVector, dim::Integer)
1076
1074
inds == linearindices (B) || throw (DimensionMismatch (" linearindices of A and B don't match" ))
1077
1075
dim > 1 && return copyto! (B, A)
1078
1076
i1 = inds[1 ]
1079
- cur_val = rcum_convert ( eltype (B) , v1)
1077
+ cur_val = reduce_first (op , v1)
1080
1078
B[i1] = cur_val
1081
1079
@inbounds for i in inds[2 : end ]
1082
1080
cur_val = op (cur_val, A[i])
0 commit comments