JuliaSmoothOptimizers / PartitionedVectors.jl

Other
8 stars 1 forks source link

Remove allocations from in-place broadcasted operations #19

Closed paraynaud closed 1 year ago

paraynaud commented 1 year ago

@dpo huge news, I successfully removed allocations from inplace broadcasted operations!!

using BenchmarkTools
using StatsBase
using PartitionedVectors

N = 5000 #elements
n = 20000
nie = 15
element_variables =
  vcat(map((i -> sample(1:n, nie, replace = false)), 1:N))

pv1 = PartitionedVector(element_variables; n)
pv1 .= 1
pv2 = PartitionedVector(element_variables; n)
pv2 .= 2
res = PartitionedVector(element_variables; n)

@benchmark res .= pv1 .+ pv2 .* 2
# BenchmarkTools.Trial: 10000 samples with 1 evaluation.
#  Range (min … max):  78.800 μs … 374.800 μs  ┊ GC (min … max): 0.00% … 0.00%
#  Time  (median):     82.300 μs               ┊ GC (median):    0.00%
#  Time  (mean ± σ):   92.795 μs ±  28.771 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%
#   ▄█▂▁▁    ▂▁▂      ▁                                          ▁
#   █████▇█▇▇███▇▆▆▆▅▆███▇▇▇▇▇▇▆▇▆▇▆▅▅▆▅▆▆▅▆▅▅▅▇█▇▇▇▇▆▅▄▅▆▆▆▅▅▄▅ █
#   78.8 μs       Histogram: log(frequency) by time       209 μs <
#  Memory estimate: 128 bytes, allocs estimate: 4.

edit: I didn't implement what I taked yesterday about inplace basic operations for element vectors.

codecov[bot] commented 1 year ago

Codecov Report

Base: 98.96% // Head: 98.95% // Decreases project coverage by -0.00% :warning:

Coverage data is based on head (c60e31c) compared to base (c55e6b0). Patch coverage: 100.00% of modified lines in pull request are covered.

:exclamation: Current head c60e31c differs from pull request most recent head 8923807. Consider uploading reports for the commit 8923807 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #19 +/- ## ========================================== - Coverage 98.96% 98.95% -0.01% ========================================== Files 6 6 Lines 193 192 -1 ========================================== - Hits 191 190 -1 Misses 2 2 ``` | [Impacted Files](https://codecov.io/gh/JuliaSmoothOptimizers/PartitionedVectors.jl/pull/19?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaSmoothOptimizers) | Coverage Δ | | |---|---|---| | [src/broadcast.jl](https://codecov.io/gh/JuliaSmoothOptimizers/PartitionedVectors.jl/pull/19/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaSmoothOptimizers#diff-c3JjL2Jyb2FkY2FzdC5qbA==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaSmoothOptimizers). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaSmoothOptimizers)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.