RTableSparseCompact - Maple Help

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

Execute the external function from Maple.

 > $\mathrm{with}\left(\mathrm{ExternalCalling}\right):$
 > $\mathrm{dll}≔\mathrm{ExternalLibraryName}\left("HelpExamples"\right):$
 > $\mathrm{dup_right}≔\mathrm{DefineExternal}\left("MyFillRight",\mathrm{dll}\right):$
 > $M≔\mathrm{Matrix}\left(5,5,\mathrm{storage}=\mathrm{sparse}\left[10\right],\mathrm{datatype}=\mathrm{float}\left[8\right]\right):$
 > $M\left[1,1\right]≔1:$$M\left[2,5\right]≔2:$$M\left[3,3\right]≔3:$$M\left[3,4\right]≔4:$$M\left[5,2\right]≔5:$
 > $M$
 $\left[\begin{array}{ccccc}{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.}\end{array}\right]$ (1)
 > $\mathrm{dup_right}\left(M\right)$
 $\left[\begin{array}{ccccc}{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.}\end{array}\right]$ (2)
 > $\mathrm{dup_right}\left(M\right)$
 $\left[\begin{array}{ccccc}{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.}\end{array}\right]$ (3)
 > $\mathrm{dup_right}\left(M\right)$
 $\left[\begin{array}{ccccc}{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.}\end{array}\right]$ (4)