-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use Int8(1) instead of true in I #29596
Conversation
I think that hard zeros are appropriate for the identity matrix. |
I don't really love it. Couldn't we just change the behavior of |
Could you come up with an example that actually uses julia> false*I*[Inf, NaN]
2-element Array{Float64,1}:
0.0
0.0 Do you really multiply the identity with a Boolean? It seems like a pretty rare operation to me.
I think that would be a bit odd if julia> I[2,1]
false
julia> I[1,1]
true and I think it's odd that the identity doesn't contain zeros and ones. Notice that for the first many years, the element type of |
I think that
is really what you'd expect from an identity matrix. Your changed identity matrix does not act by identity modulo If users are surprised by the display, i.e. that a dense matrix acting by identity on vectors of Floats containing If it is instead decided that off-diagonal zeros must be soft, for consistency with BLAS libraries, and return an all-NaN vector when multiplied to a Inf/NaN-containing vector, then that is a very compelling reason to do this change (that has nothing to do with pretty printing). PS. No, I do not have examples where anybody should rely on this. |
Is this more of a symptom of the fact that Basically... we left |
My understanding is that this was motivated by #5468 |
Cool, thanks for the ref. #5468 went to the effort of adding a check of the sign to give |
Maybe we could print Bools as 0 and 1 when the typeinfo context allows it? |
That would be confusing for people who really want Boolean values and not numbers. |
@nalimilan I sympathise - but it has to be said, given we have |
I don't think the following would be very confusing, the type is prominently stated. It is rather an improvement in readability.
|
On the other hand,
So yes, we have I'd still like the more terse output of Bool-arrays as 0/1. |
Note that we already print some integer types in a way that doesn't round trip to the same type, e.g.: julia> Int8(123)
123
julia> rand(Int8, 5, 5)
5×5 Array{Int8,2}:
-18 -84 -101 57 65
80 89 -101 107 -68
15 -88 -14 110 -51
-21 -93 100 21 -83
-86 -41 -109 7 -80 If you want the actual same value back you can do |
True, but that seems like more of an unfortunate consequence of not having literals for integer types like |
This is a very good point. They are not generally interchangeable, so we should not print them as though they are. |
This is fair point but the thing is that it's struck me many times for entirely different reasons that the printing of boolean vectors and matrices is really annoying and verbose, so I already want to not print them using the standard input syntax for |
Just curious about the negative feedback here since I considered this change extremely small. For a long time So, I'd like to hear why people are sceptical here. (And please keep the strong zero property out of the discussion because it never played a role in the first place). Changing the printing of Boolean matrices might also be a fine solution here but I'm still curious why this is considered so bad. |
The only remaining thing that occurs to me is that sometimes you want to study F2 - aka GF(2) - aka But that’s pretty esoteric for many users so not sure - this PR has other small advantages and we don’t actually have a number type that faithfully represents GF(2) at the moment. |
Because it goes from using an element type that is explicitly intended to be "weak" in the sense of always yielding to others when promoted to one that just happens to be weaker than most other types most of the time because it just happens to print in a way that people prefer. That's a lot of "just happens"—which bothers me. If people find the printing of |
Agree, it seems much easier to read to print Bool matrices and vectors with 0 and 1. |
@andreasnoack Am I correct in understanding here that you don't object to any of the behaviors of |
@mbauman Yes, the idea was just to make the identity matrix have number elements instead of word elements and to do that with a minimal change that wouldn't have any (real) behavioral effects. As mentioned in the top post, I'd be very surprised if this PR would break any user code. I didn't consider the possibility of changing the printing of julia> I[1,1]
true |
Superseded by #30575 |
This is a slightly modified version of #24396 to make
I
useInt8
instead ofBool
. For almost all real use cases, I would expect the behavior to be unaffected by this change sinceInt8
andBool
have the same promotion behavior in almost all the relevant cases. In particular, they have the same promotion behavior in the cases mentioned in #24396.The main motivation for this change is that
is not really what you'd expect from an identity matrix. With this change, it would instead be
I'd be interested in a PkgEval run of this since I wouldn't expect any user code to break from this change.