JuliaMath / JuliaMath/Interpolations.jl
promote FixedPointNumber to float when necessary
- Dominant language
- Julia
- Stars
- 575
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
JuliaImages widely uses `FixedPointNumbers.N0f8`, which is internally an `UInt8`, to represent [0,1] range. It seems that `interpolate` fails to promote the datatype for some interpolation types:
```julia
using FixedPointNumbers, Interpolations
interpolate(rand(N0f8, 4, 4), BSpline(Quadratic(Flat(OnGrid()))))
# ERROR: ArgumentError: N0f8 is an 8-bit type representing 256 values from 0.0 to 1.0; cannot represent 1.1045751633986929
float(N0f8) # Float32
```
error stack
```julia
julia> itp = interpolate(rand(N0f8, 4, 4), BSpline(Quadratic(Flat(OnGrid()))))
ERROR: ArgumentError: N0f8 is an 8-bit type representing 256 values from 0.0 to 1.0; cannot represent 1.1045751633986929
Stacktrace:
[1] throw_converterror(#unused#::Type{N0f8}, x::Float64)
@ FixedPointNumbers ~/.julia/packages/FixedPointNumbers/HAGk2/src/FixedPointNumbers.jl:326
[2] _convert
@ ~/.julia/packages/FixedPointNumbers/HAGk2/src/normed.jl:76 [inlined]
[3] FixedPoint
@ ~/.julia/packages/FixedPointNumbers/HAGk2/src/FixedPointNumbers.jl:58 [inlined]
[4] convert
@ ./number.jl:7 [inlined]
[5] setindex!
@ ./array.jl:841 [inlined]
[6] setindex!
@ ./multidimensional.jl:639 [inlined]
[7] _A_ldiv_B_md!(dest::Matrix{N0f8}, F::LinearAlgebra.LU{Float64, LinearAlgebra.Tridiagonal{Float64, Vector{Float64}}}, src::Matrix{N0f8}, R1::CartesianIndices{0, Tuple{}}, R2::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, b::Vector{N0f8})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/filter1d.jl:39
[8] _A_ldiv_B_md!(dest::Matrix{N0f8}, W::WoodburyMatrices.Woodbury{Float64, LinearAlgebra.LU{Float64, LinearAlgebra.Tridiagonal{Float64, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Matrix{Float64}, Matrix{Float64}}, src::Matrix{N0f8}, R1::CartesianIndices{0, Tuple{}}, R2::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, b::Vector{N0f8})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/filter1d.jl:78
[9] A_ldiv_B_md!(dest::Matrix{N0f8}, F::WoodburyMatrices.Woodbury{Float64, LinearAlgebra.LU{Float64, LinearAlgebra.Tridiagonal{Float64, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Matrix{Float64}, Matrix{Float64}}, src::Matrix{N0f8}, dim::Int64, b::Vector{N0f8})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/filter1d.jl:17
[10] prefilter!
@ ~/.julia/packages/Interpolations/qHlUr/src/b-splines/prefiltering.jl:59 [inlined]
[11] prefilter(#unused#::Type{Float64}, #unused#::Type{N0f8}, A::Base.ReinterpretArray{N0f8, 2, UInt8, Matrix{UInt8}, false}, it::BSpline{Quadratic{Flat{OnGrid}}})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/b-splines/prefiltering.jl:40
[12] interpolate(#unused#::Type{Float64}, #unused#::Type{N0f8}, A::Base.ReinterpretArray{N0f8, 2, UInt8, Matrix{UInt8}, false}, it::BSpline{Quadratic{Flat{OnGrid}}})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/b-splines/b-splines.jl:160
[13] interpolate(A::Base.ReinterpretArray{N0f8, 2, UInt8, Matrix{UInt8}, false}, it::BSpline{Quadratic{Flat{OnGrid}}})
@ Interpolations ~/.julia/packages/Interpolations/qHlUr/src/b-splines/b-splines.jl:184
[14] top-level scope
@ REPL[3]:1
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.