Skip to content

Commit

Permalink
Dispatch the Model methods using parametric type selectors
Browse files Browse the repository at this point in the history
Instead of calling the constructor and instantiating the type it's
preferable to simply pass the type.
  • Loading branch information
Sagnac committed Jul 3, 2023
1 parent 1f6adcd commit 9729b25
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ScaleAperture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function J(v::Vector{Float64}, ε::Float64; precision = 3, finesse::Int = 101)
Λ(ΔW, b, v2, n_max; finesse)
end

function J(v::Vector{Float64}, ε::Float64, ::Model; precision = 3)
function J(v::Vector{Float64}, ε::Float64, ::Type{Model}; precision = 3)
v2, n_max = Π(v, ε)
Zᵢ = Vector{Polynomial}(undef, length(v))
Ψ(v2, Zᵢ, n_max; precision)[1]
Expand Down
14 changes: 7 additions & 7 deletions src/TransformAperture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ function P(v::Vector{T}, ε::T, δ::Complex{T} = 0.0im,
Λ(ΔW, b, v2, n_max; finesse)
end

function P(v::Vector{T}, ε::T, δ::Complex{T}, ϕ::T, ω::Tuple{T, T}, ::Model;
function P(v::Vector{T}, ε::T, δ::Complex{T}, ϕ::T, ω::Tuple{T, T}, ::Type{Model};
precision = 3) where T <: Float64
v2, n_max = S(v, ε, δ, ϕ, ω)
Zᵢ = Vector{Polynomial}(undef, length(v))
Ψ(v2, Zᵢ, n_max; precision)[1]
end

function P(v::Vector{T}, ε::T, ::Model; precision = 3) where T <: Float64
P(v, ε, 0.0im, zero(T), (1.0, 0.0), Model(); precision)
function P(v::Vector{T}, ε::T, ::Type{Model}; precision = 3) where T <: Float64
P(v, ε, 0.0im, zero(T), (1.0, 0.0), Model; precision)
end

function P(v::Vector{T}, ε::T, δ::Complex{T}, ::Model;
function P(v::Vector{T}, ε::T, δ::Complex{T}, ::Type{Model};
precision = 3) where T <: Float64
P(v, ε, δ, zero(T), (1.0, 0.0), Model(); precision)
P(v, ε, δ, zero(T), (1.0, 0.0), Model; precision)
end

function P(v::Vector{T}, ε::T, δ::Complex{T}, ϕ::T, ::Model;
function P(v::Vector{T}, ε::T, δ::Complex{T}, ϕ::T, ::Type{Model};
precision = 3) where T <: Float64
P(v, ε, δ, ϕ, (1.0, 0.0), Model(); precision)
P(v, ε, δ, ϕ, (1.0, 0.0), Model; precision)
end
12 changes: 6 additions & 6 deletions src/WavefrontError.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
# fitting function (construction function 1)
function Wf::FloatVec, θ::FloatVec, OPD::FloatVec, n_max::Int)
j_max = get_j(n_max, n_max)
Zᵢ = Polynomial[Z(j, Model()) for j = 0:j_max]
Zᵢ = Polynomial[Z(j, Model) for j = 0:j_max]
v = fit(ρ, θ, OPD, Zᵢ)
return v, Zᵢ
end
Expand All @@ -57,7 +57,7 @@ function Ψ(v, Zᵢ, n_max, orders = Tuple{Int, Int}[]; precision)
aᵢ = precision == "full" ? aᵢ : round(aᵢ; digits = precision)
if !iszero(aᵢ)
if clipped
Zᵢ[i] = Z(i-1, Model())
Zᵢ[i] = Z(i-1, Model)
end
push!(a, (; Zᵢ[i].inds..., a = aᵢ))
push!(av, aᵢ)
Expand Down Expand Up @@ -147,14 +147,14 @@ function standardize(v_sub::FloatVec, orders::Vector{Tuple{Int, Int}})
end

# methods
function W::FloatVec, θ::FloatVec, OPD::FloatVec, n_max::Int, ::Model;
function W::FloatVec, θ::FloatVec, OPD::FloatVec, n_max::Int, ::Type{Model};
precision = 3)
v, Zᵢ = Wf(ρ, θ, OPD, n_max)
return Ψ(v, Zᵢ, n_max; precision)[1]
end

function W::FloatVec, θ::FloatVec, OPD::FloatVec,
orders::Vector{Tuple{Int, Int}}, ::Model; precision = 3)
orders::Vector{Tuple{Int, Int}}, ::Type{Model}; precision = 3)
n_max = maximum(mn -> mn[2], orders; init = 0)
v, Zᵢ = Wf(ρ, θ, OPD, orders)
return Ψ(v, Zᵢ, n_max, orders; precision)[1]
Expand Down Expand Up @@ -186,8 +186,8 @@ function W(OPD::FloatMat, fit_to; options...)
W(coords(OPD)..., vec(OPD), fit_to; options...)
end

function W(OPD::FloatMat, fit_to, ::Model; precision = 3)
W(coords(OPD)..., vec(OPD), fit_to, Model(); precision)
function W(OPD::FloatMat, fit_to, ::Type{Model}; precision = 3)
W(coords(OPD)..., vec(OPD), fit_to, Model; precision)
end

# reverse transform;
Expand Down
4 changes: 2 additions & 2 deletions src/Zernike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ getindex(Z::T, i) where {T <: Output} = getfield(Z, fieldnames(T)[i])
iterate(Z::Output, i = 1) = (i > 3 ? nothing : (Z[i], i + 1))

# methods
Z(m::Int, n::Int, ::Model) = Zf(m, n)
Z(m::Int, n::Int, ::Type{Model}) = Zf(m, n)

Z(; m, n, finesse::Int = 100) = Z(m, n; finesse)

Z(j::Int; finesse::Int = 100) = Z(get_mn(j)...; finesse)

Z(j::Int, ::Model) = Zf(get_mn(j)...)
Z(j::Int, ::Type{Model}) = Zf(get_mn(j)...)

end

0 comments on commit 9729b25

Please sign in to comment.