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
RTableSparseCompact(kv, rt)
RTableSparseIndexRow(kv, rt, dim)
RTableSparseIndexSort(kv, rt, by_dim)
RTableSparseSetNumElems(kv, rt, num)
RTableSparseSize(kv, rt)
RTableSparseResize(kv, rt, size)
kv
-
kernel handle of type MKernelVector
rt
type ALGEB rtable object
dim
specify dimension of the rtable
by_dim
num
number of stored elements in the rtable
size
number of storable elements in the existing rtable data block
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.
#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");
RTableGetSettings(kv,&rts,rt);
if( rts.num_dimensions != 2 ) {
MapleRaiseError(kv,"2D rtable expected");
if( rts.storage != RTABLE_SPARSE ) {
MapleRaiseError(kv,"sparse rtable expected");
if( rts.data_type != RTABLE_FLOAT64 ) {
MapleRaiseError(kv,"float[8] rtable expected");
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 )
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 )
row[j] = row[i];
col[j] = col[i]+1;
data[j++] = data[i];
RTableSparseSetNumElems(kv,rt,j);
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
dup_right≔DefineExternal⁡MyFillRight,dll:
M≔Matrix⁡5,5,storage=sparse10,datatype=float8:
M1,1≔1:M2,5≔2:M3,3≔3:M3,4≔4:M5,2≔5:
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.
dup_right⁡M
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.
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.
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.
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
rtable
Download Help Document