@@ -685,16 +685,6 @@ _iterable(v) = Iterators.repeated(v)
685
685
end
686
686
end
687
687
688
- # #
689
-
690
- # see discussion in #18364 ... we try not to widen type of the resulting array
691
- # from cumsum or cumprod, but in some cases (+, Bool) we may not have a choice.
692
- rcum_promote_type (op, :: Type{T} , :: Type{S} ) where {T,S} = promote_op (op, T, S)
693
- rcum_promote_type (op, :: Type{T} ) where {T} = rcum_promote_type (op, T,T)
694
-
695
- # handle sums of Vector{Bool} and similar. it would be nice to handle
696
- # any AbstractArray here, but it's not clear how that would be possible
697
- rcum_promote_type (op, :: Type{Array{T,N}} ) where {T,N} = Array{rcum_promote_type (op,T), N}
698
688
699
689
# accumulate_pairwise slightly slower then accumulate, but more numerically
700
690
# stable in certain situations (e.g. sums).
@@ -729,7 +719,7 @@ function accumulate_pairwise!(op::Op, result::AbstractVector, v::AbstractVector)
729
719
end
730
720
731
721
function accumulate_pairwise (op, v:: AbstractVector{T} ) where T
732
- out = similar (v, rcum_promote_type (op, T))
722
+ out = similar (v, promote_op (op, T))
733
723
return accumulate_pairwise! (op, out, v)
734
724
end
735
725
@@ -774,7 +764,7 @@ julia> cumsum(a,2)
774
764
```
775
765
"""
776
766
function cumsum (A:: AbstractArray{T} , dim:: Integer ) where T
777
- out = similar (A, rcum_promote_type (+ , T))
767
+ out = similar (A, promote_op (+ , T))
778
768
cumsum! (out, A, dim)
779
769
end
780
770
@@ -908,7 +898,7 @@ julia> accumulate(+, fill(1, 3, 3), 2)
908
898
```
909
899
"""
910
900
function accumulate (op, A, dim:: Integer )
911
- out = similar (A, rcum_promote_type (op, eltype (A)))
901
+ out = similar (A, promote_op (op, eltype (A)))
912
902
accumulate! (op, out, A, dim)
913
903
end
914
904
@@ -1057,7 +1047,7 @@ julia> accumulate(min, 0, [1,2,-1])
1057
1047
```
1058
1048
"""
1059
1049
function accumulate (op, v0, x:: AbstractVector )
1060
- T = rcum_promote_type (op, typeof (v0), eltype (x))
1050
+ T = promote_op (op, typeof (v0), eltype (x))
1061
1051
out = similar (x, T)
1062
1052
accumulate! (op, out, v0, x)
1063
1053
end
0 commit comments