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

Overload broadcasting behavour #263

Closed
oxinabox opened this issue Jan 2, 2025 · 3 comments · Fixed by #264
Closed

Overload broadcasting behavour #263

oxinabox opened this issue Jan 2, 2025 · 3 comments · Fixed by #264
Labels
enhancement New feature or request ⭐✨ Quality ✨⭐ QA, cleaning, testing, CIs

Comments

@oxinabox
Copy link

oxinabox commented Jan 2, 2025

Target functionality

I often find myself writing functions that take a Model and either s Species or a Reaction etc.
And I want to broadcast this across a list of reactions.
foo.(model, rs)

Optional: Suggestions for implementation

Broadcast.broadcastable(x::Model) = Ref(x)
Broadcast.broadcastable(x::Species) = Ref(x)
Broadcast.broadcastable(x::Reaction) = Ref(x)

etc

@exaexa
Copy link
Collaborator

exaexa commented Jan 2, 2025

oh nice so this is the way to avoid writing Ref everywhere that I was looking for... :D I'll try to do asap, if you have any working code please feel free to PR even if half-baked or so.

Q: Is there some docs that guarantees how supported/sustainable/portable this is w.r.t. julia stdlib? The docs here https://docs.julialang.org/en/v1/manual/interfaces/#man-interfaces-broadcasting are the only authoritative ones, right? If I get it right, these basically say that your oneliners (one per struct type) are completely sufficient, right?

@exaexa exaexa added enhancement New feature or request ⭐✨ Quality ✨⭐ QA, cleaning, testing, CIs labels Jan 2, 2025
@oxinabox
Copy link
Author

oxinabox commented Jan 2, 2025

This is indeed part of the julia public API.
There potentially is some suggestion that it should be written:
Broadcast.broadcastable(x::Model) = (x,)
but it is much of a muchness

You can also do it with a union

Broadcast.broadcastable(x:Union{Model, Species,Reaction,...}) = Ref(x)

@exaexa
Copy link
Collaborator

exaexa commented Jan 5, 2025

@oxinabox I'll release this shortly, dependency for this should be 1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ⭐✨ Quality ✨⭐ QA, cleaning, testing, CIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants