RTableNumDimensions
query the number of dimensions of an rtable in external code
Calling Sequence
Parameters
Description
Examples
RTableNumDimensions(kv, rt)
kv
-
kernel handle of type MKernelVector
rt
type ALGEB rtable object
This function can be used in external code with OpenMaple or define_external.
RTableNumDimensions returns the number of dimensions of the given rtable, rt. This command is equivalent to calling rtable_num_dims.
#include "maplec.h"
ALGEB M_DECL MyFlattenRTable( MKernelVector kv, ALGEB *args )
{
M_INT argc, n, i, num_dims, bounds[2];
ALGEB rt1, rt2, *data1, *data2;
RTableSettings rts;
argc = MapleNumArgs(kv,(ALGEB)args);
if( argc != 1 ) {
MapleRaiseError(kv,"one argument expected");
return( NULL );
}
if( !IsMapleRTable(kv,args[1]) ) {
MapleRaiseError(kv,"rtable expected for parameter 1");
rt1 = args[1];
RTableGetSettings(kv,&rts,rt1);
if( rts.data_type != RTABLE_DAG ) {
MapleRaiseError(kv,"DAG rtable expected for parameter 1");
num_dims = RTableNumDimensions(kv,rt1);
if( num_dims <= 1 )
return( rt1 );
n = RTableNumElements(kv,rt1);
RTableGetDefaults(kv,&rts);
rts.num_dimensions = 1;
rts.subtype = RTABLE_ARRAY;
rts.data_type = RTABLE_DAG;
bounds[0] = 1;
bounds[1] = n;
rt2 = RTableCreate(kv,&rts,NULL,bounds);
data1 = (ALGEB*)RTableDataBlock(kv,rt1);
data2 = (ALGEB*)RTableDataBlock(kv,rt2);
for( i=0; i<n; ++i ) {
data2[i] = data1[i];
return( rt2 );
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
flatten≔DefineExternal⁡MyFlattenRTable,dll:
M≔Matrix⁡3,i,j↦3⋅i−3+j
M≔123456789
flatten⁡M
147258369
M≔Matrix⁡3,i,j↦3⋅i−3+j,order=C_order
123456789
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
rtable
rtable_num_dims
Download Help Document