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

Online Help

All Products    Maple    MapleSim


RTableSparseCompact

remove zero entries of a NAG sparse rtable in external code

RTableSparseIndexRow

retrieve a NAG sparse rtable's index vector in external code

RTableSparseIndexSort

sort a NAG sparse rtable's index vectors in external code

RTableSparseSetNumElems

set the number of stored elements of a NAG sparse rtable in external code

RTableSparseSize

find the size of the data-block of a NAG sparse rtable in external code

RTableSparseResize

resize the data-block of a NAG sparse rtable in external code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

RTableSparseCompact(kv, rt)

RTableSparseIndexRow(kv, rt, dim)

RTableSparseIndexSort(kv, rt, by_dim)

RTableSparseSetNumElems(kv, rt, num)

RTableSparseSize(kv, rt)

RTableSparseResize(kv, rt, size)

Parameters

kv

-

kernel handle of type MKernelVector

rt

-

type ALGEB rtable object

dim

-

specify dimension of the rtable

by_dim

-

specify dimension of the rtable

num

-

number of stored elements in the rtable

size

-

number of storable elements in the existing rtable data block

Description

• 

These functions can be used in external code with OpenMaple or define_external.

• 

RTableSparseCompact removes zero entries from a NAG sparse rtable.  Such rtables can be manipulated in external code, but on return to Maple, they must not contain zero entries or duplicates.

• 

RTableSparseIndexRow retrieves the ith index vector from a NAG sparse rtable.  NAG sparse rtables have one index vector for every dimension, plus a data vector.  The ith entries of the index vectors combine to form the index that specifies the ith data entry.

• 

RTableSparseIndexSort sorts the index vectors in a NAG sparse rtable. The by_dim parameter indicates which vector is sorted first.  A value of 1 indicates that the row vector in a 2-D rtable is sorted first. A value of 2 indicates the column vector of the same rtable is sorted first. Internally Maple maintains the index vectors in two sections, the first part is assumed to be sorted, and the second part is unsorted. A sort is automatically triggered when the unsorted section becomes too large.  A value of by_dim = -1 indicates that the order of the first part may have changed, so the entire data vector must be resorted. Otherwise, sorting by row assumes the first block is sorted so only sorts the second block, and then merges the two blocks.  Changing the order without resorting results in unpredictable rtable access from Maple.

• 

NAG sparse rtables usually have space for inserting new elements without reallocating the index and data vectors.  If external code makes use of this space, then RTableSparseSetNumElems must be called to update the internal structure with the new number of elements stored in the rtable.  The size of the data block can be retrieved by calling RTableSparseSize.  To increase or reduce the size of the data block, use RTableSparseResize.

Examples

    #include "maplec.h"

    ALGEB M_DECL MyFillRight( MKernelVector kv, ALGEB *args )

    {

    M_INT argc, i, j, colbound, size, numelems;

    RTableSettings rts;

    ALGEB rt;

    NAG_INT *row, *col;

    FLOAT64 *data;

    argc = MapleNumArgs(kv,(ALGEB)args);

    if( argc != 1 ) {

        MapleRaiseError(kv,"one 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.storage != RTABLE_SPARSE ) {

        MapleRaiseError(kv,"sparse rtable expected");

        return( NULL );

    }

    if( rts.data_type != RTABLE_FLOAT64 ) {

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

        return( NULL );

    }

    size = RTableSparseSize(kv,rt);

    numelems = RTableNumElements(kv,rt);

    if( numelems == 0 )

        return( rt );

    RTableSparseIndexSort(kv,rt,1);

    if( 2*numelems > size ) {

        RTableSparseResize(kv,rt,2*numelems);

    }

    data = (FLOAT64*)RTableDataBlock(kv,rt);

    if( !data )

        return( rt );

    row = RTableSparseIndexRow(kv,rt,1);

    col = RTableSparseIndexRow(kv,rt,2);

    colbound = RTableUpperBound(kv,rt,1);

    for( i=0, j=numelems; i<numelems; ++i ) {

        if( col[i] == colbound )

        continue;

        if( i < numelems-1 && row[i+1] == row[i] && col[i+1] == col[i]+1 )

        continue;

        row[j] = row[i];

        col[j] = col[i]+1;

        data[j++] = data[i];

    }

    RTableSparseSetNumElems(kv,rt,j);

    return( rt );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

dup_rightDefineExternalMyFillRight&comma;dll&colon;

MMatrix5&comma;5&comma;storage=sparse10&comma;datatype=float8&colon;

M1,11&colon;M2,52&colon;M3,33&colon;M3,44&colon;M5,25&colon;

M

1.0.0.0.0.0.0.0.0.2.0.0.3.4.0.0.0.0.0.0.0.5.0.0.0.

(1)

dup_rightM

1.1.0.0.0.0.0.0.0.2.0.0.3.4.4.0.0.0.0.0.0.5.5.0.0.

(2)

dup_rightM

1.1.1.0.0.0.0.0.0.2.0.0.3.4.4.0.0.0.0.0.0.5.5.5.0.

(3)

dup_rightM

1.1.1.1.0.0.0.0.0.2.0.0.3.4.4.0.0.0.0.0.0.5.5.5.5.

(4)

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

rtable