-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Make broadcastable treat Char like Number
#40877
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
Conversation
|
In particular, note that julia> ndims('x')
0
julia> 'x'[] == 'x'
trueso I think we should have a |
|
Do we already have test coverage for broadcast operations with |
I believe that currently the only test is |
|
Would be good to add another test, just to be safe. |
done |
simeonschaub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first PR!
|
For me it's unintuitive that Char is a container. Having Char behave like a container makes it even easier than it already is to accidentally work on the wrong data type (a Char rather than a sequence of Chars). I would think indexability is mostly a historical artifact from its early origins as an Arraylike/Int, and it would be better to clean up the interface by removing the containerness in 2.0 rather than leaning into it by adding more containery features. (The same applies for numbers really.) What do you think? |
|
That comes up from time to time. It really is convenient to be able to treat a scalar like a 0-d array sometimes, so removing the methods strikes me as overly pedantic. |
Agreed, but having some things and not others be arraylike complicates the semantics (what is an atom vs a collection? is this like APL or not?). We can have an answer that's clear and flexible: treating scalars as atoms by default and using |
|
The tester_linux32 check failed. Is there anything I am supposed to do? I don't see how the problem is related to my PR. |
|
Yes, that failure can safely be ignored here. |
|
Shouldn't this have been |
This is my very first PR, so I hope I'm doing things right. It's motivated by a thread on Discourse, see here. stevengj suggested that I file this issue on GitHub.
Starting point is the observation that
Charseems to be the only plain-bits type for whichbroadcastablecallscollect(the default method, meant for collecting iterables). stevengj mentioned on Discourse thatCharonce was a subtype ofNumber, so maybe it was just forgotten to align the treatment forCharwithNumberwhenCharceased to be a subtype. This PR proposes to make this alignment.It turns out that it's not enough to define
broadcastable(x::Char) = x(same method as forNumber). One also needsgetindex(x, CartesianIndex()), which is not defined forChar(maybe again an omission). If one adds this, then everything seems to work. The entire test suite runs without problems. I've also added a test for thegetindexcall mentioned above. Note that there is already a@testset "broadcasting of Char"intest/char.jl.