rtable_scanblock - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


rtable_scanblock

scan a block of elements in an rtable

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Compatibility

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.

Thread Safety

• 

The rtable_scanblock command is thread-safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

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

N100:

ALinearAlgebra:-RandomMatrixN,N,outputoptions=datatype=float

rtable_scanblockA,rtable_dimsA,Average,Maximum,Minimum

0.292500000000000,99.,−99.

(1)

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;

gzeroprocval&comma;resif0<valthenreturntrueelsereturnfalseend ifend proc

(2)

AVector1&comma;0&comma;1&colon;

rtable_scanblockA&comma;&comma;noindex&comma;gzero&comma;stopresult=true

true

(3)

BVector1&comma;0&comma;2&colon;

rtable_scanblockB&comma;&comma;noindex&comma;gzero&comma;stopresult=true

false

(4)

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.

N100&colon;

ALinearAlgebra:-RandomMatrixN&comma;N&comma;outputoptions=datatype=float

rtable_scanblockA&comma;1..N&comma;1..1&comma;val&comma;ind&comma;res`if`res2<val&comma;ind&comma;val&comma;res&comma;1&comma;1&comma;A1,1

94&comma;1&comma;99.

(5)

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

N100&colon;

ALinearAlgebra:-RandomMatrixN&comma;N&comma;outputoptions=datatype=float

rtable_scanblockA&comma;N..N&comma;1..N&comma;val&comma;ind&comma;res`if`res2<val&comma;ind&comma;val&comma;res&comma;1&comma;1&comma;A1,1&comma;val&comma;ind&comma;res`if`val<res2&comma;ind&comma;val&comma;res&comma;1&comma;1&comma;A1,1

100&comma;4&comma;96.,100&comma;12&comma;−95.

(6)

Compatibility

• 

The rtable_scanblock command was updated in Maple 2020.

See Also

Array

for

Matrix

rtable

rtable_dims

seq

Vector