-
Notifications
You must be signed in to change notification settings - Fork 33
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
support reinterpret from UIntX to Fixed{IntX, N} #96
Comments
If this is a problem with the redundancy, we can write it as: julia> reinterpret(Q0f15, signed(0x8123))
-0.99112Q0f15 I don't think the implicit conversion is good from the viewpoint of preventing bugs. On the other hand, I think there is still debate about the need for |
julia> a = [0x8123]
1-element Array{UInt16,1}:
0x8123
julia> reinterpret(Q0f15, a)
1-element reinterpret(Fixed{Int16,15}, ::Array{UInt16,1}):
-0.99112Q0f15
julia> @which reinterpret(Q0f15, a)
reinterpret(::Type{T}, a::A) where {T, N, S, A<:AbstractArray{S,N}} in Base at reinterpretarray.jl:14 |
It is documented that the behavior is different between "arrays" and others.
That conflicts with the error message. 😕
I beleve that Julia's Edit: |
By my reading, that only documents the fact that it is implemented for arrays and not for other types. That error message comes from the fact that it fails the "has 0 fields test" here. AFAICT that's not a property that is important other than for implementation.
That's not unreasonable. That said, I certainly don't feel strongly about this issue, to me it's a very niche issue and I can happily live with the status quo. |
In essence I agree with you. I didn't mean "preventing bugs" to be "type-safe". |
Just stumbled across this, via a headache with loaded images. I have a PR over on Julia to allow general conversions between bits types of the same size. Which would solve this entire class of annoyances. Happy to entertain ways to make it fool-proof. |
Update: The PR I mentioned above is integrated into Julia as of 1.10, so this functionality is now available via Base. |
At first glance, this appeared to be solved. In other words, previously, every downstream package did an explicit reinterpret because julia did not allow it. Now, downstream packages can do various reinterpretations, and that can cause compatibility bugs. Even though CI checks can prevent releasing the bugs, the ❌ sign makes the developers tired. Of course, that is the downstream package's own responsibility. |
Currently if you have a
UInt16
that you want to reinterpret as a signed fixed-point number thereinterpret
method here doesn't apply, so you get an error:Is it worth having another
reinterpret
method to handle this, or is it safer to have the user double-reinterpret? (e.g.reinterpret(Fixed{Int16, 15}, reinterpret(Int16, 0x8123))
)One proposed method would be:
Or we could even drop the requirement the
x
subtypesUnsigned
if we want to reinterpret more broadly.The text was updated successfully, but these errors were encountered: