RTableNumDimensions - Maple Help

RTableNumDimensions

query the number of dimensions of an rtable in external code

 Calling Sequence RTableNumDimensions(kv, rt)

Parameters

 kv - kernel handle of type MKernelVector rt - type ALGEB rtable object

Description

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

Examples

 #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"); return( NULL ); } rt1 = args[1]; RTableGetSettings(kv,&rts,rt1); if( rts.data_type != RTABLE_DAG ) { MapleRaiseError(kv,"DAG rtable expected for parameter 1"); return( NULL ); } 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

Execute the external function from Maple.

 > $\mathrm{with}\left(\mathrm{ExternalCalling}\right):$
 > $\mathrm{dll}≔\mathrm{ExternalLibraryName}\left("HelpExamples"\right):$
 > $\mathrm{flatten}≔\mathrm{DefineExternal}\left("MyFlattenRTable",\mathrm{dll}\right):$
 > $M≔\mathrm{Matrix}\left(3,\left(i,j\right)↦3\cdot i-3+j\right)$
 ${M}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\\ {7}& {8}& {9}\end{array}\right]$ (1)
 > $\mathrm{flatten}\left(M\right)$
 $\left[\begin{array}{ccccccccc}{1}& {4}& {7}& {2}& {5}& {8}& {3}& {6}& {9}\end{array}\right]$ (2)
 > $M≔\mathrm{Matrix}\left(3,\left(i,j\right)↦3\cdot i-3+j,\mathrm{order}='\mathrm{C_order}'\right)$
 ${M}{≔}\left[\begin{array}{ccc}{1}& {2}& {3}\\ {4}& {5}& {6}\\ {7}& {8}& {9}\end{array}\right]$ (3)
 > $\mathrm{flatten}\left(M\right)$
 $\left[\begin{array}{ccccccccc}{1}& {2}& {3}& {4}& {5}& {6}& {7}& {8}& {9}\end{array}\right]$ (4)