Skip to content
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

Enhance promotion of SimpleRatio to work with FixedPointNumbers #18

Closed
mkitti opened this issue May 5, 2021 · 2 comments · Fixed by #19
Closed

Enhance promotion of SimpleRatio to work with FixedPointNumbers #18

mkitti opened this issue May 5, 2021 · 2 comments · Fixed by #19

Comments

@mkitti
Copy link

mkitti commented May 5, 2021

Could we enhance the promotion of SimpleRatio so that it can work with FixedPointNumbers? Many images are encoded in FixedPointNumbers and this would be useful to apply Interpolations to them directly.

Minimum Working Example:

julia> using Ratios, FixedPointNumbers

julia> SimpleRatio(5,3) * 0.035N0f8
ERROR: promotion of types SimpleRatio{Int64} and N0f8 failed to change any arguments
Stacktrace:
 [1] error(::String, ::String, ::String)
   @ Base .\error.jl:42
 [2] sametype_error(input::Tuple{SimpleRatio{Int64}, N0f8})
   @ Base .\promotion.jl:316
 [3] not_sametype(x::Tuple{SimpleRatio{Int64}, N0f8}, y::Tuple{SimpleRatio{Int64}, N0f8})
   @ Base .\promotion.jl:310
 [4] promote
   @ .\promotion.jl:293 [inlined]
 [5] *(x::SimpleRatio{Int64}, y::N0f8)
   @ Base .\promotion.jl:322
 [6] top-level scope
   @ REPL[51]:1

Motivating Example:
xref: JuliaMath/Interpolations.jl#413
cc: @johnnychen94

julia> using FixedPointNumbers, Interpolations

julia> r = reinterpret(N0f8,[0x73, 0x94, 0x66, 0x1e])
4-element reinterpret(N0f8, ::Vector{UInt8}):
 0.451N0f8
 0.58N0f8
 0.4N0f8
 0.118N0f8

julia> itp = interpolate(r, BSpline(Quadratic(Flat(OnGrid()))));

julia> itp
4-element interpolate(OffsetArray(::Array{N0f8,1}, 0:5), BSpline(Quadratic(Flat(OnGrid())))) with element type Float64:
Error showing value of type Interpolations.BSplineInterpolation{Float64, 1, OffsetArrays.OffsetVector{N0f8, Vector{N0f8}}, BSpline{Quadratic{Flat{OnGrid}}}, Tuple{Base.OneTo{Int64}}}:
ERROR: promotion of types Ratios.SimpleRatio{Int64} and N0f8 failed to change any arguments
Stacktrace:
  [1] error(::String, ::String, ::String)
    @ Base .\error.jl:42
  [2] sametype_error(input::Tuple{Ratios.SimpleRatio{Int64}, N0f8})
    @ Base .\promotion.jl:316
  [3] not_sametype(x::Tuple{Ratios.SimpleRatio{Int64}, N0f8}, y::Tuple{Ratios.SimpleRatio{Int64}, N0f8})
    @ Base .\promotion.jl:310
  [4] promote
    @ .\promotion.jl:293 [inlined]
  [5] *(x::Ratios.SimpleRatio{Int64}, y::N0f8)
    @ Base .\promotion.jl:322
@mkitti
Copy link
Author

mkitti commented Aug 7, 2021

@timholy any thoughts on the best way to proceed with this?

@timholy
Copy link
Owner

timholy commented Aug 7, 2021

I'm surprised this hasn't come up before! See #19 (feel free to review and let me know what you don't like).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants