5 %> @brief MATLAB code generation to create, boot, train and use blocks.
19 properties(SetAccess=
protected)
24 flag_handle; % whether the data is a handle class, just in case
26 %> Whether the "u"
object is in the workspace
30 %> Also generated code, but does not
get emptied by @c execute()
32 %> Name of the variable that the
block has in the base workspace.
37 function set.classname(o, z)
42 function set.dsnames(o, z)
47 function set.params(o, z)
52 function z =
get.varname(o)
61 methods (Access=
protected)
62 function o = assert_started(o)
70 %> Makes a
string to represent the input data.
71 function sds = get_sds(o)
72 if o.refblock.flag_multiin
74 for i = 1:length(o.dsnames);
75 if i > 1; sds = cat(2, sds, ', '); end;
76 sds = cat(2, sds, o.dsnames{i});
78 sds = strcat(sds,
']');
85 function o = add_code(o, code)
87 o.allcode{end+1} = code;
91 %> Executes accumulated code
92 %> @param flag_finish Whether the execution is the last of a series (will add an extra LineFeed
if so)
93 function o = execute(o, flag_finish)
98 % temp =
char(o.code);
111 function o = start(o)
112 if ~isempty(o.classname)
113 o.refblock = eval(o.classname); % instantializes the class in order to find out a few things
114 elseif ~isempty(o.blockname)
115 o.refblock = evalin('base', [o.blockname, ';']);
117 irerror('Cannot start: neither classname nor blockname set');
120 o.flag_data = ~isempty(o.dsnames);
123 o.code = {}; % Clears generated code
128 % o.add_code([
'% -- @ ', datestr(now), 10]);
132 %> Generates code that creates
new block
133 function o = m_create(o)
136 o.add_code(sprintf('u = %s();\n', o.classname)); % C O D E - creates o.refblock
138 if ~isempty(o.params)
139 o.add_code(
params2str(o.params, 1)); % C O D E - sets parameters
144 if o.flag_leave_block && o.flag_u
146 o = o.add_code(sprintf('%s = u;\n', o.blockname));
152 %> Generates code that boots the
block
153 function o = m_boot(o)
155 if o.refblock.flag_bootable
156 o = o.add_code(sprintf('%s = %s.boot();\n', o.varname, o.varname));
161 %> Generates code that trains the
block
162 function o = m_train(o)
166 irerror('Cannot apply
block: dataset names not provided!');
169 if o.refblock.flag_trainable > 0
170 o = o.add_code(sprintf('%s = %s.train(%s);\n', o.varname, o.varname, o.get_sds()));
174 %> Generate code that uses the
block
175 function o = m_use(o)
179 irerror('Cannot apply
block: dataset names not provided!');
184 if isa(o.refblock, '
vis') && o.refblock.flag_graphics
185 o = o.add_code(sprintf('figure;\n'));
189 if o.refblock.flag_out
190 o = o.add_code(sprintf('out = %s.use(%s);\n', o.varname, sds));
191 o = extract_output(o);
194 o = o.open_in_browser();
197 o = o.add_code(sprintf('%s.use(%s);\n', o.varname, sds));
202 %> Executes "generic" method from the
block. Does not not pass any parameter to the
block, i.e., it is assumed
203 %> that the block can execute the method using its own properties previously assigned.
204 function o = m_generic(o, what)
208 %
irerror('Cannot apply block: dataset names not provided!');
213 % o = o.add_code(sprintf('out = %s.%s(%s);', o.varname, what, sds));
215 o = o.add_code(sprintf('out = %s.%s();\n', o.varname, what));
217 o = extract_output(o);
220 function o = extract_output(o)
221 o = o.assert_started();
224 out = evalin('base', 'out;');
225 flag_cell = iscell(out);
228 data = evalin('base', [o.dsnames{1},
';']);
229 % o.flag_handle = isa(data,
'handle');
234 [ni, nj] = size(out);
242 sij = sprintf(
'{%d, %d}', i, j);
248 if isa(outij,
'irdata')
251 if o.refblock.flag_multiin
261 for k = 1:numel(outij)
262 o = o.add_code(sprintf('%s_%02d = out%s(%d);\n', outname, k, sij, k));
265 o = o.add_code(sprintf('%s = out%s;\n', outname, sij));
269 % Anything else than datasets will be made into a decent name, but not extracted if it is an array.
273 o = o.add_code(sprintf('%s = out%s;\n', outname, sij));
283 function o = open_in_browser(o)
284 o = o.add_code(sprintf('out.open_in_browser();\n'));
287 function o = finish(o)
function params2str(in params, in flag_o)
Visualization base class.
function get_suffix(in clname, in no_trim)
function ircode_add(in s, in title)
function ircode_eval(in s, in title)
function find_varname(in prefix)
MATLAB code generation to create, boot, train and use blocks.