retrieve an element of an rtable in external code - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : RTable Manipulation : OpenMaple/C/RTableSelect

RTableSelect - retrieve an element of an rtable in external code

RTableAssign - assign into an rtable in external code

Calling Sequence

RTableSelect(kv, rt, index)

RTableAssign(kv, rt, index, val)

Parameters

kv

-

kernel handle of type MKernelVector

rt

-

type ALGEB rtable object

index

-

integer array denoting the element index

val

-

RTableData union value

Description

• 

These functions can be used in external code with OpenMaple or define_external.

• 

RTableSelect extracts the element at the index from the rtable rt.  RTableAssign sets the element at the index in the rtable rt to val.

• 

These functions are especially useful for extracting elements from rtables with indexing functions or unusual storage.  For example, assigning directly to the data-block of a dense symmetric Matrix may violate the symmetric property of the Matrix unless you are careful to ensure the element reflected along the diagonal is also updated.   This is automatically handled when using RTableSelect and RTableAssign.

• 

The value val set by RTableAssign, and returned by RTableSelect is one of the datatypes in the RTableData union.  The type must exactly correspond to the rtable data_type.  The following union members match with these rtable_types.

 

 

 

TYPE

NAME

DATA-TYPE

 

 

 

INTEGER8

int8

RTABLE_INTEGER8

INTEGER16

int16

RTABLE_INTEGER16

INTEGER32

int32

RTABLE_INTEGER32

INTEGER64

int64

RTABLE_INTEGER64

FLOAT32

float32

RTABLE_FLOAT32

FLOAT64

float64

RTABLE_FLOAT64

ComplexFloat64

complexf64

RTABLE_COMPLEX

CXDAG

cxdag

RTABLE_CXDAG

ALGEB

dag

RTABLE_DAG

 

 

 

Examples

    #include "maplec.h"

    ALGEB M_DECL MySwapRow( MKernelVector kv, ALGEB *args )

    {

    M_INT argc, i, index1[2], index2[2];

    RTableSettings rts;

    RTableData rtd1, rtd2;

    ALGEB rt;

    argc = MapleNumArgs(kv,(ALGEB)args);

    if( argc != 3 ) {

        MapleRaiseError(kv,"three argument expected");

        return( NULL );

    }

    rt = args[1];

    if( !IsMapleRTable(kv,rt) ) {

        MapleRaiseError(kv,"rtable expected");

        return( NULL );

    }

    RTableGetSettings(kv,&rts,rt);

    if( rts.num_dimensions != 2 ) {

        MapleRaiseError(kv,"2D rtable expected");

        return( NULL );

    }

    if( rts.read_only ) {

        MapleRaiseError(kv,"cannot modify read-only rtable");

        return( NULL );

    }

    index1[0] = MapleToM_INT(kv,args[2]);

    index2[0] = MapleToM_INT(kv,args[3]);

    for( i=RTableLowerBound(kv,rt,2); i<=RTableUpperBound(kv,rt,2); ++i ) {

        index1[1] = i;

        index2[1] = i;

        rtd1 = RTableSelect(kv,rt,index1);

        rtd2 = RTableSelect(kv,rt,index2);

        if( rts.data_type == RTABLE_INTEGER32 ) {

        MaplePrintf(kv,"Swapping rt[%d,%d] = %d and rt[%d,%d] = %dn",

            index1[0],index1[1],rtd1.int32,

            index2[0],index2[1],rtd2.int32 );

        }

        RTableAssign(kv,rt,index1,rtd2);

        RTableAssign(kv,rt,index2,rtd1);

    }

    return( rt );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dll:=ExternalLibraryNameHelpExamples&colon;

swaprow:=DefineExternalMySwapRow&comma;dll&colon;

M:=Matrix4&comma;4&comma;storage&equals;sparse&colon;

M1&comma;1:=1&colon;M1&comma;3:=2&colon;M3&comma;2:=3&colon;M3&comma;4:=4&colon;M

1020000003040000

(1)

swaprowM&comma;1&comma;3

0304000010200000

(2)

M:=Matrix4&comma;4&comma;i&comma;j&rarr;i&comma;shape&equals;symmetric&comma;datatype&equals;integer4

M:=1111122212331234

(3)

swaprowM&comma;2&comma;3

Swapping rt[2,1] = 1 and rt[3,1] = 1
Swapping rt[2,2] = 2 and rt[3,2] = 2
Swapping rt[2,3] = 2 and rt[3,3] = 3
Swapping rt[2,4] = 2 and rt[3,4] = 3

1111123313221324

(4)

See Also

CustomWrapper, define_external, OpenMaple, OpenMaple/C/API, OpenMaple/C/Examples, rtable


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