Skip to content

rewrite make_zero! and remake_zero! with ntuple over fields#2607

Merged
vchuravy merged 1 commit intomainfrom
vc/remake_zero!
Sep 26, 2025
Merged

rewrite make_zero! and remake_zero! with ntuple over fields#2607
vchuravy merged 1 commit intomainfrom
vc/remake_zero!

Conversation

@vchuravy
Copy link
Member

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2025

Benchmark Results

main d4f6bf6... main / d4f6bf6...
basics/make_zero/namedtuple 0.0511 ± 0.0013 μs 0.0508 ± 0.0022 μs 1.01 ± 0.051
basics/make_zero/struct 0.264 ± 0.0059 μs 0.253 ± 0.0054 μs 1.04 ± 0.032
basics/overhead 5.26 ± 0.92 ns 4.34 ± 0.01 ns 1.21 ± 0.21
basics/remake_zero!/namedtuple 0.299 ± 0.0065 μs 0.234 ± 0.0042 μs 1.28 ± 0.036
basics/remake_zero!/struct 0.307 ± 0.0076 μs 0.233 ± 0.0034 μs 1.32 ± 0.038
time_to_load 1.27 ± 0.008 s 1.27 ± 0.0086 s 1 ± 0.0092

Benchmark Plots

A plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/18039430455/artifacts/4115489625.

@codecov
Copy link

codecov bot commented Sep 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.30%. Comparing base (8da98df) to head (d4f6bf6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2607   +/-   ##
=======================================
  Coverage   75.30%   75.30%           
=======================================
  Files          57       57           
  Lines       17751    17751           
=======================================
  Hits        13368    13368           
  Misses       4383     4383           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from vc/format_typeutils to main September 22, 2025 18:24
end
push!(seen, prev)
for i in 1:nf
ntuple(Val(nf)) do i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly this feels like it should become a generated function (and we can also therefore conditionally create the seen dict if there is > 1 potentially aliasing piece of data)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ntuple is a generated function, just one that is limited in scope. I still prefer this over the headache that generated function bring with them otherwise.

I also don't think it would be unreasonable for a user to provide their own make_zero function / remake_zero! function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we definitely want user definable overrides. I'm just dreaming of a world where we don't need the explicit specialization for make_zero(Array) in addition to make_zero(Array, seen).

in any case we can figure this out later, this is already clearly a good change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also sadly while we might be able to use a generated function, that would only allow us to guard against recursion in the type-domain and not recursion in the value domain :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps but things like make_zero of a tuple of floats is sufficiently common that we really want it to use the right thing without the is check

@vchuravy vchuravy force-pushed the vc/remake_zero! branch 2 times, most recently from 3e17451 to 8f268dc Compare September 25, 2025 15:01
@vchuravy vchuravy merged commit 297c7c7 into main Sep 26, 2025
43 of 44 checks passed
@vchuravy vchuravy deleted the vc/remake_zero! branch September 26, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants