[feature] Optimize does not work on `Colorant{T,1}`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start at fit in fitting.jl:76 and fitting.jl:99, then reproduce the reported optimize failure with a Matrix{Gray{Float64}}. Determine whether the fit entry point should support AbstractGray inputs as proposed, and verify that fitting such an image completes without the DiffResult MethodError.
Written by the indexing model from the issue text.
Description
When trying to fit an image of a bead, it is most commonly represented as an array of colorants. The most likely for this use in particular is for it to be some subtype of AbstractGray. But when trying to fit some kind of Gray array, there it throws:
ERROR: MethodError: no method matching DiffResults.DiffResult(::Gray{Float64}, ::Vector{Float64})
Closest candidates are:
DiffResults.DiffResult(::Union{Number, AbstractArray}, ::Union{Number, AbstractArray}...) at ~/.julia/packages/DiffResults/wASAy/src/DiffResults.jl:52
Stacktrace:
[1] (::NLSolversBase.var"#14#18"{Gray{Float64}, PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, Gray{Float64}}, Gray{Float64}, 5, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, Gray{Float64}}, Gray{Float64}, 5}}}})(out::Vector{Float64}, x::Vector{Gray{Float64}})
@ NLSolversBase ~/.julia/packages/NLSolversBase/cfJrN/src/objective_types/oncedifferentiable.jl:69
[2] value_gradient!!(obj::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, x::Vector{Gray{Float64}})
@ NLSolversBase ~/.julia/packages/NLSolversBase/cfJrN/src/interface.jl:82
[3] initial_state(method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}, d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, initial_x::Vector{Gray{Float64}})
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/solvers/first_order/l_bfgs.jl:164
[4] optimize(d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, initial_x::Vector{Gray{Float64}}, method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing})
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/optimize/optimize.jl:36
[5] optimize(f::Function, initial_x::Vector{Gray{Float64}}, method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}; inplace::Bool, autodiff::Symbol)
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/optimize/interface.jl:142
[6] fit(model::typeof(gaussian), params::NamedTuple{(:x, :y, :fwhm, :amp), Tuple{Float64, Float64, Tuple{Int64, Int64}, Int64}}, image::Matrix{Gray{Float64}}, inds::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}; func_kwargs::NamedTuple{(), Tuple{}}, loss::typeof(abs2), alg::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, maxfwhm::Float64, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PSFModels ~/.julia/packages/PSFModels/G3WuK/src/fitting.jl:99
[7] fit (repeats 2 times)
@ ~/.julia/packages/PSFModels/G3WuK/src/fitting.jl:76 [inlined]
[8] top-level scope
@ REPL[167]:1
Could there be definition such as:
function fit(..., image::AbstractArray{T}, ...) where {T<:AbstractGray}
fit(..., Real.(image), ...)
end
Do you think it is a good idea?
- Dominant language
- Julia
- Stars
- 11
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaAstro/PSFModels.jl
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
JuliaAstro/PSFModels.jl#47 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
JuliaAstro/PSFModels.jl#11 · 4 comments ·
All issues in JuliaAstro/PSFModels.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
brown-ccv/Chamber.jl#272 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaBayes/Wren.jl#404 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAI/MLJTransforms.jl#113 ·
Maintainers usually reply within 1 day