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

Online Help

All Products    Maple    MapleSim


RTableSelect

retrieve an element of an rtable in external code

RTableAssign

assign into an rtable in external code

 

Calling Sequence

Parameters

Description

Examples

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;

dllExternalLibraryNameHelpExamples&colon;

swaprowDefineExternalMySwapRow&comma;dll&colon;

MMatrix4&comma;4&comma;storage=sparse&colon;

M1,11&colon;M1,32&colon;M3,23&colon;M3,44&colon;M

1020000003040000

(1)

swaprowM&comma;1&comma;3

0304000010200000

(2)

MMatrix4&comma;4&comma;i&comma;ji&comma;shape=symmetric&comma;datatype=integer4

M1111122212331234

(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