rtable_eval - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Evaluation : rtable_eval

rtable_eval

evaluate the entries of an rtable under certain conditions

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Calling Sequence

rtable_eval(A,inplace)

Parameters

A

-

rtable object

inplace

-

(optional) BooleanOpt(inplace); specifies if output overwrites input

Description

• 

The rtable_eval(A) command, where A is an Array, Matrix, or Vector, returns either a copy of A, or the original input A depending if evaluation is needed.  It also changes the way elements are evaluated when the returned rtable is subsequently referenced.

  

Evaluation is needed provided the following two conditions are met. Firstly, eval(A[i],1) <> eval(A[i]) for a given element Ai.  Secondly, full evaluation must have been applied to A prior to calling rtable_eval(A).

  

Applying eval() to an rtable returns immediately without changing the given rtable.  This is unlike a list, which maps eval() onto each element and returns a copy.  Evaluation of rtable elements is normally deferred until elements are referenced.  If the same elements are repeatedly referenced, evaluation of those elements is also repeated.  The rtable_eval(A) command provides a way to evaluate every element once so that future references can bypass evaluation, without necessarily making a copy.

• 

Applying rtable_eval to any rtable with a hardware datatype always returns the input rtable unchanged.

• 

Applying rtable_eval to any rtable with a user defined indexing-function always returns the input rtable unchanged.

• 

The result of rtable_eval is an rtable with the same attributes as the input rtable, including shape, storage, and datatype.

• 

If the optional second argument, inplace is specified, the input rtable is changed if necessary.  No copy is made.

Thread Safety

• 

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

• 

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

Examples

Create an rtable that prints something when an element is referenced.

p := proc(i) printf("eval element %d\n",i); end proc:

VVector&apos;p1&apos;&comma;&apos;p2&apos;&comma;&apos;p3&apos;&colon;

Reference the first element 4 times. This generates 4 eval()'s.

f := proc(V) V[1]; V[1]; V[1]; V[1]; end proc:

fV

eval element 1
eval element 1
eval element 1
eval element 1

Use rtable_eval() to evaluate every element initially. Subsequent references will already contain the results of evaluating, so V[1] does not print anything.

f := proc(VV) local V; V := rtable_eval(VV); V[1]; V[1]; V[1]; V[1]; end proc:

fV

eval element 1
eval element 2
eval element 3

Generate a Matrix containing polynomials that are expensive to evaluate.

F := proc(n) option remember; if n <= 2 then n else x*F(n-1)+F(n-2); end if; end proc:

MMatrix5&comma;5&comma;i&comma;j&rarr;F5i&plus;j&colon;

Compare the cost of an O(N^3) operation with and without rtable_eval().

dostuff1 := proc(M) local i, j, k, y;
    for i from 1 to op([1,1],M) do
    for j from 1 to op([1,2],M) do
        for k from 1 to op([1,2],M) do
        y := M[i,j];
        end do;
        end do;
    end do;
end proc:

dostuff2 := proc(M) local i, j, k, y;
    rtable_eval(M,'inplace');
    for i from 1 to op([1,1],M) do
    for j from 1 to op([1,2],M) do
        for k from 1 to op([1,2],M) do
        y := M[i,j];
        end do;
        end do;
    end do;
end proc:

timedostuff1M

1.165

(1)

timedostuff2M

0.272

(2)

See Also

Array

eval

Matrix

rtable

Vector

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam