Skip to content

Commit d8ac226

Browse files
committed
get rid of rcum_convert
1 parent b48095c commit d8ac226

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
@@ -740,8 +740,6 @@ rcum_promote_type(op, ::Type{T}) where {T} = rcum_promote_type(op, T,T)
740740
# any AbstractArray here, but it's not clear how that would be possible
741741
rcum_promote_type(op, ::Type{Array{T,N}}) where {T,N} = Array{rcum_promote_type(op,T), N}
742742

743-
rcum_convert(::Type{T}, x) where {T} = convert(T,x)
744-
rcum_convert(::Type{T}, c::Char) where {T <: AbstractString} = T(string(c))
745743
# accumulate_pairwise slightly slower then accumulate, but more numerically
746744
# stable in certain situations (e.g. sums).
747745
# it does double the number of operations compared to accumulate,
@@ -768,7 +766,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
768766
n = length(li)
769767
n == 0 && return result
770768
i1 = first(li)
771-
@inbounds result[i1] = v1 = v[i1]
769+
@inbounds result[i1] = v1 = reduce_first(op,v[i1])
772770
n == 1 && return result
773771
_accumulate_pairwise!(op, result, v, v1, i1+1, n-1)
774772
return result
@@ -1022,7 +1020,7 @@ function accumulate!(op, B, A, dim::Integer)
10221020
# register usage and will be slightly faster
10231021
ind1 = inds_t[1]
10241022
@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])
10261024
B[first(ind1), I] = tmp
10271025
for i_1 = first(ind1)+1:last(ind1)
10281026
tmp = op(tmp, A[i_1, I])
@@ -1072,7 +1070,7 @@ end
10721070
# Copy the initial element in each 1d vector along dimension `dim`
10731071
ii = first(ind)
10741072
@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])
10761074
end
10771075
# Accumulate
10781076
@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)
11201118
inds == linearindices(B) || throw(DimensionMismatch("linearindices of A and B don't match"))
11211119
dim > 1 && return copyto!(B, A)
11221120
i1 = inds[1]
1123-
cur_val = rcum_convert(eltype(B), v1)
1121+
cur_val = reduce_first(op, v1)
11241122
B[i1] = cur_val
11251123
@inbounds for i in inds[2:end]
11261124
cur_val = op(cur_val, A[i])

0 commit comments

Comments
 (0)