JuliaML / LossFunctions.jl

Julia package of loss functions for machine learning.
https://juliaml.github.io/LossFunctions.jl/stable
Other
148 stars 34 forks source link

Improve aggregation speeds by using `eachindex` instead of `iterate` #173

Closed MilesCranmer closed 11 months ago

MilesCranmer commented 11 months ago

This changes from e.g.,

  sum(loss(ŷ, y) for (ŷ, y) in zip(outputs, targets))

to

  sum(i -> loss(outputs[i], targets[i]), eachindex(outputs, targets))

which improves speeds by ~3.5x. Fixes https://github.com/JuliaML/LossFunctions.jl/issues/172