8
8
clean! (:: Model ) = " "
9
9
10
10
"""
11
- _process_model_def(ex)
11
+ _process_model_def(modl, ex)
12
12
13
13
Take an expression defining a model (`mutable struct Model ...`) and unpack key
14
14
elements for further processing:
@@ -17,12 +17,17 @@ elements for further processing:
17
17
- Names of parameters (`params`)
18
18
- Default values (`defaults`)
19
19
- 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} ()
23
28
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[]
26
31
27
32
# inspect all lines which may define parameters, retrieve their names,
28
33
# default values and constraints on values that can be given to them
@@ -67,7 +72,7 @@ function _process_model_def(ex)
67
72
# these are simple heuristics when no default value is given for the
68
73
# field but an "obvious" one can be provided implicitly (ideally this should
69
74
# 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)
71
76
if eff_type <: Number
72
77
defaults[param] = zero (eff_type)
73
78
elseif eff_type <: AbstractString
168
173
Macro to help define MLJ models with constraints on the default parameters.
169
174
"""
170
175
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)
172
177
# keyword constructor
173
178
const_ex = _model_constructor (modelname, params, defaults)
174
179
# associate the constructor with the definition of the struct
0 commit comments