@@ -37,37 +37,59 @@ warn_serializable_mach(operation) = "The operation $operation has been called on
37
37
" deserialised machine mach whose learned parameters " *
38
38
" may be unusable. To be sure, first run restore!(mach)."
39
39
40
+ # Given return value `ret` of an operation with symbol `operation` (eg, `:predict`) return
41
+ # `ret` in the ordinary case that the operation does not include an "report" component ;
42
+ # otherwise update `mach.report` with that component and return the non-report part of
43
+ # `ret`:
44
+ function get! (ret, operation, mach)
45
+ if operation in reporting_operations (mach. model)
46
+ report = last (ret)
47
+ if isnothing (mach. report) || isempty (mach. report)
48
+ mach. report = report
49
+ else
50
+ mach. report = merge (mach. report, report)
51
+ end
52
+ return first (ret)
53
+ end
54
+ return ret
55
+ end
56
+
40
57
# 0. operations on machine, given rows=...:
41
58
42
59
for operation in OPERATIONS
43
60
44
- if operation != :inverse_transform
61
+ quoted_operation = QuoteNode ( operation) # eg, :(:predict)
45
62
46
- ex = quote
47
- function $ (operation)(mach:: Machine{<:Model,false} ; rows= :)
48
- # catch deserialized machine with no data:
49
- isempty (mach. args) && _err_serialized ($ operation)
50
- return ($ operation)(mach, mach. args[1 ](rows= rows))
51
- end
52
- function $ (operation)(mach:: Machine{<:Model,true} ; rows= :)
53
- # catch deserialized machine with no data:
54
- isempty (mach. args) && _err_serialized ($ operation)
55
- model = mach. model
56
- return ($ operation)(model,
57
- mach. fitresult,
58
- selectrows (model, rows, mach. data[1 ])... )
59
- end
60
- end
61
- eval (ex)
63
+ operation == :inverse_transform && continue
62
64
65
+ ex = quote
66
+ function $ (operation)(mach:: Machine{<:Model,false} ; rows= :)
67
+ # catch deserialized machine with no data:
68
+ isempty (mach. args) && _err_serialized ($ operation)
69
+ ret = ($ operation)(mach, mach. args[1 ](rows= rows))
70
+ return get! (ret, $ quoted_operation, mach)
71
+ end
72
+ function $ (operation)(mach:: Machine{<:Model,true} ; rows= :)
73
+ # catch deserialized machine with no data:
74
+ isempty (mach. args) && _err_serialized ($ operation)
75
+ model = mach. model
76
+ ret = ($ operation)(
77
+ model,
78
+ mach. fitresult,
79
+ selectrows (model, rows, mach. data[1 ])... ,
80
+ )
81
+ return get! (ret, $ quoted_operation, mach)
82
+ end
63
83
end
84
+ eval (ex)
85
+
64
86
end
65
87
66
88
# special case of Static models (no training arguments):
67
89
transform (mach:: Machine{<:Static} ; rows= :) = _err_rows_not_allowed ()
68
90
69
91
inverse_transform (mach:: Machine ; rows= :) =
70
- throw (ArgumentError (" `inverse_transform()( mach)` and " *
92
+ throw (ArgumentError (" `inverse_transform(mach)` and " *
71
93
" `inverse_transform(mach, rows=...)` are " *
72
94
" not supported. Data or nodes " *
73
95
" must be explictly specified, " *
@@ -77,22 +99,32 @@ _symbol(f) = Base.Core.Typeof(f).name.mt.name
77
99
78
100
for operation in OPERATIONS
79
101
102
+ quoted_operation = QuoteNode (operation) # eg, :(:predict)
103
+
80
104
ex = quote
81
105
# 1. operations on machines, given *concrete* data:
82
106
function $operation (mach:: Machine , Xraw)
83
107
if mach. state != 0
84
108
mach. state == - 1 && @warn warn_serializable_mach ($ operation)
85
- return $ (operation)(mach. model,
86
- mach. fitresult,
87
- reformat (mach. model, Xraw)... )
109
+ ret = $ (operation)(
110
+ mach. model,
111
+ mach. fitresult,
112
+ reformat (mach. model, Xraw)... ,
113
+ )
114
+ get! (ret, $ quoted_operation, mach)
88
115
else
89
116
error (" $mach has not been trained." )
90
117
end
91
118
end
92
119
93
120
function $operation (mach:: Machine{<:Static} , Xraw, Xraw_more... )
94
- return $ (operation)(mach. model, mach. fitresult,
95
- Xraw, Xraw_more... )
121
+ ret = $ (operation)(
122
+ mach. model,
123
+ mach. fitresult,
124
+ Xraw,
125
+ Xraw_more... ,
126
+ )
127
+ get! (ret, $ quoted_operation, mach)
96
128
end
97
129
98
130
# 2. operations on machines, given *dynamic* data (nodes):
0 commit comments