 rtable_scanblock - Maple Help

rtable_scanblock

scan a block of elements in an rtable Calling Sequence rtable_scanblock(A, ranges, operation) rtable_scanblock(A, ranges, noindex, operation1, data1, stopresult=val1, passindex, operation2, ... ) operation_passindex(value, index, data) operation_noindex(value, data) Parameters

 A - rtable object ranges - empty list or list of ranges operation* - name of a builtin operation or a proc val* - (optional) stop scanning when the operation proc returns this noindex - (optional) do not pass the index to the operation proc passindex - (optional) pass the index to the operation proc value - value at the current element in A index - index of the current element entry in A data - val1, or value of the previous result operation_passindex - calling sequence for the operation parameter when passindex is given operation_passnoindex - calling sequence for the operation parameter when noindex is given Description

 • The rtable_scanblock(A) command applies one or more operations to the values in the specified ranges of an Array, Matrix, or Vector.
 • If ranges is an empty list all elements of A will be scanned.  Otherwise, the given list of ranges must be fully specified with integer lower and upper bounds, and fall within the index-space of A.  Note that for an integer $n$, the range $n..n$ can be written as simply $n$.
 • The following built-in operations are recognized.

 Average compute the average value HasNonZero true if there exists a nonzero value HasZero true if there exists a zero value Maximum find the maximum defined value MaximumCheckUndefined find the maximum value or undefined if present Minimum find the minimum defined value MinimumCheckUndefined find the minimum value or undefined if present NumericMaxMin find the max and min of only the numeric entries NonZeros count the number of nonzero entries NonZeroAverage compute the average of the nonzero entries NonZeroMaximum find the maximum excluding zero NonZeroMinimum find the minimum excluding zero Sum compute the sum of all the elements Zeros count the number of zero entries

 Most of these built-in operations work only on numeric data.  A value of FAIL is returned if the operation cannot be completed.
 • The operation parameter can be a procedure that accepts either the calling sequence given by operation_passindex or by operation_noindex listed in the Calling Sequence section. If the option noindex is specified in the calling sequence, then every operation following is assumed to have the form of the operation_noindex calling sequence.  In other words, the elements index is not passed to those operation procedures.  This may be more efficient as creation of the index expression sequence can sometimes be avoided.  When passindex is specified, then the subsequent operation parameters are called with the index of the element in addition to the element's value.
 The data parameter to the operation callbacks is initially the valN value passed to rtable_scanblock.  After the first callback, data becomes the result of the last callback. This is useful for building a result that depends on previous scanned elements.
 • It is often desirable to stop scanning once certain information is known about an element.  For example, upon detection of the first non-numeric type you may want to interrupt the scan.  This can be done using the stopresult parameter.  If the operation procedure returns the value given by stopresult, then the block scan is terminated and that result is returned.  Only the operation paired with its stopresult is terminated.  If other operations specified in the rtable_scanblock calling sequence are not finished, they will continue. • The rtable_scanblock command is thread-safe as of Maple 15. Examples

Compute the average, maximum, and minimum values in a Matrix.

 > $N≔100:$
 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(N,N,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{float}\right]\right)$
 ${A}{≔}\begin{array}{c}\left[\begin{array}{ccccccccccc}{6.}& {74.}& {-21.}& {-76.}& {40.}& {63.}& {15.}& {0.}& {46.}& {25.}& {\dots }\\ {-48.}& {69.}& {96.}& {61.}& {65.}& {-59.}& {31.}& {41.}& {40.}& {-51.}& {\dots }\\ {-36.}& {-78.}& {-26.}& {60.}& {72.}& {-73.}& {76.}& {-37.}& {-9.}& {-53.}& {\dots }\\ {-19.}& {-81.}& {27.}& {-16.}& {62.}& {-27.}& {-46.}& {39.}& {-79.}& {74.}& {\dots }\\ {-76.}& {98.}& {-58.}& {-93.}& {62.}& {-67.}& {93.}& {-17.}& {-68.}& {8.}& {\dots }\\ {22.}& {55.}& {-70.}& {71.}& {-51.}& {91.}& {-20.}& {-37.}& {-39.}& {-25.}& {\dots }\\ {-21.}& {-43.}& {-41.}& {-33.}& {2.}& {-20.}& {-36.}& {-30.}& {11.}& {2.}& {\dots }\\ {23.}& {-34.}& {15.}& {-99.}& {91.}& {43.}& {-24.}& {-62.}& {27.}& {-20.}& {\dots }\\ {-80.}& {83.}& {19.}& {13.}& {-54.}& {-60.}& {-20.}& {13.}& {47.}& {42.}& {\dots }\\ {22.}& {8.}& {96.}& {-91.}& {34.}& {18.}& {-33.}& {17.}& {-89.}& {77.}& {\dots }\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {}\end{array}\right]\\ \hfill {\text{100 × 100 Matrix}}\end{array}$ (1)
 > $\mathrm{rtable_scanblock}\left(A,\left[\mathrm{rtable_dims}\left(A\right)\right],'\mathrm{Average}','\mathrm{Maximum}','\mathrm{Minimum}'\right)$
 ${0.292500000000000}{,}{99.}{,}{-99.}$ (2)

Check if a Vector has a value bigger than 0.

 > gzero := proc(val,res)     if val > 0 then         return true;     else         return false;     end if; end proc;
 ${\mathrm{gzero}}{≔}{\mathbf{proc}}\left({\mathrm{val}}{,}{\mathrm{res}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{0}{<}{\mathrm{val}}\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}}$ (3)
 > $A≔\mathrm{Vector}\left(\left[-1,0,1\right]\right):$
 > $\mathrm{rtable_scanblock}\left(A,\left[\right],'\mathrm{noindex}',\mathrm{gzero},'\mathrm{stopresult}'=\mathrm{true}\right)$
 ${\mathrm{true}}$ (4)
 > $B≔\mathrm{Vector}\left(\left[-1,0,-2\right]\right):$
 > $\mathrm{rtable_scanblock}\left(B,\left[\right],'\mathrm{noindex}',\mathrm{gzero},'\mathrm{stopresult}'=\mathrm{true}\right)$
 ${\mathrm{false}}$ (5)

Find the maximum element and its index in the first column of a Matrix.  Note [[1,1],A[1,1]] is used as the initial max value.

 > $N≔100:$
 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(N,N,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{float}\right]\right)$
 ${A}{≔}\begin{array}{c}\left[\begin{array}{ccccccccccc}{-59.}& {-15.}& {-66.}& {20.}& {-7.}& {-78.}& {-59.}& {-15.}& {49.}& {-39.}& {\dots }\\ {-92.}& {-10.}& {56.}& {30.}& {51.}& {35.}& {-28.}& {-2.}& {97.}& {-85.}& {\dots }\\ {-77.}& {47.}& {70.}& {-27.}& {-17.}& {-23.}& {-39.}& {20.}& {-40.}& {48.}& {\dots }\\ {-55.}& {49.}& {16.}& {-84.}& {-68.}& {98.}& {60.}& {18.}& {86.}& {-33.}& {\dots }\\ {53.}& {-40.}& {91.}& {-90.}& {-78.}& {-51.}& {21.}& {5.}& {-89.}& {29.}& {\dots }\\ {-17.}& {-72.}& {-3.}& {-83.}& {16.}& {-77.}& {-43.}& {89.}& {-40.}& {-88.}& {\dots }\\ {-31.}& {-29.}& {5.}& {-94.}& {93.}& {-16.}& {-35.}& {14.}& {-22.}& {-62.}& {\dots }\\ {2.}& {22.}& {-58.}& {77.}& {83.}& {-79.}& {83.}& {-51.}& {19.}& {-67.}& {\dots }\\ {75.}& {-79.}& {-59.}& {33.}& {2.}& {66.}& {-22.}& {24.}& {-2.}& {1.}& {\dots }\\ {53.}& {-21.}& {-13.}& {68.}& {-53.}& {-15.}& {61.}& {-10.}& {0.}& {33.}& {\dots }\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {}\end{array}\right]\\ \hfill {\text{100 × 100 Matrix}}\end{array}$ (6)
 > $\mathrm{rtable_scanblock}\left(A,\left[1..N,1..1\right],\left(\mathrm{val},\mathrm{ind},\mathrm{res}\right)↦\mathrm{if}\left(\mathrm{res}\left[2\right]<\mathrm{val},\left[\mathrm{ind},\mathrm{val}\right],\mathrm{res}\right),\left[\left[1,1\right],A\left[1,1\right]\right]\right)$
 $\left[\left[{94}{,}{1}\right]{,}{99.}\right]$ (7)

Find the maximum and minimum elements and their corresponding indices in the last row of a Matrix.

 > $N≔100:$
 > $A≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(N,N,\mathrm{outputoptions}=\left[\mathrm{datatype}=\mathrm{float}\right]\right)$
 ${A}{≔}\begin{array}{c}\left[\begin{array}{ccccccccccc}{-60.}& {-5.}& {-6.}& {6.}& {-8.}& {2.}& {-1.}& {4.}& {-38.}& {-62.}& {\dots }\\ {40.}& {31.}& {9.}& {88.}& {6.}& {10.}& {-83.}& {-76.}& {35.}& {-41.}& {\dots }\\ {-52.}& {24.}& {-93.}& {-68.}& {-73.}& {-92.}& {-48.}& {79.}& {21.}& {33.}& {\dots }\\ {-43.}& {21.}& {97.}& {4.}& {-36.}& {34.}& {32.}& {78.}& {69.}& {59.}& {\dots }\\ {-82.}& {0.}& {-58.}& {39.}& {-10.}& {15.}& {62.}& {-3.}& {-54.}& {-91.}& {\dots }\\ {-33.}& {58.}& {82.}& {-12.}& {-28.}& {35.}& {84.}& {-7.}& {40.}& {21.}& {\dots }\\ {61.}& {-42.}& {-8.}& {-72.}& {17.}& {66.}& {72.}& {40.}& {58.}& {-77.}& {\dots }\\ {-32.}& {-4.}& {76.}& {42.}& {24.}& {-5.}& {-97.}& {-56.}& {47.}& {-17.}& {\dots }\\ {-51.}& {-85.}& {-10.}& {-44.}& {-61.}& {-82.}& {2.}& {37.}& {-24.}& {-65.}& {\dots }\\ {-92.}& {94.}& {15.}& {39.}& {-57.}& {56.}& {14.}& {55.}& {15.}& {-17.}& {\dots }\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {}\end{array}\right]\\ \hfill {\text{100 × 100 Matrix}}\end{array}$ (8)
 > $\mathrm{rtable_scanblock}\left(A,\left[N..N,1..N\right],\left(\mathrm{val},\mathrm{ind},\mathrm{res}\right)↦\mathrm{if}\left(\mathrm{res}\left[2\right]<\mathrm{val},\left[\mathrm{ind},\mathrm{val}\right],\mathrm{res}\right),\left[\left[1,1\right],A\left[1,1\right]\right],\left(\mathrm{val},\mathrm{ind},\mathrm{res}\right)↦\mathrm{if}\left(\mathrm{val}<\mathrm{res}\left[2\right],\left[\mathrm{ind},\mathrm{val}\right],\mathrm{res}\right),\left[\left[1,1\right],A\left[1,1\right]\right]\right)$
 $\left[\left[{100}{,}{4}\right]{,}{96.}\right]{,}\left[\left[{100}{,}{12}\right]{,}{-95.}\right]$ (9) Compatibility

 • The rtable_scanblock command was updated in Maple 2020.