RTableAssign - Maple Help

# 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 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.

 > $\mathrm{with}\left(\mathrm{ExternalCalling}\right):$
 > $\mathrm{dll}≔\mathrm{ExternalLibraryName}\left("HelpExamples"\right):$
 > $\mathrm{swaprow}≔\mathrm{DefineExternal}\left("MySwapRow",\mathrm{dll}\right):$
 > $M≔\mathrm{Matrix}\left(4,4,\mathrm{storage}=\mathrm{sparse}\right):$
 > $M\left[1,1\right]≔1:$$M\left[1,3\right]≔2:$$M\left[3,2\right]≔3:$$M\left[3,4\right]≔4:$$M$
 $\left[\begin{array}{cccc}{1}& {0}& {2}& {0}\\ {0}& {0}& {0}& {0}\\ {0}& {3}& {0}& {4}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (1)
 > $\mathrm{swaprow}\left(M,1,3\right)$
 $\left[\begin{array}{cccc}{0}& {3}& {0}& {4}\\ {0}& {0}& {0}& {0}\\ {1}& {0}& {2}& {0}\\ {0}& {0}& {0}& {0}\end{array}\right]$ (2)
 > $M≔\mathrm{Matrix}\left(4,4,\left(i,j\right)↦i,\mathrm{shape}=\mathrm{symmetric},\mathrm{datatype}=\mathrm{integer}\left[4\right]\right)$
 ${M}{≔}\left[\begin{array}{cccc}{1}& {1}& {1}& {1}\\ {1}& {2}& {2}& {2}\\ {1}& {2}& {3}& {3}\\ {1}& {2}& {3}& {4}\end{array}\right]$ (3)
 > $\mathrm{swaprow}\left(M,2,3\right)$
 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
 $\left[\begin{array}{cccc}{1}& {1}& {1}& {1}\\ {1}& {2}& {3}& {3}\\ {1}& {3}& {2}& {2}\\ {1}& {3}& {2}& {4}\end{array}\right]$ (4)

 See Also