RTableIndFn
retrieve an indexing function code in external code
RTableIndFnArgs
retrieve arguments for an indexing function code in external code
Calling Sequence
Parameters
Description
Examples
RTableIndFn(kv, rt, i)
RTableIndFnArgs(kv, rt, i)
kv
-
kernel handle of type MKernelVector
rt
type ALGEB rtable object
i
ith indexing function in an rtable
These functions can be used in external code with OpenMaple or define_external.
RTableIndFn returns the RTABLE_INDEX_* code denoting the kind of indexing function used by the rtable rt. Since rtables can have more than one indexing function, the parameter i specifies which index function to examine. Use MapleNumArgs on the RTableSettings indexing_functions field to determine the number of indexing functions an rtable has. Typically an rtable has no indexing functions.
Some indexing functions have extra data associated with them. For example band is usually denoted band[p1,p2] where p1 and p2 are the number of diagonals above and below the main diagonal. These extra arguments can be retrieved using RTableIndFnArgs.
#include <string.h>
#include "maplec.h"
ALGEB M_DECL MySetDiagonal( MKernelVector kv, ALGEB *args )
{
M_INT argc, i, diag, size, index[2], num_iter;
RTableSettings rts;
RTableData rtd;
ALGEB rt;
argc = MapleNumArgs(kv,(ALGEB)args);
if( argc != 3 ) {
MapleRaiseError(kv,"three arguments expected");
return( NULL );
}
rt = args[1];
if( !IsMapleRTable(kv,rt) ) {
MapleRaiseError(kv,"rtable expected");
RTableGetSettings(kv,&rts,rt);
if( rts.data_type != RTABLE_FLOAT64 ) {
MapleRaiseError(kv,"float[8] rtable expected");
if( rts.num_dimensions != 2 ) {
MapleRaiseError(kv,"2D rtable expected");
if( RTableUpperBound(kv,rt,1) != RTableUpperBound(kv,rt,2)
|| RTableLowerBound(kv,rt,1) != 1
|| RTableLowerBound(kv,rt,2) != 1 ) {
MapleRaiseError(kv,
"square rtable with indexing starting at 1 expected");
rtd.float64 = MapleToFloat64(kv,args[3]);
diag = MapleToM_INT(kv,args[2]);
size = RTableUpperBound(kv,rt,1) - RTableLowerBound(kv,rt,1) + 1;
if( diag > size-1 )
return( rt );
if( diag < 0 ) {
index[0] = 1;
index[1] = -diag+1;
num_iter = size - index[1] + 1;
else {
index[0] = diag+1;
index[1] = 1;
num_iter = size - index[0] + 1;
if( MapleNumArgs(kv,rts.index_functions) == 1
&& RTableIndFn(kv,rt,1) == RTABLE_INDEX_BAND
&& rts.order == RTABLE_FORTRAN
&& rts.storage == RTABLE_BAND ) {
M_INT p1, p2, j;
ALGEB band_args;
FLOAT64 *data;
band_args = RTableIndFnArgs(kv,rt,1);
p1 = MapleToM_INT(kv,(ALGEB)band_args[1]);
p2 = MapleToM_INT(kv,(ALGEB)band_args[2]);
if( p1 == rts.p1 && p2 == rts.p2 ) {
if( (diag < 0 && -diag > p2)
|| (diag > 0 && diag > p1) ) {
MapleRaiseError(kv,"diagonal outside of bands");
data = (FLOAT64*)RTableDataBlock(kv,rt);
j = MATRIX_OFFSET_FORTRAN_BAND(index[0],index[1],
size,size,p1,p2);
for( i=0; i<num_iter; ++i ) {
data[j] = rtd.float64;
j += p1+p2+1;
RTableAssign(kv,rt,index,rtd);
index[0]++;
index[1]++;
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
setdiag≔DefineExternal⁡MySetDiagonal,dll:
M≔Matrix⁡5,5,i,j↦5⋅i−5+j,shape=band1,2,datatype=float8
M≔1.2.3.0.0.6.7.8.9.0.0.12.13.14.15.0.0.18.19.20.0.0.0.24.25.
setdiag⁡M,−2,55
1.2.55.0.0.6.7.8.55.0.0.12.13.14.55.0.0.18.19.20.0.0.0.24.25.
setdiag⁡M,−1,66
1.66.55.0.0.6.7.66.55.0.0.12.13.66.55.0.0.18.19.66.0.0.0.24.25.
setdiag⁡M,0,77
77.66.55.0.0.6.77.66.55.0.0.12.77.66.55.0.0.18.77.66.0.0.0.24.77.
setdiag⁡M,1,88
77.66.55.0.0.88.77.66.55.0.0.88.77.66.55.0.0.88.77.66.0.0.0.88.77.
M≔Matrix⁡5,5,fill=1,shape=symmetric,datatype=float8
M≔1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.
setdiag⁡M,1,99
1.99.1.1.1.99.1.99.1.1.1.99.1.99.1.1.1.99.1.99.1.1.1.99.1.
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
rtable
rtable_indexingfunctions
rtable_indfns
Download Help Document