Skip to content

Commit

Permalink
get rid of rcum_convert
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jan 17, 2018
1 parent b48095c commit d8ac226
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,6 @@ rcum_promote_type(op, ::Type{T}) where {T} = rcum_promote_type(op, T,T)
# any AbstractArray here, but it's not clear how that would be possible
rcum_promote_type(op, ::Type{Array{T,N}}) where {T,N} = Array{rcum_promote_type(op,T), N}

rcum_convert(::Type{T}, x) where {T} = convert(T,x)
rcum_convert(::Type{T}, c::Char) where {T <: AbstractString} = T(string(c))
# accumulate_pairwise slightly slower then accumulate, but more numerically
# stable in certain situations (e.g. sums).
# it does double the number of operations compared to accumulate,
Expand All @@ -768,7 +766,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
n = length(li)
n == 0 && return result
i1 = first(li)
@inbounds result[i1] = v1 = v[i1]
@inbounds result[i1] = v1 = reduce_first(op,v[i1])
n == 1 && return result
_accumulate_pairwise!(op, result, v, v1, i1+1, n-1)
return result
Expand Down Expand Up @@ -1022,7 +1020,7 @@ function accumulate!(op, B, A, dim::Integer)
# register usage and will be slightly faster
ind1 = inds_t[1]
@inbounds for I in CartesianIndices(tail(inds_t))
tmp = rcum_convert(eltype(B), A[first(ind1), I])
tmp = reduce_first(op, A[first(ind1), I])
B[first(ind1), I] = tmp
for i_1 = first(ind1)+1:last(ind1)
tmp = op(tmp, A[i_1, I])
Expand Down Expand Up @@ -1072,7 +1070,7 @@ end
# Copy the initial element in each 1d vector along dimension `dim`
ii = first(ind)
@inbounds for J in R2, I in R1
B[I, ii, J] = rcum_convert(eltype(B), A[I, ii, J])
B[I, ii, J] = reduce_first(op, A[I, ii, J])
end
# Accumulate
@inbounds for J in R2, i in first(ind)+1:last(ind), I in R1
Expand Down Expand Up @@ -1120,7 +1118,7 @@ function _accumulate1!(op, B, v1, A::AbstractVector, dim::Integer)
inds == linearindices(B) || throw(DimensionMismatch("linearindices of A and B don't match"))
dim > 1 && return copyto!(B, A)
i1 = inds[1]
cur_val = rcum_convert(eltype(B), v1)
cur_val = reduce_first(op, v1)
B[i1] = cur_val
@inbounds for i in inds[2:end]
cur_val = op(cur_val, A[i])
Expand Down

0 comments on commit d8ac226

Please sign in to comment.