Skip to content

Commit 53ce262

Browse files
committed
Document thoroughly and organise code
1 parent 3a49d8d commit 53ce262

File tree

3 files changed

+306
-93
lines changed

3 files changed

+306
-93
lines changed

src/compiler.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,15 @@ end
718718
# TODO(mhauru) matchingvalue has methods that can accept both types and values. Why?
719719
# TODO(mhauru) This function needs a more comprehensive docstring.
720720
"""
721-
matchingvalue(vi, value)
721+
matchingvalue(param_eltype, value)
722722
723-
Convert the `value` to the correct type for the `vi` object.
723+
Convert the `value` to the correct type, given the element type of the parameters
724+
being used to evaluate the model.
724725
"""
725-
function matchingvalue(vi, value)
726+
function matchingvalue(param_eltype, value)
726727
T = typeof(value)
727728
if hasmissing(T)
728-
_value = convert(get_matching_type(vi, T), value)
729+
_value = convert(get_matching_type(param_eltype, T), value)
729730
# TODO(mhauru) Why do we make a deepcopy, even though in the !hasmissing branch we
730731
# are happy to return `value` as-is?
731732
if _value === value
@@ -738,29 +739,30 @@ function matchingvalue(vi, value)
738739
end
739740
end
740741

741-
function matchingvalue(vi, value::FloatOrArrayType)
742-
return get_matching_type(vi, value)
742+
function matchingvalue(param_eltype, value::FloatOrArrayType)
743+
return get_matching_type(param_eltype, value)
743744
end
744-
function matchingvalue(vi, ::TypeWrap{T}) where {T}
745-
return TypeWrap{get_matching_type(vi, T)}()
745+
function matchingvalue(param_eltype, ::TypeWrap{T}) where {T}
746+
return TypeWrap{get_matching_type(param_eltype, T)}()
746747
end
747748

748749
# TODO(mhauru) This function needs a more comprehensive docstring. What is it for?
749750
"""
750-
get_matching_type(vi, ::TypeWrap{T}) where {T}
751+
get_matching_type(param_eltype, ::TypeWrap{T}) where {T}
751752
752-
Get the specialized version of type `T` for `vi`.
753+
Get the specialized version of type `T`, given an element type of the parameters
754+
being used to evaluate the model.
753755
"""
754756
get_matching_type(_, ::Type{T}) where {T} = T
755-
function get_matching_type(vi, ::Type{<:Union{Missing,AbstractFloat}})
756-
return Union{Missing,float_type_with_fallback(eltype(vi))}
757+
function get_matching_type(param_eltype, ::Type{<:Union{Missing,AbstractFloat}})
758+
return Union{Missing,float_type_with_fallback(param_eltype)}
757759
end
758-
function get_matching_type(vi, ::Type{<:AbstractFloat})
759-
return float_type_with_fallback(eltype(vi))
760+
function get_matching_type(param_eltype, ::Type{<:AbstractFloat})
761+
return float_type_with_fallback(param_eltype)
760762
end
761-
function get_matching_type(vi, ::Type{<:Array{T,N}}) where {T,N}
762-
return Array{get_matching_type(vi, T),N}
763+
function get_matching_type(param_eltype, ::Type{<:Array{T,N}}) where {T,N}
764+
return Array{get_matching_type(param_eltype, T),N}
763765
end
764-
function get_matching_type(vi, ::Type{<:Array{T}}) where {T}
765-
return Array{get_matching_type(vi, T)}
766+
function get_matching_type(param_eltype, ::Type{<:Array{T}}) where {T}
767+
return Array{get_matching_type(param_eltype, T)}
766768
end

0 commit comments

Comments
 (0)