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

Online Help

All Products    Maple    MapleSim


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

Calling Sequence

RTableIndFn(kv, rt, i)

RTableIndFnArgs(kv, rt, i)

Parameters

kv

-

kernel handle of type MKernelVector

rt

-

type ALGEB rtable object

i

-

ith indexing function in an rtable

Description

• 

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.

Examples

    #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");

            return( NULL );

        }

    RTableGetSettings(kv,&rts,rt);

    if( rts.data_type != RTABLE_FLOAT64 ) {

        MapleRaiseError(kv,"float[8] rtable expected");

            return( NULL );

        }

    if( rts.num_dimensions != 2 ) {

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

            return( NULL );

        }

    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");

            return( NULL );

        }

    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");

                    return( NULL );

                }

        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;

        }

        return( rt );

        }

    }

    for( i=0; i<num_iter; ++i ) {

        RTableAssign(kv,rt,index,rtd);

        index[0]++;

        index[1]++;

    }

    return( rt );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

setdiagDefineExternalMySetDiagonal&comma;dll&colon;

MMatrix5&comma;5&comma;i&comma;j5i5+j&comma;shape=band1,2&comma;datatype=float8

M1.2.3.0.0.6.7.8.9.0.0.12.13.14.15.0.0.18.19.20.0.0.0.24.25.

(1)

setdiagM&comma;2&comma;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.

(2)

setdiagM&comma;1&comma;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.

(3)

setdiagM&comma;0&comma;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.

(4)

setdiagM&comma;1&comma;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.

(5)

MMatrix5&comma;5&comma;fill=1&comma;shape=symmetric&comma;datatype=float8

M1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.

(6)

setdiagM&comma;1&comma;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.

(7)

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

rtable

rtable_indexingfunctions

rtable_indfns