query the number of dimensions of an rtable in external code - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : C Application Programming Interface : RTable Manipulation : OpenMaple/C/RTableNumDimensions

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<n; ++i ) {

        data2[i] = data1[i];

    }

    return( rt2 );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dll:=ExternalLibraryNameHelpExamples&colon;

flatten:=DefineExternalMyFlattenRTable&comma;dll&colon;

M:=Matrix3&comma;i&comma;j&rarr;3i1&plus;j

M:=123456789

(1)

flattenM

147258369

(2)

M:=Matrix3&comma;i&comma;j&rarr;3i1&plus;j&comma;order&equals;&apos;C_order&apos;

M:=123456789

(3)

flattenM

123456789

(4)

See Also

CustomWrapper, define_external, OpenMaple, OpenMaple/C/API, OpenMaple/C/Examples, rtable, rtable_num_dims


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam