-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.mathsMathematical functionsMathematical functions
Description
It seems that sum uses the naive sequential sum algorithm for generators. With large vectors, it eventually saturates, and yields an incorrect answer:
julia> N = 100000000; aa = rand(Float32, N);
julia> mean((x for x in aa))
0.16777216f0
julia> mean(aa)
0.500059f0I have a real-world case where it causes an alarmingly large difference:
julia> mean(skipmissing(Umat))
1.0638367f0 V
julia> mean(collect(skipmissing(Umat)))
3.1320891f0 VAs @simonbyrne pointed out on discourse, sum(::Array) already uses a smarter algorithm. It could presumably be used for generators, too.
nacnudus and cossio
Metadata
Metadata
Assignees
Labels
foldsum, maximum, reduce, foldl, etc.sum, maximum, reduce, foldl, etc.mathsMathematical functionsMathematical functions