Skip to content

Commit 29bc9df

Browse files
committed
Make _truncerror_impl more GPU friendly
1 parent b3a5b53 commit 29bc9df

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

src/implementations/truncation.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,8 @@ function _truncerr_impl(values::AbstractVector, I; atol::Real = 0, rtol::Real =
9696
# fast path to avoid checking all values
9797
ϵᵖ Nᵖ && return Base.OneTo(0)
9898

99-
truncerrᵖ = zero(real(eltype(values)))
100-
rank = length(values)
101-
for i in reverse(I)
102-
truncerrᵖ += by(values[i])
103-
truncerrᵖ ϵᵖ && break
104-
rank -= 1
105-
end
106-
99+
truncerrᵖ_array = cumsum(map(by, values[reverse(I)]))
100+
rank = length(values) - (findfirst(truncerrᵖ -> truncerrᵖ ϵᵖ, truncerrᵖ_array) - 1)
107101
return Base.OneTo(rank)
108102
end
109103

0 commit comments

Comments
 (0)