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
|
|
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
|
|
•
|
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.
>
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
|
|