RTableSelect
retrieve an element of an rtable in external code
RTableAssign
assign into an rtable in external code
Calling Sequence
Parameters
Description
Examples
RTableSelect(kv, rt, index)
RTableAssign(kv, rt, index, val)
kv
-
kernel handle of type MKernelVector
rt
type ALGEB rtable object
index
integer array denoting the element index
val
RTableData union value
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
#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");
RTableGetSettings(kv,&rts,rt);
if( rts.num_dimensions != 2 ) {
MapleRaiseError(kv,"2D rtable expected");
if( rts.read_only ) {
MapleRaiseError(kv,"cannot modify read-only rtable");
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.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
swaprow≔DefineExternal⁡MySwapRow,dll:
M≔Matrix⁡4,4,storage=sparse:
M1,1≔1:M1,3≔2:M3,2≔3:M3,4≔4:M
1020000003040000
swaprow⁡M,1,3
0304000010200000
M≔Matrix⁡4,4,i,j↦i,shape=symmetric,datatype=integer4
M≔1111122212331234
swaprow⁡M,2,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
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
rtable
Download Help Document