RTableCopyImPart - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


RTableIsReal

test if an rtable contains only real data in external code

RTableCopyImPart

create a copy of only the imaginary part of a complex rtable in external code

RTableCopyRealPart

create a copy of only the real part of a complex rtable in external code

RTableZipReIm

combine two rtables into a single complex rtable in external code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

RTableIsReal(kv, rt)

RTableCopyImPart(kv, rts, rt)

RTableCopyRealPart(kv, rts, rt)

RTableZipReIm(kv, rts, rt_re, rt_im)

Parameters

kv

-

kernel handle of type MKernelVector

rt, rt_re, rt_im

-

type ALGEB rtable objects

rts

-

pointer to an RTableSettings structure

Description

• 

These functions can be used in external code with OpenMaple or define_external.

• 

RTableIsReal tests if a rtable contains only real-valued numeric data.  A scan of the data is only done for rtables with data_type = RTABLE_DAG.  When the data_type is RTABLE_COMPLEX or RTABLE_CXDAG, FALSE is immediately returned.  For all other data_types, TRUE is immediately returned.

• 

RTableCopyRealPart creates a new rtable containing only the real part of complex numeric data in the rtable rt.  The new rtable has the settings in the supplied OpenMaple/C/RTableSettings structure.

• 

RTableCopyImPart creates a new rtable containing only the imaginary part of complex numeric data in the rtable rt.  The result is an ordinary rtable of numeric data.  If the specified data_type of rt is RTABLE_CXDAG or RTABLE_COMPLEX, the new rtable has 0s in the imaginary part, and the copied data in the real part. The new rtable has the settings in the supplied OpenMaple/C/RTableSettings structure.

• 

RTableZipReIm combines two real numeric rtables rt_re and rt_im into a complex rtable of the form rt_re + I*rt_im. Both rtables must be the same size.  The new rtable has the settings in the supplied OpenMaple/C/RTableSettings structure, provided such settings allow for storage of complex data.

Examples

    #include "maplec.h"

    ALGEB M_DECL MyFilterIm( MKernelVector kv, ALGEB *args )

    {

    M_INT argc, i, numelems;

    RTableSettings rts;

    ALGEB rt, zero, rel, im, r, evalb;

    FLOAT64 val;

    ComplexFloat64 *fdata;

    ALGEB *adata;

    CXDAG *cdata;

    argc = MapleNumArgs(kv,(ALGEB)args);

    if( argc != 2 ) {

        MapleRaiseError(kv,"two arguments expected");

        return( NULL );

    }

    rt = args[1];

    if( !IsMapleRTable(kv,rt) ) {

        MapleRaiseError(kv,"rtable expected");

        return( NULL );

    }

    if( RTableIsReal(kv,rt) )

        return( rt );

    RTableGetSettings(kv,&rts,rt);

    if( MapleNumArgs(kv,rts.index_functions) != 0 ) {

        MapleRaiseError(kv,"cannot handle rtable with indexing function");

        return( NULL );

    }

    if( rts.read_only ) {

        MapleRaiseError(kv,"cannot modify read-only rtable");

        return( NULL );

    }

    numelems = RTableNumElements(kv,rt);

    switch( rts.data_type ) {

    case RTABLE_DAG:

        adata = (ALGEB*)RTableDataBlock(kv,rt);

        evalb = ToMapleName(kv,"evalb",TRUE);

        for( i=0; i<numelems; ++i ) {

        im = MapleSelectImaginaryPart(kv,adata[i]);

        rel = ToMapleRelation(kv,">",args[2],im);

        if( (r=EvalMapleProc(kv,evalb,1,rel)) && MapleToInteger8(kv,r) ) {

            adata[i] = MapleSelectRealPart(kv,adata[i]);

        }

        }

        break;

    case RTABLE_CXDAG:

        cdata = (CXDAG*)RTableDataBlock(kv,rt);

        evalb = ToMapleName(kv,"evalb",TRUE);

        zero = ToMapleFloat(kv,0.0);

        for( i=0; i<numelems; ++i ) {

        rel = ToMapleRelation(kv,">",args[2],cdata[i].im);

        if( (r=EvalMapleProc(kv,evalb,1,rel)) && MapleToInteger8(kv,r) ) {

            cdata[i].im = zero;

        }

        }

        RTableSetType(kv,&rts,RTABLE_DAG,"anything");

        break;

    case RTABLE_COMPLEX:

        fdata = (ComplexFloat64*)RTableDataBlock(kv,rt);

        val = MapleToFloat64(kv,args[2]);

        for( i=0; i<numelems; ++i ) {

        if( fdata[i].im < val ) {

            fdata[i].im = 0.0;

        }

        }

        rts.data_type = RTABLE_FLOAT64;

        break;

    }

    return( RTableCopyImPart(kv,&rts,rt) );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

filterImDefineExternalMyFilterIm&comma;dll&colon;

VVectorrow8&comma;ii+Ii

V1+I2+2I3+3I4+4I5+5I6+6I7+7I8+8I

(1)

filterImV&comma;4

00045678

(2)

V

1234+4I5+5I6+6I7+7I8+8I

(3)

VVector5&comma;i1i+Ii&comma;datatype=complexsfloat

V1.+I0.5000000000+0.5000000000I0.3333333333+0.3333333333I0.2500000000+0.2500000000I0.2000000000+0.2000000000I

(4)

filterImV&comma;0.5

1.0.50000000000.0.0.

(5)

VVector5&comma;ii+I1i0.4&comma;datatype=complexfloat8

V1.+0.600000000000000I2.+0.100000000000000I3.0.0666666667000000I4.0.150000000000000I5.0.200000000000000I

(6)

filterImV&comma;0

0.6000000000000000.1000000000000000.0.0.

(7)

See Also

CustomWrapper

define_external

LinearAlgebra[Zip]

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

rtable