Select - Maple Help

CodeTools[Profiling]

 Select
 select procedures from a table of profiling data

 Calling Sequence Select(selector, tab)

Parameters

 selector - boolean valued procedure tab - table of profiling data

Description

 • The Select(selector, tab) command is similar to the select function. The boolean valued procedure, selector, is called on each element in tab.  A new table is returned containing only those elements of tab for which selector returns true.
 • The selector parameter is a procedure that accepts two arguments. The first argument is the encoded name (see EncodeName) of the procedure and the second is the rtable containing the profiling data.

Examples

 > $\mathrm{with}\left({\mathrm{CodeTools}}_{\mathrm{Profiling}}\right):$
 > selector := proc(n,t)     # check the total number of function calls     if (t[1][1] > 5) then         return true;     else     return false;     end if; end proc;
 ${\mathrm{selector}}{≔}{\mathbf{proc}}\left({n}{,}{t}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{5}{<}{t}{[}{1}{]}{[}{1}{]}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{true}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{false}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > a := proc( )     return 1; end proc;
 ${a}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > b := proc( )     local i;     for i from 1 to 10 do         a();     end do; end proc;
 ${b}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{i}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{for}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{i}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{to}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{10}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{do}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{a}{}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end do}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)
 > $t≔\mathrm{Build}\left(\mathrm{procs}=\left[a,b\right],\mathrm{commands}='b\left(\right)'\right)$
 ${t}{≔}{table}{}\left(\left[{\mathrm{_Inert_ASSIGNEDNAME}}{}\left({"b"}{,}{"PROC"}\right){=}\left[\begin{array}{ccc}{1}& {0}& {0}\\ {1}& {0}& {0}\\ {10}& {0}& {0}\end{array}\right]{,}{\mathrm{_Inert_ASSIGNEDNAME}}{}\left({"a"}{,}{"PROC"}\right){=}\left[\begin{array}{ccc}{10}& {0}& {0}\\ {10}& {0}& {0}\end{array}\right]\right]\right)$ (4)
 > $\mathrm{PrintProfiles}\left(t\right)$
 a a := proc()      |Calls Seconds  Words| PROC |   10   0.000      0|    1 |   10   0.000      0| return 1 end proc b b := proc() local i;      |Calls Seconds  Words| PROC |    1   0.000      0|    1 |    1   0.000      0| for i to 10 do    2 |   10   0.000      0|     a()                             end do end proc
 > $s≔\mathrm{Select}\left(\mathrm{selector},t\right)$
 ${s}{≔}{table}{}\left(\left[{\mathrm{_Inert_ASSIGNEDNAME}}{}\left({"a"}{,}{"PROC"}\right){=}\left[\begin{array}{ccc}{10}& {0}& {0}\\ {10}& {0}& {0}\end{array}\right]\right]\right)$ (5)
 > $\mathrm{PrintProfiles}\left(s\right)$
 a a := proc()      |Calls Seconds  Words| PROC |   10   0.000      0|    1 |   10   0.000      0| return 1 end proc