Skip to content

Commit 696c916

Browse files
committed
get rid of rcum_convert
1 parent 65dff7a commit 696c916

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

base/multidimensional.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,6 @@ rcum_promote_type(op, ::Type{T}) where {T} = rcum_promote_type(op, T,T)
696696
# any AbstractArray here, but it's not clear how that would be possible
697697
rcum_promote_type(op, ::Type{Array{T,N}}) where {T,N} = Array{rcum_promote_type(op,T), N}
698698

699-
rcum_convert(::Type{T}, x) where {T} = convert(T,x)
700-
rcum_convert(::Type{T}, c::Char) where {T <: AbstractString} = T(string(c))
701699
# accumulate_pairwise slightly slower then accumulate, but more numerically
702700
# stable in certain situations (e.g. sums).
703701
# it does double the number of operations compared to accumulate,
@@ -724,7 +722,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
724722
n = length(li)
725723
n == 0 && return result
726724
i1 = first(li)
727-
@inbounds result[i1] = v1 = v[i1]
725+
@inbounds result[i1] = v1 = reduce_first(op,v[i1])
728726
n == 1 && return result
729727
_accumulate_pairwise!(op, result, v, v1, i1+1, n-1)
730728
return result
@@ -978,7 +976,7 @@ function accumulate!(op, B, A, dim::Integer)
978976
# register usage and will be slightly faster
979977
ind1 = inds_t[1]
980978
@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])
982980
B[first(ind1), I] = tmp
983981
for i_1 = first(ind1)+1:last(ind1)
984982
tmp = op(tmp, A[i_1, I])
@@ -1028,7 +1026,7 @@ end
10281026
# Copy the initial element in each 1d vector along dimension `dim`
10291027
ii = first(ind)
10301028
@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])
10321030
end
10331031
# Accumulate
10341032
@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)
10761074
inds == linearindices(B) || throw(DimensionMismatch("linearindices of A and B don't match"))
10771075
dim > 1 && return copyto!(B, A)
10781076
i1 = inds[1]
1079-
cur_val = rcum_convert(eltype(B), v1)
1077+
cur_val = reduce_first(op, v1)
10801078
B[i1] = cur_val
10811079
@inbounds for i in inds[2:end]
10821080
cur_val = op(cur_val, A[i])

0 commit comments

Comments
 (0)