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

For a 0.3.6 release #72

Merged
merged 4 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
- linux
julia:
- 1.0
- 1.4
- 1.5
- nightly
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJModelInterface"
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
authors = ["Thibaut Lienart and Anthony Blaom"]
version = "0.3.5"
version = "0.3.6"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
21 changes: 13 additions & 8 deletions src/model_def.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
clean!(::Model) = ""

"""
_process_model_def(ex)
_process_model_def(modl, ex)

Take an expression defining a model (`mutable struct Model ...`) and unpack key
elements for further processing:
Expand All @@ -17,12 +17,17 @@ elements for further processing:
- Names of parameters (`params`)
- Default values (`defaults`)
- Constraints (`constraints`)
"""
function _process_model_def(ex)
defaults = Dict{Symbol,Any}()

When no default field value is given a heuristic is to guess an
appropriate default (eg, zero for a `Float64` parameter). To this end,
the specified type expression is evaluated in the module `modl`.

"""
function _process_model_def(modl, ex)
defaults = Dict{Symbol,Any}()
constraints = Dict{Symbol,Any}()
modelname = ex.args[2] isa Symbol ? ex.args[2] : ex.args[2].args[1]
params = Symbol[]
modelname = ex.args[2] isa Symbol ? ex.args[2] : ex.args[2].args[1]
params = Symbol[]

# inspect all lines which may define parameters, retrieve their names,
# default values and constraints on values that can be given to them
Expand Down Expand Up @@ -67,7 +72,7 @@ function _process_model_def(ex)
# these are simple heuristics when no default value is given for the
# field but an "obvious" one can be provided implicitly (ideally this should
# not be used as it's not very clear that the intention matches the usage)
eff_type = eval(type)
eff_type = modl.eval(type)
if eff_type <: Number
defaults[param] = zero(eff_type)
elseif eff_type <: AbstractString
Expand Down Expand Up @@ -168,7 +173,7 @@ end
Macro to help define MLJ models with constraints on the default parameters.
"""
macro mlj_model(ex)
ex, modelname, params, defaults, constraints = _process_model_def(ex)
ex, modelname, params, defaults, constraints = _process_model_def(__module__, ex)
# keyword constructor
const_ex = _model_constructor(modelname, params, defaults)
# associate the constructor with the definition of the struct
Expand Down