Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: what problem is NullBroadcasts solving #4

Open
Sbozzolo opened this issue Jan 31, 2025 · 2 comments
Open

Docs: what problem is NullBroadcasts solving #4

Sbozzolo opened this issue Jan 31, 2025 · 2 comments

Comments

@Sbozzolo
Copy link
Member

Sbozzolo commented Jan 31, 2025

(I know documentation is under construction)

The current documentation describes the package, but does really mention where/why one would use `NullBroadcasted.

It'd be useful to add a line to provide more motivation for the package.

This package defines NullBroadcasted(), which can be added to, subtracted from, or multiplied by any value in a broadcast expression without incurring a runtime performance penalty. This can be useful for X

@charleskawczynski
Copy link
Member

NullBroadcasts provides an elegant solution to summing/subtracting non-existing broadcasted objects in broadcast expressions, without a performance penalty. It will also allow us to skip kernel launches on simple increments, for example: @. x += NullBroadcasted(), which will result in Base.materialize!(dest, ::NullBroadcasted) = nothing (no cost, no reads/writes, no kernel launches, a no-op).

The original alternative we had in ClimaAtmos was to use something of the flavor @. x += zero(eltype(x)), but that means that we would be reading and writing to x for every point in space, in a useless operation. We don't want to pay for this. Enter NullBroadcasts.jl.

I guess we could show users how we plan to use it, if you think it's helpful. See, for example CliMA/ClimaAtmos.jl#3540.

@charleskawczynski
Copy link
Member

Also, this helps us avoid issues with operations like * and + that using zero would face:

julia> 0 * NaN
NaN

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

No branches or pull requests

2 participants