-
Notifications
You must be signed in to change notification settings - Fork 20
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
Return type of *
for x::Gray{Bool}
and real number
#148
Comments
As for multiplication ( |
The root of the problem is that julia> 0x1 + Gray{N0f8}(0)
Gray{Float32}(0.0f0) And the following is completely irrational: julia> true + Gray{Bool}(0)
Gray{N0f8}(1.0) It is obvious that the result of addition and subtraction between integers is an integer, and there is no advantage to julia> true + Gray{Bool}(1)
ERROR: ArgumentError: 2 is an integer in the range 0-255, but integer inputs are encoded with the N0f8
type, an 8-bit type representing 256 discrete values between 0 and 1.
Consider dividing your input values by 255, for example: Gray{N0f8}(2/255)
Or use `reinterpret(N0f8, x)` if `x` is a `UInt8`.
See the READMEs for FixedPointNumbers and ColorTypes for more information. Personally, I think the following seems relatively reasonable. However, it goes against the idea of treating julia> true + Gray{Bool}(1) # the `true` is a `Integer`
Gray{Float32}(2.0)
julia> Gray{Bool}(1) + Gray{Bool}(1) # similar to `Gray{N0f8}(1) + Gray{N0f8}(1)`
Gray{Bool}(false) At least, there is no reason to maintain the backward compatibility with respect to the julia> Gray{Bool}(1) + Gray{Bool}(1)
Gray{BigFloat}(2.0) |
Of course, it is obvious that the julia> Gray{N0f8}(1) + 0
Gray{Float32}(1.0f0)
julia> Gray24(1) + 0
Gray24(1.0N0f8) julia> Gray(1.0) / Gray{N0f8}(0.6)
Gray{Float64}(1.6666666666666667)
julia> Gray(1.0) / 0.6N0f8
ERROR: ArgumentError: N0f8 is an 8-bit type representing 256 values from 0.0 to 1.0; cannot represent 1.6666666 |
Proposalcf: #153 (comment)
🆙 : proposal for v0.10.0 |
LGTM. Are there any plans to support the other side of Current |
I added the cf. #153 (comment), #153 (comment)
There are several other cases, but the current tests for ColorVectorSpace are not so systematic to begin with.
You're right, but I think it's also non-intuitive to suddenly promote to |
Incidentally, my motivation for considering the return types and intermediate representations is to bring consistency to the new definition of However, the more essential issue is related to the relaxation from It is debatable what kind of rules are most preferable, but it is definitely beneficial to generalize the codes as much as possible and consolidate the rules in one place. |
I haven't made up my mind about what the return type should be if the definition of
one
for Colorant types is the real number1
. (cf. JuliaGraphics/ColorTypes.jl#235)I found an odd type promotion in the case study.
The text was updated successfully, but these errors were encountered: