-
-
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
result types of bool matrix operations #2980
Comments
Regarding arithmetic, I can see three options.
|
I think that the following makes the most sense to me:
Currently, arrays of bools are the only ones for which vectorized arrays don't preserve the size and type of their operands, which is a bit inconsistent, but probably much more useful than the alternative of doing Int arithmetic and then casting back to Bool – if you want that, you can always express it more clearly using bitwise operators. Side issue: can we replace |
Agree on the arithmetic, since it's what we do for all other integer types. It'd be nice to get rid of
I don't yet see a way around this. |
One option would be to introduce pure imaginary numbers, |
Of course, that proposal doesn't actually simplify the type hierarchy, but it does generalize it to be more useful. |
fixes Gunnar's issue 5, part of #2980
Amusingly my suggestion to have false * x = zero(typeof(x)) and true * x = x is a perfect fit with the desire to have Inf * complex(false, true) = complex(0.0, Inf). |
I did notice that, and it does make me stop and think. But my current impression is that it's mostly a coincidence. |
Thanks, Jeff. I think the right approach for supporting things like matmul in GF(2) is to make a new type whose addition and multiplication are appropriate to that field. |
This change requires giving multiplition by Bools special behavior. Approximately, `true * x = x` and `false * x = zero(x)`, but a bit complicated for the sake of promotion, the only non-trivial example of which is `Bool * MathConst`, which is promoted to Float64. Idea originally due to @GunnarFarneback: https://groups.google.com/forum/#!topic/julia-dev/VkGrqnrAdaY #2980 #3728
This change requires giving multiplition by Bools special behavior. Approximately, `true * x = x` and `false * x = zero(x)`, but a bit complicated for the sake of promotion, the only non-trivial example of which is `Bool * MathConst`, which is promoted to Float64. Idea originally due to @GunnarFarneback: https://groups.google.com/forum/#!topic/julia-dev/VkGrqnrAdaY #2980 #3728
Gunnar's issues 5 and 6:
We have
true+true === 2
buttrue*true === true
. Maybe it's best just to give anInt
for all bool arithmetic.Then there is a further problem, that functions like
dot
and matrix*
use the input type to determine the output type, but forBool
this is wrong. One thing that works isto be pedantic.
The text was updated successfully, but these errors were encountered: