/* DP decoder backtrack function * * This function performes the backtracking after decoding. * * @param glob Pointer to the global memory structure * @param itDst Destination transducer for backtracking * @return <code>NULL</code> if successfull, the error string otherwise */ const char *fsts_sdp_backtrack(struct fsts_glob *glob,CFst *itDst){ INT32 gwi; CDlpObject_Copy(BASEINST(itDst),BASEINST(((CFst*)glob->algo))); if((gwi=CData_FindComp(AS(CData,itDst->ud),"~GW"))<0){ CData_AddComp(AS(CData,itDst->ud),"~GW",T_DOUBLE); gwi=CData_GetNComps(AS(CData,itDst->ud))-1; } CData_Dstore(AS(CData,itDst->ud),itDst->m_nGw,0,gwi); return NULL; }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Intersect ( CFst* _this, CFst* itSrc1, CFst* itSrc2, INT32 nUnit1, INT32 nUnit2 ) { CFst* itAux1 = NULL; CFst* itAux2 = NULL; CData* idAux = NULL; INT32 nIcTis1 = -1; INT32 nIcTos1 = -1; INT32 nIcTis2 = -1; INT32 nIcTos2 = -1; INT16 nErr = O_K; nIcTis1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TIS); nIcTos1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TOS); nIcTis2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TIS); nIcTos2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TOS); if (nIcTis1<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of left operand"); if (nIcTis2<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of right operand"); ICREATEEX(CFst ,itAux1,"CFst_Intersect.itAux1",NULL); ICREATEEX(CFst ,itAux2,"CFst_Intersect.itAux2",NULL); ICREATEEX(CData,idAux ,"CFst_Intersect.idAux" ,NULL); CFst_Copy(BASEINST(itAux1),BASEINST(itSrc1)); CFst_Copy(BASEINST(itAux2),BASEINST(itSrc2)); if (nIcTos1>=0) { CData_DeleteComps(AS(CData,itAux1->td),nIcTos1,1); CData_SelectComps(idAux,AS(CData,itAux1->td),nIcTis1,1); CData_SetCname(idAux,0,NC_TD_TOS); CData_Join(AS(CData,itAux1->td),idAux); } if (nIcTos2>=0) { CData_DeleteComps(AS(CData,itAux2->td),nIcTos2,1); CData_SelectComps(idAux,AS(CData,itAux2->td),nIcTis2,1); CData_SetCname(idAux,0,NC_TD_TOS); CData_Join(AS(CData,itAux2->td),idAux); } nErr = CFst_Compose(_this,itAux1,itAux2,nUnit1,nUnit2); IDESTROY(itAux1); IDESTROY(itAux2); IDESTROY(idAux); return nErr; }
/** * Initializes the instance from the interpreter command line. * <h3>Note</h3> * <p>You must setup the method invocation context <code>m_lpMic</code> (see * <a href="dlpinst.html"><code class="link">CDlpInstance</code></a>) before * calling this method. Otherwise it will do noting.</p> * * @param _this This instance * @param nRec First record to read * @param nComp First component to read * @param nCount Number of items to read * @return O_K if successfull, an error code otherwise */ INT16 CGEN_PUBLIC CData_InitializeEx(CData* _this, INT32 nRec, INT32 nComp, INT32 nCount) { INT32 nXXR = 0; INT32 nXC = 0; INT32 nR = 0; INT32 nC = 0; INT32 nCtr = 0; BOOL bRead = 0; const char* lpsToken = NULL; if (_this && !CDlpObject_MicGet(BASEINST(_this))) return IERROR(_this,ERR_GENERIC,"No method invocation context",0,0); if (!_this || CData_IsEmpty(_this)) { /* _this == NULL is ok, just remove the tokens between { and } */ do { lpsToken = MIC_NEXTTOKEN_FORCE; if (!lpsToken) return IERROR(_this,DATA_HERESCAN,"}",0,0); } while (dlp_strcmp(lpsToken,"}")!=0); return O_K; } /* Actual setup */ nXXR = CData_GetMaxRecs(_this); nXC = CData_GetNComps(_this); nR = nRec; nC = nComp; bRead = TRUE; for (;;) { lpsToken = MIC_NEXTTOKEN_FORCE; if (!lpsToken) return IERROR(_this,DATA_HERESCAN,"}",0,0); if (dlp_strcmp(lpsToken,"}")==0) break; if (!bRead) continue; if (nR==nXXR || (nCount>=0 && nCtr>=nCount)) { /* Ignore further initializers */ bRead = FALSE; continue; } /* Initialize cell value; skip cell on wildcard '*' initializer */ if (dlp_strcmp(lpsToken,"*")!=0) IF_NOK(dlp_sscanx(lpsToken,CData_GetCompType(_this,nC),CData_XAddr(_this,nR,nC))) IERROR(_this,DATA_BADINITIALIZER,lpsToken,(int)nR,(int)nC); nCtr++; nC++; if (nC==nXC) { nC=nComp; nR++; } } if (nCount>=0&&nCtr<nCount) return IERROR(_this,DATA_INITIALIZERS,"few" ,0,0); if (!bRead ) return IERROR(_this,DATA_INITIALIZERS,"many",0,0); return O_K; }
/* * Manual page at process.def */ INT16 CGEN_PUBLIC CProcess::Status() { CData* d; char s[L_INPUTLINE]; INT32 i; printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Status of instance"); // Protocol printf("\n process %s",BASEINST(_this)->m_lpInstanceName); // Protocol printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n State : 0x%04X",m_nState); // Protocol if (m_nState!=0) // In any but the maiden state { // >> BOOL b = 0; // Comma flag printf(" ("); // Protocol if (m_nState&PRC_DATASENT ) { if(b) printf(", "); printf("data sent" ); b=1; }//... if (m_nState&PRC_RUNNING ) { if(b) printf(", "); printf("running" ); b=1; }//... if (m_nState&PRC_COMPLETE ) { if(b) printf(", "); printf("complete" ); b=1; }//... if (m_nState&PRC_KILLED ) { if(b) printf(", "); printf("killed" ); b=1; }//... if (m_nState&PRC_DATARECEIVED) { if(b) printf(", "); printf("data received"); b=1; }//... printf(")"); // Protocol } // << printf("\n Return value: %ld",(long)m_nRetVal ); // Protocol if (dlp_strlen(m_psTmpFile)) printf("\n Temp. files : %s*",m_psTmpFile); // Protocol dlp_strcpy(s,m_psCmdLine); dlp_strreplace(s,m_psTmpFile,"<tmpfile>"); // Abbreviate command line if (dlp_strlen(m_psCmdLine)) printf("\n Command line: %s" ,s); // Protocol // Show transferred data // ------------------------------------ if (m_iDto) // Have data transfer object { // >> printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Transferred data"); // Protocol d = (CData*)CDlpObject_FindInstanceWord(m_iDto,PRC_S_IDSIGN,NULL); // Get signature table printf("\n - function : %s",(char*)CData_XAddr(d,0,0)); // Protocol (job function name) for (i=1; i<CData_GetNRecs(d); i++) // Loop over function arguemnts printf("\n %13s %s",i==1?"- arguments :":"",(char*)CData_XAddr(d,i,0)); // Protocol (job function arg.) d = (CData*)CDlpObject_FindInstanceWord(m_iDto,PRC_S_IDGLOB,NULL); // Get list of global instances if (d) // Have one for (i=0; i<CData_GetNRecs(d); i++) // Loop over entries printf("\n %13s %-8s %s",i==0?"- globals :":"", // Protocol (global instance) (char*)CData_XAddr(d,i,0),(char*)CData_XAddr(d,i,1)); // | printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); // Protocol printf("\n Transferred program"); // Protocol for (i=0; dlp_strlen(__sSlaveScript[i]); i++) // Loop over slave script lines { // >> dlp_strcpy(s,__sSlaveScript[i]); // Get a line if (strstr(s,"##"))*(strstr(s,"##"))='\0'; // Truncate at comment printf("\n (%02ld) %s",i,dlp_strtrimright(s)); // Protocol (script line) } // << } // << printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); printf("\n"); // Protocol return O_K; // All done }
/** * Removes the variable's value from the stack. This method <em>must</em> be * called from all interactive methods. * * @see Exec */ void CGEN_PROTECTED CVar_PopOwnValue(CVar *_this) { switch (_this->m_nType) { case T_BOOL: CDlpObject_MicGetB(BASEINST(_this),-1,0); break; case T_COMPLEX: case T_RDOUBLE: case T_RDDATA: CDlpObject_MicGetN(BASEINST(_this),-1,0); break; case T_STRING: case T_RSDATA: CDlpObject_MicGetS(BASEINST(_this),-1,0); break; case T_INSTANCE: CDlpObject_MicGetI(BASEINST(_this),-1,0); break; default: DLPASSERT(FMSG("Unknown variable type")); } }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_CopyUi(CFst* _this, CFst* itSrc, CData* idIndex, INT32 nPar) { INT32 i = 0; INT32 nU = 0; /* Validate */ CHECK_THIS_RV(NOT_EXEC); CFst_Check(_this); CFst_Check(itSrc); if (idIndex) { if (CData_IsEmpty(idIndex)) return NOT_EXEC; if (nPar<0) for (i=0; i<CData_GetNComps(idIndex); i++) if (dlp_is_numeric_type_code(CData_GetCompType(idIndex,i))) { nPar=i; break; } if ( nPar<0 || nPar>=CData_GetNComps(idIndex) || !dlp_is_numeric_type_code(CData_GetCompType(idIndex,nPar)) ) { return IERROR(_this,FST_BADID,"component",nPar,0); } } /* Initialize */ CREATEVIRTUAL(CFst,itSrc,_this); CFst_Reset(BASEINST(_this),TRUE); if (idIndex) { /* Loop over records of idIndex */ for (i=0; i<CData_GetNRecs(idIndex); i++) { nU = (INT32)CData_Dfetch(idIndex,i,nPar); if (nU>=0 && nU<UD_XXU(itSrc)) { DLPASSERT(OK(CFst_CatEx(_this,itSrc,nU,1))) } else IERROR(_this,FST_BADID2,"unit",nU,0); } } else if (nPar<0)
/** * Get data initializer '{ ... }' from command line and store into token list * lpsInit. * <h3>Note</h3> * <p>You must setup the method invocation context <code>m_lpMic</code> (see * <a href="dlpinst.html"><code class="link">CDlpInstance</code></a>) before * calling this method. Otherwise it will do noting.</p> * * @param lpsInit Pointer to character buffer to store initializer in. The * tokens will be separated by nulls '\0', opening and closing * curly braces will not be included! The token list will be * terminated with a double null "\0\0". * @param nLen Maximal number of characters to place on lpsInit (including * the terminal double null) * @param bForce If TRUE the method does not seek for the opening curly brace * but starts reading initializers until it encounters a closing * curly brace '}'. A leading opening curly brace will, however, * be tolerated. If FALSE the method <i>expects</i> an opening * curly brace and does not read any initializers if no leading * opening brace is found. * @return The number of initializers read */ INT32 CGEN_PROTECTED CData_ReadInitializer ( CData* _this, char* lpsInit, INT32 nLen, BOOL bForce ) { const char* lpsToken; /* Current token */ INT32 nCnt; /* Token counter */ INT32 nPos; /* Position in output buffer */ BOOL bStor; /* Store next token */ /* Initialize */ /* --------------------------------- */ if (!CDlpObject_MicGet(BASEINST(_this))) return 0; /* Need invocation context */ if (!lpsInit) return 0; /* Need output buffer */ dlp_memset(lpsInit,0,nLen); /* Clear output buffer */ /* Do initializers follow? */ /* --------------------------------- */ lpsToken = MIC_NEXTTOKEN_FORCE; /* Ruthlessly get next token */ if (!lpsToken || dlp_strcmp(lpsToken,"{")!=0) /* No or not the "{" token */ { /* >> */ if (bForce) IERROR(_this,DATA_NOTFOUND,"Constant initializer ","'{'",0); /* If there should be some-> error */ if (lpsToken) MIC_REFUSETOKEN; /* Wrong token -> push it back */ return 0; /* Now get out'a here */ } /* << */ /* Get 'em tokens */ /* --------------------------------- */ for (nCnt=0,nPos=0,bStor=TRUE; ; nCnt++) /* Infinitely ... */ { /* >> */ lpsToken = MIC_NEXTTOKEN_FORCE; /* Ruthlessly get next token */ if (!lpsToken) return IERROR(_this,DATA_HERESCAN,"}",0,0); /* No more tokens -> forget it */ if (dlp_strcmp(lpsToken,"}")==0) break; /* End token -> get out'a here */ if (nLen<nPos+(INT32)dlp_strlen(lpsToken)+2) bStor = FALSE; /* Cannot store more tokens :( */ if (!bStor) continue; /* Ignore ALL following tokens */ dlp_strcpy(&lpsInit[nPos],lpsToken); /* Store token */ nPos+=(INT32)dlp_strlen(&lpsInit[nPos])+1; /* Set next token pointer */ } /* << */ return nCnt; /* Return number of tokens read */ }
INT16 CCPproc::Quantize() { INT16 __nErr = O_K; INT32 nQuant; INT32 nFirst; INT32 nCount; CData* idFea; CData* idRes; MIC_CHECK; nQuant = (INT32)MIC_GET_N(1,0); nCount = (INT32)MIC_GET_N(2,1); nFirst = (INT32)MIC_GET_N(3,2); idFea = (CData*)MIC_GET_I_EX(idFea,data,4,3); ICREATEEX(CData,idRes,"#TMP#-quantize",NULL); __nErr = QuantizeImpl(idFea, nFirst, nCount, nQuant, idRes); MIC_PUT_I(BASEINST(idRes)); return __nErr; return O_K; }
void CFsttools_Constructor(CFsttools* _this, const char* lpInstanceName, BOOL bCallVirtual) { DEBUGMSG(-1,"CFsttools_Constructor; (bCallVirtual=%d)",(int)bCallVirtual,0,0); #ifndef __cplusplus /* Register instance */ dlp_xalloc_register_object('J',_this,1,sizeof(CFsttools), __FILE__,__LINE__,"fsttools",lpInstanceName); /* Create base instance */ _this->m_lpBaseInstance = calloc(1,sizeof(CDlpObject)); CDlpObject_Constructor(_this->m_lpBaseInstance,lpInstanceName,FALSE); /* Override virtual member functions */ _this->m_lpBaseInstance->AutoRegisterWords = CFsttools_AutoRegisterWords; _this->m_lpBaseInstance->Reset = CFsttools_Reset; _this->m_lpBaseInstance->Init = CFsttools_Init; _this->m_lpBaseInstance->Serialize = CFsttools_Serialize; _this->m_lpBaseInstance->SerializeXml = CFsttools_SerializeXml; _this->m_lpBaseInstance->Deserialize = CFsttools_Deserialize; _this->m_lpBaseInstance->DeserializeXml = CFsttools_DeserializeXml; _this->m_lpBaseInstance->Copy = CFsttools_Copy; _this->m_lpBaseInstance->ClassProc = CFsttools_ClassProc; _this->m_lpBaseInstance->GetInstanceInfo = CFsttools_GetInstanceInfo; _this->m_lpBaseInstance->IsKindOf = CFsttools_IsKindOf; _this->m_lpBaseInstance->Destructor = CFsttools_Destructor; _this->m_lpBaseInstance->ResetAllOptions = CFsttools_ResetAllOptions; /* Override pointer to derived instance */ _this->m_lpBaseInstance->m_lpDerivedInstance = _this; #endif /* #ifndef __cplusplus */ dlp_strcpy(BASEINST(_this)->m_lpClassName,"fsttools"); dlp_strcpy(BASEINST(_this)->m_lpObsoleteName,""); dlp_strcpy(BASEINST(_this)->m_lpProjectName,"fsttools"); dlp_strcpy(BASEINST(_this)->m_version.no,"1.00 DLC22"); dlp_strcpy(BASEINST(_this)->m_version.date,""); BASEINST(_this)->m_nClStyle = CS_AUTOACTIVATE; if (bCallVirtual) { DLPASSERT(OK(INVOKE_VIRTUAL_0(AutoRegisterWords))); INVOKE_VIRTUAL_1(Init,TRUE); } }
/** * Implementation of the class function. Leaves the value of the variable on * the stack. */ void CGEN_PROTECTED CVar_Exec(CVar *_this) { switch (_this->m_nType) { case T_BOOL: CDlpObject_MicPutB(BASEINST(_this),_this->m_bBVal); break; case T_DOUBLE: case T_COMPLEX: CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal); break; case T_STRING: CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal); break; case T_INSTANCE: CDlpObject_MicPutI(BASEINST(_this),BASEINST(_this)->m_iAliasInst); break; case T_RDOUBLE: { _this->m_nInd = (INT32)(rand()/_this->m_nNorm); _this->m_nNVal = CMPLX(_this->m_nLow+_this->m_nInd*_this->m_nDelta); CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal); break; } case T_RDDATA: _this->m_nInd = (INT32)(rand()/_this->m_nNorm); _this->m_nNVal = CData_Cfetch(AS(CData,_this->m_idRndSet),_this->m_nInd, _this->m_nIcomp); CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal); break; case T_RSDATA: _this->m_nInd = (INT32)(rand()/_this->m_nNorm); CVar_Sset(_this,(char*)CData_XAddr(AS(CData,_this->m_idRndSet),_this->m_nInd,_this->m_nIcomp)); _this->m_nType = T_RSDATA; CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal); break; default: DLPASSERT(FMSG("Unknown variable type")); } }
INT16 CDlpFile_Reset(CDlpObject* __this, BOOL bResetMembers) { GET_THIS_VIRTUAL_RV(CDlpFile,NOT_EXEC); DEBUGMSG(-1,"CDlpFile_Reset; (bResetMembers=%d)",(int)bResetMembers,0,0); { /*{{CGEN_RESETCODE */ CData* idFlistData; char lpsB1[255]; char lpsB2[255]; char lpsB3[ 32]; char lpsB4[255]; if (_this->m_idFlistData==NULL) IFIELD_RESET(CData,"flist_data"); IFIELD_RESET(CData,"recfile"); dlp_strcpy(lpsB1,_this->m_lpsFlist); dlp_strcpy(lpsB2,_this->m_lpsPath); dlp_strcpy(lpsB3,_this->m_lpsExt); dlp_strcpy(lpsB4,_this->m_lpsSep); idFlistData = AS(CData,_this->m_idFlistData); _this->m_idFlistData = NULL; RESET; _this->m_idFlistData = BASEINST(idFlistData); dlp_strcpy(_this->m_lpsFlist,lpsB1); dlp_strcpy(_this->m_lpsPath ,lpsB2); dlp_strcpy(_this->m_lpsExt ,lpsB3); dlp_strcpy(_this->m_lpsSep ,lpsB4); _this->m_nLen = CData_GetNRecs(AS(CData,_this->m_idFlistData)); /*}}CGEN_RESETCODE */ } return O_K; }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Compose ( CFst* _this, CFst* itSrc1, CFst* itSrc2, INT32 nUnit1, INT32 nUnit2 ) { BOOL bNoeps; /* No implicit insertion of e.-loops */ BOOL bNoint; /* No intermediate symbols flag */ INT16 nCheck = 0; /* Verbose level */ INT16 nVirt = 0; /* Auxiliary: patching ovrl.args. bug*/ const char *err; /* Validate */ CHECK_THIS_RV(NOT_EXEC); CFst_Check(itSrc1); CFst_Check(itSrc2); if (itSrc1==NULL || itSrc2==NULL) { CFst_Reset(BASEINST(_this),TRUE); return O_K; } if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0); if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0); if (CFst_Wsr_GetType(itSrc1,NULL)!=CFst_Wsr_GetType(itSrc2,NULL)) return IERROR(_this,FST_INCOMPATIBLE,"weight semirings","itSrc1 and itSrc2",0); if (CData_FindComp(AS(CData,itSrc1->td),NC_TD_TIS)<0) return IERROR(_this,FST_MISS,"input symbol component" ,"","transition table of itSrc1"); if (CData_FindComp(AS(CData,itSrc1->td),NC_TD_TOS)<0) return IERROR(_this,FST_MISS,"output symbol component","","transition table of itSrc1"); if (CData_FindComp(AS(CData,itSrc2->td),NC_TD_TIS)<0) return IERROR(_this,FST_MISS,"input symbol component" ,"","transition table of itSrc2"); if (CData_FindComp(AS(CData,itSrc2->td),NC_TD_TOS)<0) return IERROR(_this,FST_MISS,"output symbol component","","transition table of itSrc2"); bNoeps = _this->m_bNoeps; bNoint = _this->m_bNoint; nCheck = BASEINST(_this)->m_nCheck; /* Initialize - NO RETURNS BEYOND THIS POINT */ /* HACK: Multiple overlapping arguments on _this not handled correctly by CREATEVIRTUAL --> */ if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0); if (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; } else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; } /* <-- */ if((err=fstc_compose(itSrc1,nUnit1,itSrc2,nUnit2, bNoeps,bNoint,nCheck, _this))) return IERROR(_this,FST_INVALID,err,0,0); /* Copy input and output symbol tables */ CData_SelectComps(AS(CData,_this->is),AS(CData,itSrc1->is),IS_XXS(itSrc1)==UD_XXU(itSrc1)?nUnit1:0,1); CData_SelectComps(AS(CData,_this->os),AS(CData,itSrc2->os),OS_XXS(itSrc2)==UD_XXU(itSrc2)?nUnit2:0,1); /* Clean up */ if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); } if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); } CFst_Check(_this); CFst_TrimStates(_this,0); return O_K; }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Rcs(CFst* _this, INT32 nUnit, FLOAT64 nSeed) { #ifdef __UNENTANGLE_FST return IERROR(_this,FST_INTERNAL,__FILE__,__LINE__,0); /* NOTE: __UNENTANGLE_FST was defined (probably in dlp_config.h or fst.def). * Undefine it to use this feature! */ #else /* #ifdef __UNENTANGLE_FST */ INT32 nU = 0; /* Current unit */ FST_ITYPE nS = 0; /* Current state */ FST_ITYPE nS2 = 0; /* Current state */ FST_ITYPE nFS = 0; /* First state of current unit */ FST_ITYPE nXS = 0; /* Number of states of current unit */ FST_ITYPE nT = 0; /* Current transition */ FST_ITYPE nFT = 0; /* First transition of current unit */ FST_ITYPE nXT = 0; /* Number of tran. of current unit */ CData* idP = NULL; /* Incidence matrix */ CData* idB = NULL; /* Constanct vector of (idP-E)idX=idB */ CData* idI = NULL; /* idI = (idP-E)^-1 */ CData* idX = NULL; /* Solution of (idP-E)idX=idB */ FST_WTYPE nPSum = 0.; /* Probability sum/state */ INT32 nIcW = -1; /* Index of probability comp. in td */ INT32 nIcRcs = -1; /* Index of ref. counter comp. in sd */ INT32 nIcRct = -1; /* Index of ref. counter comp. in td */ /* Validation */ CHECK_THIS_RV(NOT_EXEC); CFst_Check(_this); if (CFst_Wsr_GetType(_this,&nIcW)!=FST_WSR_PROB) return IERROR(_this,FST_MISS,"transition probability component",NC_TD_PSR,"transition table"); /* Initialize - Find or add reference counters */ nIcRcs = CData_FindComp(AS(CData,_this->sd),NC_SD_RC); nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC); if (nIcRcs<0) { CData_AddComp(AS(CData,_this->sd),NC_SD_RC,DLP_TYPE(FST_WTYPE)); nIcRcs = CData_GetNComps(AS(CData,_this->sd))-1; } if (nIcRct<0) { CData_AddComp(AS(CData,_this->td),NC_TD_RC,DLP_TYPE(FST_WTYPE)); nIcRct = CData_GetNComps(AS(CData,_this->td))-1; } /* Initialize - Create auxilary instances */ ICREATEEX(CData,idP,"~CFst_Reverse.idP",NULL); ICREATEEX(CData,idB,"~CFst_Reverse.idB",NULL); ICREATEEX(CData,idI,"~CFst_Reverse.idI",NULL); ICREATEEX(CData,idX,"~CFst_Reverse.idX",NULL); /* Loop over units */ for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++) { CData_Reset(BASEINST(idP),TRUE); CData_Reset(BASEINST(idB),TRUE); CData_Reset(BASEINST(idI),TRUE); CData_Reset(BASEINST(idX),TRUE); nFS = UD_FS(_this,nU); nXS = UD_XS(_this,nU); nFT = UD_FT(_this,nU); nXT = UD_XT(_this,nU); /* Export transposed ergodic incidence matrix */ IF_NOK(CData_AddNcomps(idP,DLP_TYPE(FST_WTYPE),UD_XS(_this,nU)+1)) break; IF_NOK(CData_Allocate (idP,UD_XS(_this,nU)+1) ) break; IF_NOK(CData_AddNcomps(idB,DLP_TYPE(FST_WTYPE),1 )) break; IF_NOK(CData_Allocate (idB,UD_XS(_this,nU)+1) ) break; /* Fill transposed incidence matrix (summing up probabilities of parallel transitions) */ for (nT=nFT; nT<nFT+nXT; nT++) *(FST_WTYPE*)CData_XAddr(idP,TD_TER(_this,nT),TD_INI(_this,nT)) += *(FST_WTYPE*)CData_XAddr(AS(CData,_this->td),nT,nIcW); for (nS=0; nS<nXS; nS++) { if ((SD_FLG(_this,nS+nFS)&0x01)==0x01) /* Connect final states with start state */ { for (nS2=1, nPSum=0.; nS2<nXS; nS2++) nPSum += *(FST_WTYPE*)CData_XAddr(idP,nS2,nS); *(FST_WTYPE*)CData_XAddr(idP,0,nS) = 1.-nPSum; } *(FST_WTYPE*)CData_XAddr(idP,nS,nS)-=1.; /* Subtract eigenvalue 1 from main diagonal */ *(FST_WTYPE*)CData_XAddr(idP,nXS,nS)=1.; /* Additional equation implementing constraint sum(P_state)=1 */ *(FST_WTYPE*)CData_XAddr(idP,nS,nXS)=1.; /* Additional variable making incidence matrix quadratic */ } /* Fill constant vector */ CData_Fill(idB,CMPLX(1.),CMPLX(0.)); /* Calculate eigenvector of length 1 and eigenvalue 1 --> stationary state probabilities */ CMatrix_Op(idI,idP,T_INSTANCE,NULL,T_IGNORE,OP_INVT); CMatrix_Op(idX,idB,T_INSTANCE,idI,T_INSTANCE,OP_MULT); /* Fill in state reference counters */ if (nSeed>0.) nSeed /= CData_Dfetch(idX,0,0); else nSeed = 1.; for (nS=0; nS<nXS; nS++) CData_Dstore(AS(CData,_this->sd),nSeed*CData_Dfetch(idX,nS,0),nS+nFS,nIcRcs); /* Calculate stationary transition probabilities */ for (nT=nFT; nT<nFT+nXT; nT++) CData_Dstore ( AS(CData,_this->td), CData_Dfetch(AS(CData,_this->sd),TD_INI(_this,nT)+nFS,nIcRcs) * CData_Dfetch(AS(CData,_this->td),nT,nIcW), nT,nIcRct ); /* Clean up */ IDESTROY(idP); IDESTROY(idB); IDESTROY(idI); IDESTROY(idX); /* Stop in single unit mode */ if (nUnit>=0) break; } return O_K; #endif /* #ifdef __UNENTANGLE_FST */ }
/** * Creates a tree with the best <code>nPaths</code> paths (minimum cost) taken from <code>itSrc</code>. There are no * checks performed. * * @param _this Pointer to this (destination) automaton instance * @param itSrc Pointer to source automaton instance * @param nUnit Index of unit to process * @param nPaths Number of paths to be extracted * @param nPathlength Length of paths to be extracted * @return O_K if successfull, a (negative) error code otherwise * @see BestN CFst_BestN */ INT16 CGEN_PROTECTED CFst_BestNUnit(CFst* _this, CFst* itSrc, INT32 nUnit, INT32 nPaths, INT32 nPathlength) { FST_PQU_TYPE* lpPQ = NULL; /* Priority queue data struct */ FST_TID_TYPE* lpTIX = NULL; /* Source graph iterator data struct */ BYTE* lpTX = NULL; /* Ptr. to current source transition */ FST_ITYPE nFS = 0; /* First state of source unit */ INT32 nArrivals = 0; /* Paths having reached a final state */ FST_WTYPE nNeAdd = 0.; /* Neutral element of addition */ FST_WTYPE nNeMult = 0.; /* Neutral element of multiplication */ FST_ITYPE nPQsize = 0; /* Priority queue size */ FST_ITYPE nT = 0; /* Index of current source transition */ FST_ITYPE nNewT = 0; /* Index of newly inserted dst. trans.*/ FST_ITYPE nSini = 0; /* Ini. state of curr. dest. trans. */ FST_ITYPE nXini = 0; /* Ini. state of curr. source trans. */ FST_ITYPE nYini = 0; /* Ini. state of curr. aux. trans. */ FST_ITYPE nSter = 0; /* Ter. state of curr. dest. trans. */ FST_ITYPE nXter = 0; /* Ter. state of curr. source trans. */ FST_ITYPE nYter = 0; /* Ter. state of curr. aux. trans. */ FST_ITYPE nPlen = 0; /* length of the path up to here */ FST_WTYPE nWX = 0.0; /* Weight of current src. transition */ FST_WTYPE nPot = 0.0; /* Potential of current src. state */ FST_WTYPE nCacc = 0.0; /* Accumulated cost from start state */ FST_WTYPE nCtot = 0.0; /* Total cost to final state */ FST_WTYPE nCmax = 0.0; /* Maximal cost in priority queue */ INT32 nNewY = 0; /* New auxiliary state */ INT32 nIcP = 0; /* Comp. index of src. state potential*/ INT16 nCheck = 0; /* Copy buffer for verbose level */ BOOL bPush = FALSE; /* Copy of m_bPush option */ INT32 k = 0; /* Auxilary loop counter */ /* Validate */ DLPASSERT(_this!=itSrc); DLPASSERT(nUnit>=0 && nUnit<UD_XXU(itSrc)); /* Initialize destination */ nCheck = BASEINST(_this)->m_nCheck; bPush = _this->m_bPush; CFst_Reset(BASEINST(_this),TRUE); BASEINST(_this)->m_nCheck=nCheck; CData_Scopy(AS(CData,_this->sd),AS(CData,itSrc->sd)); CData_Scopy(AS(CData,_this->td),AS(CData,itSrc->td)); CData_SelectRecs(AS(CData,_this->ud),AS(CData,itSrc->ud),nUnit,1); UD_FS(_this,0) = 0; UD_FT(_this,0) = 0; UD_XS(_this,0) = 0; UD_XT(_this,0) = 0; _this->m_nGrany = itSrc->m_nGrany; _this->m_nWsr = CFst_Wsr_GetType(itSrc,&_this->m_nIcW); BASEINST(_this)->m_nCheck = BASEINST(_this)->m_nCheck>BASEINST(itSrc)->m_nCheck?BASEINST(_this)->m_nCheck:BASEINST(itSrc)->m_nCheck; CFst_Cps_AddSdAux(_this); nNeMult = CFst_Wsr_NeMult(_this->m_nWsr); nNeAdd = CFst_Wsr_NeAdd (_this->m_nWsr); /* Add in itSrc the component Extracted that stores how many times this node has been visited */ nIcP = CData_FindComp(AS(CData,itSrc->sd),NC_SD_POT); DLPASSERT(nIcP >=0); DLPASSERT(_this->m_nIcW>=0); /* Initialize - Create priority queue */ lpPQ = (FST_PQU_TYPE*)dlp_calloc(nPaths+1,sizeof(FST_PQU_TYPE)); for (k=0; k<nPaths+1; k++) lpPQ[k].nCtot = nNeAdd; /* Initialize - Graph iterator */ lpTIX = CFst_STI_Init(itSrc,nUnit,FSTI_SORTINI); nFS = UD_FS(itSrc,nUnit); /* Create initial state in _this */ nXter = CFst_Addstates(_this,0,1,SD_FLG(itSrc,nFS)&0x01); CFst_Cps_SetSdAux(_this,nXter,0,0,0); /* Initialize local variables */ nXter = 0; nYter = 0; nCacc = nNeMult; /* Best-N computation */ for(;;) { /* For all transitions leaving nXter */ lpTX = NULL; while ((lpTX=CFst_STI_TfromS(lpTIX,nXter,lpTX))!=NULL) { /* Compute nCtot following the current transition */ nT = CFst_STI_GetTransId(lpTIX,lpTX); nWX = *CFst_STI_TW(lpTIX,lpTX); nPot = *(FST_WTYPE*)(CData_XAddr(AS(CData,itSrc->sd),TD_TER(itSrc,nT)+lpTIX->nFS,nIcP)); nCtot = CFst_Wsr_Op(_this,nCacc,CFst_Wsr_Op(_this,nPot,nWX,OP_MULT),OP_MULT); /* nCacc + nWX + nPot; */ IFCHECKEX(1) printf("\n state: %d \t Cacc: %f\t W: %f \t Pot: %f \t Ctot: %f\t\n", (int)nXter,(float)nCacc,(float)nWX,(float)nPot,(float)nCtot); /* Insert into priority queue? */ if ( nPQsize < (nPaths - nArrivals) || ( nPQsize==(nPaths - nArrivals) && CFst_Wsr_Op(_this,nCtot,nCmax,OP_GREATER) ) ) { nNewY++; /* Push into priority queue */ lpPQ[nPQsize].nXini = nXter; lpPQ[nPQsize].nYini = nYter; lpPQ[nPQsize].nXter = *CFst_STI_TTer(lpTIX,lpTX); lpPQ[nPQsize].nYter = nNewY; lpPQ[nPQsize].nTran = nT; lpPQ[nPQsize].nPlen = nPlen+1; lpPQ[nPQsize].nCacc = CFst_Wsr_Op(_this,nCacc,nWX,OP_MULT); /* nWX + nCacc; */ lpPQ[nPQsize].nCtot = nCtot; nPQsize++; IFCHECKEX(1) printf("\n PriQsize:%d PUSH: [X:%d Y:%d] --- Cacc:%f Tran:%d Plen:%d Ctot:%f ----> [X:%d Y:%d]\n", (int)nPQsize,(int)nXter,(int)nYter,(float)nCacc,(int)nT,(int)nPlen, (float)nCtot,(int)*CFst_STI_TTer(lpTIX,lpTX),(int)nNewY); /* Sort priority queue */ if (_this->m_nWsr == FST_WSR_PROB) qsort(lpPQ,nPaths+1,sizeof(FST_PQU_TYPE),CFst_Bsn_CompDown); else qsort(lpPQ,nPaths+1,sizeof(FST_PQU_TYPE),CFst_Bsn_CompUp); /* Delete last element from queue (if neccesary) to keep its size smaller than nPaths+1 */ if (nPQsize == nPaths+1-nArrivals) { lpPQ[nPQsize-1].nCtot = nNeAdd; nPQsize--; } nCmax = lpPQ[nPQsize-1].nCtot; IFCHECKEX(2) for (k=0; k<nPQsize; k++) printf("Q %d : [X:%d Y:%d] --- Tran:%d ----> [X:%d Y:%d] Plen:%d Cacc:%f ", (int)k,(int)lpPQ[k].nXini,(int)lpPQ[k].nYini,(int)lpPQ[k].nTran, (int)lpPQ[k].nXter,(int)lpPQ[k].nYter,(int)lpPQ[k].nPlen,(float)lpPQ[k].nCacc), printf("Ctot:%f \n",lpPQ[k].nCtot); } } /* Write transition and state in _this */ DLPASSERT(nPQsize>=0); if (nPQsize>0) { /* Pop first record data from priority queue */ nXini = lpPQ[0].nXini; nYini = lpPQ[0].nYini; nXter = lpPQ[0].nXter; nYter = lpPQ[0].nYter; nT = lpPQ[0].nTran; nPlen = lpPQ[0].nPlen; nCacc = lpPQ[0].nCacc; nCtot = lpPQ[0].nCtot; dlp_memmove(lpPQ,&lpPQ[1],nPaths*sizeof(FST_PQU_TYPE)); lpPQ[nPQsize-1].nCtot = nNeAdd; nPQsize--; IFCHECKEX(1) printf(" Pop priority queue\n"); IFCHECKEX(2) for (k=0; k<nPQsize; k++) printf("Q %d : [X:%d Y:%d] --- Tran:%d ----> [X:%d Y:%d] Plen:%d Cacc:%f ", (int)k,(int)lpPQ[k].nXini,(int)lpPQ[k].nYini,(int)lpPQ[k].nTran, (int)lpPQ[k].nXter,(int)lpPQ[k].nYter,(int)lpPQ[k].nPlen,(float)lpPQ[k].nCacc), printf("Ctot:%f \n",(float)lpPQ[k].nCtot); /* Add state and trans in _this */ nSini = CFst_Cps_FindState(_this,nXini,nYini,0); nSter = CFst_Addstates(_this,0,1,(nPathlength<=0||nPlen>=nPathlength)?(SD_FLG(itSrc,nXter+nFS)&0x01):0); /* FS-Flag ist only used if Path is long enough */ CFst_Cps_SetSdAux(_this,nSter,nXter,nYter,0); /* If the path in itSrc is finished and path length exceeded increment nArrivals */ if ((SD_FLG(itSrc,nXter+nFS)&0x01) && (nPathlength<=0 || nPlen>=nPathlength)) { nArrivals++; nWX = nCtot; } else nWX = nNeMult; nNewT = CFst_AddtransCopy(_this,0,nSini,nSter,itSrc,nT); if (bPush) *(FST_WTYPE*)CData_XAddr(AS(CData,_this->td),nNewT,_this->m_nIcW) = nWX; IFCHECKEX(1) printf("\n AddTrans: [X:%d Y:%d] --- Cacc:%f Tran:%d Plen:%d Ctot:%f ----> [X:%d Y:%d]\n", (int)nXini,(int)nYini,(float)nCacc,(int)nT,(int)nPlen,(float)nCtot,(int)nXter,(int)nYter); }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Product ( CFst* _this, CFst* itSrc1, CFst* itSrc2, INT32 nUnit1, INT32 nUnit2 ) { INT32 nC = 0; /* Current component */ INT32 nFCS2 = 0; /* 1st data comp. of state tab.itSrc2 */ INT32 nXCS1 = 0; /* No. of comps. of state tab. itSrc1 */ INT32 nXCS2 = 0; /* No. of comps. of state tab. itSrc2 */ INT32 nFCT2 = 0; /* 1st data comp. of trans.tab.itSrc2 */ INT32 nXCT1 = 0; /* No. of comps. of trans.tab. itSrc1 */ INT32 nXCT2 = 0; /* No. of comps. of trans.tab. itSrc2 */ INT32 nRls1 = 0; /* Rec. len. of state table of itSrc1 */ INT32 nRls2 = 0; /* Rec. len. of state table of itSrc2 */ INT32 nRlt1 = 0; /* Rec. len. of trans.table of itSrc1 */ INT32 nRlt2 = 0; /* Rec. len. of trans.table of itSrc2 */ FST_ITYPE nS1 = 0; FST_ITYPE nS2 = 0; FST_ITYPE nFS1 = 0; FST_ITYPE nFS2 = 0; FST_ITYPE nXS1 = 0; FST_ITYPE nXS2 = 0; FST_ITYPE nT = 0; FST_ITYPE nIni = 0; FST_ITYPE nTer = 0; FST_ITYPE nT1 = 0; FST_ITYPE nT2 = 0; FST_ITYPE nFT1 = 0; FST_ITYPE nFT2 = 0; FST_ITYPE nXT1 = 0; FST_ITYPE nXT2 = 0; char* lpsBuf = NULL; /* String buffer */ INT16 nVirt = 0; /* Auxiliary: patching ovrl.args. bug */ BOOL bNoloopsSave = FALSE; /* Save buffer for /noloops option */ /* Validate */ CHECK_THIS_RV(NOT_EXEC); if (itSrc1==NULL || itSrc2==NULL) { CFst_Reset(BASEINST(_this),TRUE); return O_K; } if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0); if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0); /* Initialize */ /* HACK: Multiple overlapping arguments on _this not handled correctly by CREATEVIRTUAL --> */ if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0); if (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; } else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; } /* <-- */ bNoloopsSave = _this->m_bNoloops; CFst_Reset(BASEINST(_this),TRUE); _this->m_bNoloops = bNoloopsSave; /* Initialize destination state table */ nFS1 = UD_FS(itSrc1,nUnit1); nXS1 = UD_XS(itSrc1,nUnit1); nFS2 = UD_FS(itSrc2,nUnit2); nXS2 = UD_XS(itSrc2,nUnit2); nRls1 = CData_GetRecLen(AS(CData,itSrc1->sd)) - CData_GetCompOffset(AS(CData,itSrc1->sd),IC_SD_DATA); nRls2 = CData_GetRecLen(AS(CData,itSrc2->sd)) - CData_GetCompOffset(AS(CData,itSrc2->sd),IC_SD_DATA); nXCS1 = CData_GetNComps(AS(CData,itSrc1->sd)) - IC_SD_DATA; nXCS2 = CData_GetNComps(AS(CData,itSrc2->sd)) - IC_SD_DATA; nFCS2 = IC_SD_DATA + nXCS1; for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS1; nC++) CData_AddComp ( AS(CData,_this->sd), CData_GetCname(AS(CData,itSrc1->sd),nC), CData_GetCompType(AS(CData,itSrc1->sd),nC) ); for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS2; nC++) CData_AddComp ( AS(CData,_this->sd), CData_GetCname(AS(CData,itSrc2->sd),nC), CData_GetCompType(AS(CData,itSrc2->sd),nC) ); /* Initialize destination transition table */ nFT1 = UD_FT(itSrc1,nUnit1); nXT1 = UD_XT(itSrc1,nUnit1); nFT2 = UD_FT(itSrc2,nUnit2); nXT2 = UD_XT(itSrc2,nUnit2); nRlt1 = CData_GetRecLen(AS(CData,itSrc1->td)) - CData_GetCompOffset(AS(CData,itSrc1->td),IC_TD_DATA); nRlt2 = CData_GetRecLen(AS(CData,itSrc2->td)) - CData_GetCompOffset(AS(CData,itSrc2->td),IC_TD_DATA); nXCT1 = CData_GetNComps(AS(CData,itSrc1->td)) - IC_TD_DATA; nXCT2 = CData_GetNComps(AS(CData,itSrc2->td)) - IC_TD_DATA; nFCT2 = IC_TD_DATA + nXCT1; for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT1; nC++) CData_AddComp ( AS(CData,_this->td), CData_GetCname(AS(CData,itSrc1->td),nC), CData_GetCompType(AS(CData,itSrc1->td),nC) ); for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT2; nC++) CData_AddComp ( AS(CData,_this->td), CData_GetCname(AS(CData,itSrc2->td),nC), CData_GetCompType(AS(CData,itSrc2->td),nC) ); /* Copy input and output symbol tables */ CData_Copy(_this->is,itSrc1->is); CData_Copy(_this->os,itSrc2->os); /* Initialize destination unit */ lpsBuf = (char*)dlp_calloc ( CData_GetCompType(AS(CData,itSrc1->ud),IC_UD_NAME) + CData_GetCompType(AS(CData,itSrc2->ud),IC_UD_NAME) + 2, sizeof(char) ); sprintf ( lpsBuf,"%s.%s", (const char*)CData_XAddr(AS(CData,itSrc1->ud),nUnit1,IC_UD_NAME), (const char*)CData_XAddr(AS(CData,itSrc2->ud),nUnit2,IC_UD_NAME) ); CFst_Addunit(_this,lpsBuf); dlp_free(lpsBuf); /* Add product states */ CFst_Addstates(_this,0,nXS1*nXS2,FALSE); /* Copy state qualification (including final state flag) */ for (nS1=0; nS1<nXS1; nS1++) for (nS2=0; nS2<nXS2; nS2++) { if ((SD_FLG(itSrc1,nS1+nFS1)&0x01)==0x01 && (SD_FLG(itSrc2,nS2+nFS2)&0x01)==0x01) SD_FLG(_this,nS1*nXS2+nS2) |= 0x01; if (nRls1>0) dlp_memmove ( CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,IC_SD_DATA), CData_XAddr(AS(CData,itSrc1->sd),nS1+nFS1 ,IC_SD_DATA), nRls1 ); if (nRls2>0) dlp_memmove ( CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,nFCS2 ), CData_XAddr(AS(CData,itSrc2->sd),nS2+nFS2 ,IC_SD_DATA), nRls2 ); } CData_AddRecs(AS(CData,_this->td),nXT1*nXT2,_this->m_nGrany); /* Loop over all transitions of both factors */ for (nT=0, nT1=nFT1; nT1<nFT1+nXT1; nT1++) for (nT2=nFT2; nT2<nFT2+nXT2; nT2++, nT++) { /* Get product of initial and terminal state */ nIni = TD_INI(itSrc1,nT1)*nXS2 + TD_INI(itSrc2,nT2); nTer = TD_TER(itSrc1,nT1)*nXS2 + TD_TER(itSrc2,nT2); if (_this->m_bNoloops && nIni==nTer) continue; /* Add product transition */ *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_INI) = nIni; *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_TER) = nTer; /* Copy transition qualification */ dlp_memmove ( CData_XAddr(AS(CData,_this ->td),nT ,IC_TD_DATA), CData_XAddr(AS(CData,itSrc1->td),nT1,IC_TD_DATA), nRlt1 ); dlp_memmove ( CData_XAddr(AS(CData,_this ->td),nT ,nFCT2 ), CData_XAddr(AS(CData,itSrc2->td),nT2,IC_TD_DATA), nRlt2 ); } /* Finish destination instance */ CData_SelectRecs(AS(CData,_this->td),AS(CData,_this->td),0,nT); UD_XT(_this,0) = nT; /* TODO: Trim result !? */ /* Clean up */ if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); } if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); } return O_K; }
/** * Appends units from a source automaton instance to this instance. * * @param _this Pointer to destination automaton instance * @param itSrc Pointer to source automaton instance * @param nFirstUnit Index of first unit of <code>itSrc</code> to append to this instance * @param nCount Number of units to append * @return O_K if successfull, a (negative) error code otherwise */ INT16 CGEN_PUBLIC CFst_CatEx(CFst* _this, CFst* itSrc, INT32 nFirstUnit, INT32 nCount) { INT32 nU = 0; /* Current unit */ INT32 nXUd = 0; /* Number of units in destination */ INT32 nFSs = 0; /* First source state to append */ INT32 nXSs = 0; /* Number of source states to append */ INT32 nFTs = 0; /* First source transition to append */ INT32 nXTs = 0; /* Number of source transitions to append */ INT32 nXXSd = 0; /* Total number of states in destination */ INT32 nXXTd = 0; /* Total number of transitions in destination */ /* Validate */ CHECK_THIS_RV(NOT_EXEC); CFst_Check(_this); CFst_Check(itSrc); if (nFirstUnit < 0 ) nFirstUnit = 0; if (nFirstUnit+nCount > UD_XXU(itSrc)) nCount = UD_XXU(itSrc)-nFirstUnit; if (nCount <=0 ) return NOT_EXEC; /* Initialize */ CREATEVIRTUAL(CFst,itSrc,_this); /* If destination empty copy all properties from source */ if (UD_XXU(_this)==0) { CFst_Copy(BASEINST(_this),BASEINST(itSrc)); CData_SetNRecs(AS(CData,_this->ud),0); CData_SetNRecs(AS(CData,_this->sd),0); CData_SetNRecs(AS(CData,_this->td),0); CData_Reset(_this->is,0); CData_Reset(_this->os,0); } /* Get some metrics */ nXUd = UD_XXU(_this); nXXSd = UD_XXS(_this); nXXTd = UD_XXT(_this); nFSs = UD_FS(itSrc,nFirstUnit); nFTs = UD_FT(itSrc,nFirstUnit); for (nU=nFirstUnit,nXSs=0,nXTs=0; nU<nFirstUnit+nCount; nU++) { nXSs+=UD_XS(itSrc,nU); nXTs+=UD_XT(itSrc,nU); } /* Cat descriptor tables */ CDlpTable_CatEx(AS(CData,_this->ud)->m_lpTable,AS(CData,itSrc->ud)->m_lpTable,nFirstUnit,nCount); CDlpTable_CatEx(AS(CData,_this->sd)->m_lpTable,AS(CData,itSrc->sd)->m_lpTable,nFSs ,nXSs ); CDlpTable_CatEx(AS(CData,_this->td)->m_lpTable,AS(CData,itSrc->td)->m_lpTable,nFTs ,nXTs ); /* Adjust unit descriptions */ for (nU=nXUd; nU<nXUd+nCount; nU++) { UD_FS(_this,nU) += (nXXSd-nFSs); UD_FT(_this,nU) += (nXXTd-nFTs); } /* Copy input and output symbol table components */ if(!IS_XXS(_this) && IS_XXS(itSrc)) CData_Copy(_this->is,itSrc->is); if(!OS_XXS(_this) && OS_XXS(itSrc)) CData_Copy(_this->os,itSrc->os); /* Finalize */ DESTROYVIRTUAL(itSrc,_this); CFst_Check(_this); /* TODO: Remove after debugging */ return O_K; }
/** * Polymorphic set operations. * * @param lpsOpname * <p>Operator name</p> * <table> * <tr><th><code>lpsOpname</code></th><th>Boolean</th><th>Numeric</th><th>String</th><th>Instance</th></tr> * <tr><td><code>= </code></td><td>x</td><td>x</td><td>x</td><td>x</td></tr> * <tr><td><code>+= </code></td><td>x</td><td>x</td><td>x</td><td>-</td></tr> * <tr><td><code>-= </code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr> * <tr><td><code>*= </code></td><td>x</td><td>x</td><td>-</td><td>-</td></tr> * <tr><td><code>/= </code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr> * <tr><td><code>++=</code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr> * <tr><td><code>--=</code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr> * </table> * <p>For type conversion rules see * <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackLogic</code>, * <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackNumber</code>, * <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackString</code> and * <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackInstance</code>. * </p> * @return <code>O_K</code> if successfull, a (negative) error code otherwise */ INT16 CGEN_PROTECTED CVar_SetOp(CVar *_this,const char* lpsOpname) { StkItm si; if (dlp_strcmp(lpsOpname,"++=")!=0 && dlp_strcmp(lpsOpname,"--=")!=0) { if (!CDlpObject_MicGet(BASEINST(_this))->GetX) return IERROR(_this,VAR_NOTSUPPORTED,"Polymorphic signatures"," by caller",0); if (!MIC_GET_X(1,&si)) return NOT_EXEC; } if (dlp_strcmp(lpsOpname,"=")==0) switch (si.nType) { case T_BOOL : return CVar_Bset(_this,si.val.b); case T_COMPLEX : return CVar_Vset(_this,si.val.n); case T_STRING : return CVar_Sset(_this,si.val.s); case T_INSTANCE: return CVar_Iset(_this,si.val.i); default: DLPASSERT(FMSG("Unknown variable type")); return NOT_EXEC; } else if (dlp_strcmp(lpsOpname,"+=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_PLUS(_this->m_nNVal,si.val.n)); if (_this->m_nType==T_STRING) { char* lpsSi = NULL; MIC_PUT_X(&si); lpsSi = MIC_GET_S(1,0); _this->m_lpsSVal = (char*)dlp_realloc(_this->m_lpsSVal, dlp_strlen(_this->m_lpsSVal)+dlp_strlen(lpsSi)+1,sizeof(char)); if (!_this->m_lpsSVal) return IERROR(_this,ERR_NOMEM,0,0,0); dlp_strcat(_this->m_lpsSVal,lpsSi); return O_K; } if (_this->m_nType==T_BOOL) { MIC_PUT_X(&si); _this->m_bBVal|=MIC_GET_B(1,0); return O_K; } return IERROR(_this,VAR_NOTSUPPORTED,"Operator +="," for this variable type",0); } else if (dlp_strcmp(lpsOpname,"*=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MULT(_this->m_nNVal,si.val.n)); if (_this->m_nType==T_BOOL) { MIC_PUT_X(&si); _this->m_bBVal&=MIC_GET_B(1,0); return O_K; } return IERROR(_this,VAR_NOTSUPPORTED,"Operator *="," for this variable type",0); } else if (dlp_strcmp(lpsOpname,"-=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MINUS(_this->m_nNVal,si.val.n)); return IERROR(_this,VAR_NOTSUPPORTED,"Operator -="," for this variable type",0); } else if (dlp_strcmp(lpsOpname,"/=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MULT(_this->m_nNVal,CMPLX_INVT(si.val.n))); return IERROR(_this,VAR_NOTSUPPORTED,"Operator /="," for this variable type",0); } else if (dlp_strcmp(lpsOpname,"++=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_INC(_this->m_nNVal)); return IERROR(_this,VAR_NOTSUPPORTED,"Operator ++="," for this variable type",0); } else if (dlp_strcmp(lpsOpname,"--=")==0) { if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_DEC(_this->m_nNVal)); return IERROR(_this,VAR_NOTSUPPORTED,"Operator --="," for this variable type",0); } return NOT_EXEC; }
/* * Manual page at var.def */ INT16 CGEN_PUBLIC CVar_Status(CVar *_this) { char lpsBuf[255]; CVar_PopOwnValue(_this); printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); printf("\n Status of instance"); printf("\n var %s\n",BASEINST(_this)->m_lpInstanceName); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); switch (_this->m_nType) { case T_BOOL: printf("\n Type : boolean"); printf("\n Value: %d",(int)_this->m_bBVal); break; case T_DOUBLE: dlp_sprintc(lpsBuf,_this->m_nNVal,FALSE); printf("\n Type : double"); printf("\n Value: %s", lpsBuf); break; case T_COMPLEX: dlp_sprintc(lpsBuf,_this->m_nNVal,FALSE); printf("\n Type : complex"); printf("\n Value: %s", lpsBuf); break; case T_STRING: printf("\n Type : string"); printf("\n Value: \"%s\"",_this->m_lpsSVal?_this->m_lpsSVal:"(null)"); break; case T_INSTANCE: printf("\n Type : instance"); printf("\n Value: %s",CDlpObject_GetFQName(BASEINST(_this)->m_iAliasInst,lpsBuf,255)); break; case T_RDOUBLE: printf("\n Type : double random" ); printf("\n Low boundary : %8lg", (double)_this->m_nLow ); printf("\n High boundary : %8lg", (double)_this->m_nHi ); printf("\n Step size : %8lg", (double)_this->m_nDelta ); printf("\n Most recent value: %8lg", (double)_this->m_nNVal.x ); break; case T_RDDATA: printf("\n Type : numeric random data selector"); printf("\n Data table : %s",CDlpObject_GetFQName(_this->m_idRndSet,lpsBuf,255)); printf("\n Component index : %5ld",(long)_this->m_nInd ); printf("\n Component type : %5ld",(long)_this->m_nType); printf("\n Most recent value: %8lg",(double)_this->m_nNVal.x); break; case T_RSDATA: printf("\n Type : string random data selector"); printf("\n Data table : %s",CDlpObject_GetFQName(_this->m_idRndSet,lpsBuf,255)); printf("\n Component index : %5ld", (long)_this->m_nInd ); printf("\n Component type : %5ld", (long)_this->m_nType); printf("\n Most recent value: %s",_this->m_lpsSVal?_this->m_lpsSVal:"(null)"); default: DLPASSERT(FMSG("Unknown variable type")); } printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); printf("\n"); return O_K; }
/** * Copies selected word types. * * @param _this This instance * @param iSrc Source instance to copy * @param nWhat Word type to copy (for more than one use "|") */ INT16 CDlpObject_CopySelective(CDlpObject* _this, CDlpObject* iSrc, INT16 nWhat) { hscan_t hs; hnode_t* hn; SWord* lpWord = NULL; CDlpObject* iSrcInt; CDlpObject* iDstInt; CHECK_THIS_RV(NOT_EXEC); DEBUGMSG(-1,"CDlpObject_Copy for '%s'",_this->m_lpInstanceName,0,0); #ifdef __NORTTI if(strcmp(_this->m_lpClassName,"data")){ IERROR(_this,ERR_DANGEROUS,"CDlpObject_Copy","No fields can be copied in __NORTTI mode.",0); DLPASSERT(FALSE); } #endif if(_this == iSrc) return O_K; if(!iSrc) return NOT_EXEC; /* TODO: Check this! --> */ /*if(!CDlpObject_IsKindOf(iSrc,_this->m_lpClassName))*/ #ifdef __cplusplus if(!iSrc->IsKindOf(_this->m_lpClassName)) #else if(!BASEINST(iSrc)->IsKindOf(BASEINST(iSrc),_this->m_lpClassName)) #endif return IERROR(_this,ERR_NOTOFKIND,iSrc->m_lpInstanceName,_this->m_lpClassName,0); /* <-- */ /* Loop over own dictionary */ hash_scan_begin(&hs,_this->m_lpDictionary); while ((hn = hash_scan_next(&hs))!=NULL) { DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */ if (!lpWord) continue; switch (lpWord->nWordType & nWhat) { case WL_TYPE_FIELD: CDlpObject_CopyField(_this,lpWord,iSrc); break; case WL_TYPE_INSTANCE: iDstInt = (CDlpObject*)lpWord->lpData; iSrcInt = CDlpObject_FindInstanceWord(iSrc,lpWord->lpName,NULL); if (iSrcInt && iDstInt) #ifdef __cplusplus iDstInt->Copy(iSrcInt); #else BASEINST(iDstInt)->Copy(BASEINST(iDstInt),BASEINST(iSrcInt)); #endif break; case WL_TYPE_DONTCARE: /* Not supported */ case WL_TYPE_ERROR: /* Not supported */ case WL_TYPE_FACTORY: /* Not supported */ case WL_TYPE_METHOD: /* Not supported */ case WL_TYPE_OPERATOR: /* Not supported */ case WL_TYPE_OPTION: /* Not supported */ default: break; } } /* Loop over source's dictionary */ hash_scan_begin(&hs,iSrc->m_lpDictionary); while ((hn = hash_scan_next(&hs))!=NULL) { DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */ if (!lpWord) continue; switch (lpWord->nWordType & nWhat) { case WL_TYPE_INSTANCE: iSrcInt = (CDlpObject*)lpWord->lpData; iDstInt = CDlpObject_FindInstanceWord(_this,lpWord->lpName,NULL); if (iDstInt) continue; /* Has already been copied */ iDstInt = CDlpObject_Instantiate(_this,iSrcInt->m_lpClassName,iSrcInt->m_lpInstanceName,FALSE); if (iSrcInt && iDstInt) #ifdef __cplusplus iDstInt->Copy(iSrcInt); #else BASEINST(iDstInt)->Copy(BASEINST(iDstInt),BASEINST(iSrcInt)); #endif break; case WL_TYPE_DONTCARE: /* Don't know */ case WL_TYPE_ERROR: /* Don't know */ case WL_TYPE_FACTORY: /* Don't know */ case WL_TYPE_METHOD: /* Don't know */ case WL_TYPE_OPERATOR: /* Don't know */ case WL_TYPE_OPTION: /* Don't know */ default: break; } } _this->m_nCheck = iSrc->m_nCheck; return O_K; }
/* * Manual page at statistics.def */ INT16 CGEN_PUBLIC CStatistics_Pool ( CStatistics* _this, CStatistics* iSrc, CData* idMap ) { INT32 i = 0; /* Current component index */ INT32 nC = 0; /* Current pooled statistics class */ INT32 nCs = 0; /* Current source class index */ INT32 nXC = 0; /* Number of pooled classes */ INT32 nRpb = 0; /* Statistics raw data block size */ INT16 nCheckSave = 0; /* Saved check level */ CData* idAux = NULL; /* Auxilary data instance #1 */ CData* idPmp = NULL; /* Pooling map */ CData* idPcd = NULL; /* Pooled class raw data buffer */ /* Initialize */ /* --------------------------------- */ CHECK_THIS_RV(0); /* Check this instance */ IF_NOK(CStatistics_Check(iSrc)) /* Check source statistics */ return IERROR(_this,ERR_INVALARG,"iSrc",0,0); /* ... */ nCheckSave = _this->m_nCheck; /* Save check level */ CStatistics_Reset(BASEINST(_this),TRUE); /* Reset destination */ _this->m_nCheck = nCheckSave; /* Restore check level */ IFIELD_RESET(CData,"dat"); /* Create pool raw stats. data inst. */ /* Protocol */ /* --------------------------------- */ IFCHECK /* On verbose level 1 */ { /* >> */ printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); /* Print protocol header */ printf("\n statistics -pool"); /* ... */ printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());printf("\n");/* ... */ } /* << */ /* No map --> pool all classes */ /* --------------------------------- */ if (CData_IsEmpty(idMap)) /* NULL or empty map instance */ { /* >> */ IFCHECK printf("\n Empty pooling map --> pool all classes"); /* Protocol (verbose level 1) */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,0); /* Pool sum data */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,1); /* Pool min data */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,2); /* Pool max data */ STA_PROTOCOL_FOOTER(1,"done"); /* Print protocol footer */ return O_K; /* That's it */ } IFCHECK printf("\n Pooling by map"); /* Protocol (verbose level 1) */ ICREATEEX(CData,idAux,"CStatistics_Pool.~idAux",NULL); /* Create auxilary data instance #1 */ ICREATEEX(CData,idPmp,"CStatistics_Pool.~idPmp",NULL); /* Create pooling map */ ICREATEEX(CData,idPcd,"CStatistics_Pool.~idPcs",NULL); /* Create pooled raw stats.data inst.*/ /* Find and copy map component (pooled class) */ /* --------------------------------- */ for (i=0; i<CData_GetNComps(idMap); i++) /* Loop over components of idMap */ if (dlp_is_numeric_type_code(CData_GetCompType(idMap,i))) /* Is current component numeric? */ { /* >> (Yes) */ CData_SelectComps(idPmp,idMap,i,1); /* Copy component */ break; /* Have ready :) */ } /* << */ if (CData_IsEmpty(idPmp)) /* Have not got map component */ { /* >> */ IERROR(_this,STA_BADCOMP,"map",BASEINST(idMap)->m_lpInstanceName,"numeric");/* Error message */ DLPTHROW(STA_BADCOMP); /* Throw exception */ } /* << */ /* Create source class component */ /* --------------------------------- */ CData_AddComp(idPmp,"srcc",T_LONG); /* Add source class index component */ for (i=0; i<CData_GetNRecs(idPmp); i++) CData_Dstore(idPmp,i,i,1); /* Fill it */ /* Finish pooling map and initialize pooling */ /* --------------------------------- */ CData_Sortup(idPmp,idPmp,0); /* Sort map by pooled class index */ nXC = (INT32)CData_Dfetch(idPmp,CData_GetNRecs(idPmp)-1,0)+1; /* Get greatest pooled class index */ IFCHECK printf("\n Pooling %ld statistics classes",(long)nXC); /* Protocol (verbose level 1) */ IFCHECKEX(3) CData_Print(idPmp); /* Print pooling map (verbose lvl.3) */ nRpb = CData_GetNRecsPerBlock(iSrc->m_idDat); /* Get block size */ /* Prepare pooled statistics */ /* --------------------------------- */ CData_Scopy(_this->m_idDat,iSrc->m_idDat); /* Create target raw data components */ CData_Allocate(_this->m_idDat,nRpb*nXC); /* Allocate target raw data */ CData_SetNBlocks(_this->m_idDat,nXC); /* Set target statistics block number*/ /* Pooling loop */ /* --------------------------------- */ for (i=0; i<CData_GetNRecs(idPmp); ) /* Loop over pooling map */ { /* >> */ /* - Copy raw statistics data of one pooled class */ /* - - - - - - - - - - - - - - - - */ nC = (INT32)CData_Dfetch(idPmp,0,0); /* Get pooled class index */ IFCHECK printf("\n Pooled class %3ld"); /* Protocol (verbose level 1) */ for (i=0; i<CData_GetNRecs(idPmp); i++) /* Loop over partition of pool.map */ { /* >> */ if (nC != (INT32)CData_Dfetch(idPmp,0,0)) break; /* Not the current class anymore */ nCs = (INT32)CData_Dfetch(idPmp,i,1); /* Get source class index */ IFCHECK printf("\n - Source class %3ld",nCs); /* Protocol (verbose level 1) */ CData_SelectBlocks(idAux,iSrc->m_idDat,nCs,1); /* Copy raw stats. data block */ CData_Cat(idPcd,idAux); /* Append to buffer */ } /* << */ /* - Pool data */ /* - - - - - - - - - - - - - - - - */ CData_SetNBlocks(idPcd,CData_GetNRecs(idPcd)/nRpb); /* Set block count of aggr. buffer */ IFCHECK /* Protocol (verbose level 1) */ printf("\n - Aggregating %ld statistics classes", /* | */ (long)CData_GetNBlocks(idPcd)); /* | */ CStatistics_PoolInt(idAux,idPcd,0); /* Pool sum data */ CStatistics_PoolInt(idAux,idPcd,1); /* Pool min data */ CStatistics_PoolInt(idAux,idPcd,2); /* Pool max data */ /* - Store pooled raw statistics data block */ /* - - - - - - - - - - - - - - - - */ dlp_memmove /* Copy pooled raw stats. data */ ( /* | */ CData_XAddr(_this->m_idDat,nC*nRpb,0), /* | To target statistics block */ CData_XAddr(idAux,0,0), /* | From aggregation buffer */ CData_GetNRecs(idAux)*CData_GetRecLen(idAux) /* | Length of aggregation buffer */ ); /* | */ /* - Clean up auxilary instances */ /* - - - - - - - - - - - - - - - - */ CData_Reset(idPcd,TRUE); /* Clear aggregation buffer */ } /* Clean up */ /* --------------------------------- */ IDESTROY(idAux); /* Destroy auxilary data instance #1 */ IDESTROY(idPmp); /* Destroy pooling map */ IDESTROY(idPcd); /* Destroy pooled cls. raw data inst.*/ STA_PROTOCOL_FOOTER(1,"done"); /* Print protocol footer */ return O_K; /* Ok */ DLPCATCH(STA_BADCOMP) /* == Catch STA_BADCOMP exception */ IDESTROY(idAux); /* Destroy auxilary data instance #1 */ IDESTROY(idPmp); /* Destroy pooling map */ IDESTROY(idPcd); /* Destroy pooled cls. raw data inst.*/ STA_PROTOCOL_FOOTER(1,"FAILED"); /* Print protocol footer */ return NOT_EXEC; /* Not ok */ }