Skip to content

Commit 8469bd9

Browse files
authored
Merge pull request #72 from alan-turing-institute/dev
For a 0.3.6 release
2 parents ce8ba3a + 594e8c6 commit 8469bd9

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- linux
55
julia:
66
- 1.0
7-
- 1.4
7+
- 1.5
88
- nightly
99
matrix:
1010
allow_failures:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJModelInterface"
22
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
33
authors = ["Thibaut Lienart and Anthony Blaom"]
4-
version = "0.3.5"
4+
version = "0.3.6"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

src/model_def.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
clean!(::Model) = ""
99

1010
"""
11-
_process_model_def(ex)
11+
_process_model_def(modl, ex)
1212
1313
Take an expression defining a model (`mutable struct Model ...`) and unpack key
1414
elements for further processing:
@@ -17,12 +17,17 @@ elements for further processing:
1717
- Names of parameters (`params`)
1818
- Default values (`defaults`)
1919
- Constraints (`constraints`)
20-
"""
21-
function _process_model_def(ex)
22-
defaults = Dict{Symbol,Any}()
20+
21+
When no default field value is given a heuristic is to guess an
22+
appropriate default (eg, zero for a `Float64` parameter). To this end,
23+
the specified type expression is evaluated in the module `modl`.
24+
25+
"""
26+
function _process_model_def(modl, ex)
27+
defaults = Dict{Symbol,Any}()
2328
constraints = Dict{Symbol,Any}()
24-
modelname = ex.args[2] isa Symbol ? ex.args[2] : ex.args[2].args[1]
25-
params = Symbol[]
29+
modelname = ex.args[2] isa Symbol ? ex.args[2] : ex.args[2].args[1]
30+
params = Symbol[]
2631

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

0 commit comments

Comments
 (0)