/* * Manual page at statistics.def */ INT16 CGEN_PUBLIC CStatistics_Setup ( CStatistics* _this, INT32 nOrder, INT32 nDim, INT32 nCls, CData* idLtb, INT32 nIcLtb ) { INT32 c = 0; /* Statistics class loop counter */ INT32 n = 0; /* Dimension loop couner */ FLOAT64* lpMin = NULL; /* Ptr. to class' k minimum vector */ FLOAT64* lpMax = NULL; /* Ptr. to class' k maximum vector */ /* Validate */ /* --------------------------------- */ CHECK_THIS_RV(NOT_EXEC); /* Check this pointer */ if (nOrder<2) nOrder = 2; /* Default order is 2 */ if (nDim <1) nDim = 1; /* Default dimensionality is 1 */ if (nCls <1) nCls = 1; /* Default number of classes is 1 */ /* Initialize statistics */ /* --------------------------------- */ CStatistics_Reset(_this,TRUE); /* Start over */ IFIELD_RESET(CData,"dat"); /* Create/reset statistic data */ CData_Array(_this->m_idDat,T_DOUBLE,nDim,nCls*(nOrder+nDim+2)); /* Allocate statistic data */ CData_SetNBlocks(_this->m_idDat,nCls); /* Set number of blocks */ if (CData_IsEmpty(_this->m_idDat)) return IERROR(_this,ERR_NOMEM,0,0,0); /* Check if it worked out... */ for (c=0; c<nCls; c++) /* Loop over classes */ { /* >> */ lpMin = CStatistics_GetPtr(_this,c,STA_DAI_MIN); /* Get ptr. to class' k min. vec. */ lpMax = CStatistics_GetPtr(_this,c,STA_DAI_MAX); /* Get ptr. to class' k max. vec. */ for (n=0; n<nDim; n++) /* Loop over dimensions */ { /* >> */ lpMin[n] = T_DOUBLE_MAX; /* Initialize minimum vector */ lpMax[n] = T_DOUBLE_MIN; /* Initialize maximum vector */ } /* << */ } /* << */ /* Initialize label table */ /* --------------------------------- */ if (CData_IsEmpty(idLtb)) return O_K; /* No label table -> that's it */ if (CData_GetNRecs(idLtb)!=nCls) /* Bad number of labels */ return IERROR(_this,STA_NOTSETUP," (wrong no. of labels in idLtb)",0,0); /* -> Error */ if (nIcLtb<0) /* Label component not specified */ for (nIcLtb=0; nIcLtb<CData_GetNComps(idLtb); nIcLtb++) /* Seek first symbolic component */ if (dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb))) /* ... */ break; /* ... */ if (!dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb))) /* Label component not symbolic */ return IERROR(_this,STA_NOTSETUP," (label comp. not found in idLtb)",0,0); /* -> Error */ IFIELD_RESET(CData,"ltb"); /* Create/reset label table */ CData_SelectComps(_this->m_idLtb,idLtb,nIcLtb,1); /* Copy label table */ return O_K; /* Done */ }
/** * 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; }
/** * Expand/reduce number of pitch markers to fit new target sum of period length. * * @param idSrc source object * @param idDst target object * @param n target length * @return O_K if sucessfull, not exec otherwise */ INT16 CGEN_PUBLIC CPMproc::ExpandPm(CData *idSrc, CData* idDst, INT32 n) { if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC; if(n <= 0) return NOT_EXEC; CREATEVIRTUAL(CData,idSrc,idDst); DLPASSERT(CData_GetNComps(idSrc) == 2); CData_Reset(idDst, TRUE); CData_Scopy(idDst,idSrc); INT32 nRecsNew = 0; INT32 nRecs = (INT32)CData_GetNRecs(idSrc); INT16* pm_new = NULL; if(dlm_pm_expand((INT16*)CData_XAddr(idSrc,0,0), nRecs, &pm_new, &nRecsNew, n) != O_K) { return IERROR(this,ERR_NULLARG, "", NULL, NULL); } CData_Allocate(idDst,nRecsNew); dlp_memmove(CData_XAddr(idDst,0,0), pm_new, nRecsNew*2*sizeof(INT16)); dlp_free(pm_new); CData_CopyDescr(idDst,idSrc); /* clean up */ DESTROYVIRTUAL(idSrc,idDst) return(O_K); }
/** * Convert f0-contour with equal spaced sampling points to pitch markers. * * @param idSrc source f0-contour * @param idDst target pitch marker * @param n target sum of pitch marker lengths * @param srate sampling rate * @return O_K if sucessfull, not exec otherwise */ INT16 CGEN_PUBLIC CPMproc::F02pm(CData *idSrc, CData* idDst, INT32 n, INT32 srate) { INT16* p_pm = NULL; INT32 n_pm = 0; if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC; if(n <= 0) return NOT_EXEC; DLPASSERT(CData_GetNComps(idSrc) == 1); CREATEVIRTUAL(CData,idSrc,idDst); CData_Reset(idDst, TRUE); dlm_f02pm((FLOAT64*)idSrc->XAddr(0,0), idSrc->GetNRecs(), &p_pm, &n_pm, n, srate); CData_AddComp(idDst, "pm", T_SHORT); CData_AddComp(idDst, "v/uv", T_SHORT); CData_Allocate(idDst, n_pm); ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate); dlp_memmove(idDst->XAddr(0,0), p_pm, 2*n_pm*sizeof(INT16)); /* clean up */ DESTROYVIRTUAL(idSrc,idDst) dlp_free(p_pm); return(O_K); }
/** * Expand/reduce number of pitch markers to new number. * * @param idSrc source object * @param idDst target object * @param n target number of pitch markers * @return O_K if sucessfull, not exec otherwise */ INT16 CGEN_PUBLIC CPMproc::CompressPm(CData *idSrc, CData* idDst, INT32 n) { if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC; if(n <= 0) return NOT_EXEC; CREATEVIRTUAL(CData,idSrc,idDst); DLPASSERT(CData_GetNComps(idSrc) == 2); CData_Reset(idDst, TRUE); CData_Scopy(idDst,idSrc); CData_Allocate(idDst, n); if(dlm_pm_compress((INT16*)CData_XAddr(idSrc,0,0), CData_GetNRecs(idSrc), (INT16*)CData_XAddr(idDst,0,0), CData_GetNRecs(idDst)) != O_K) { return IERROR(this,ERR_NULLARG, "", NULL, NULL); } CData_CopyDescr(idDst,idSrc); /* clean up */ DESTROYVIRTUAL(idSrc,idDst) return(O_K); }
/** * Add periods to reach desired sum od periods. * * @param idSrc source object * @param idDst target object * @param n target number of pitch markers * @param method fill method * @return O_K if sucessfull, not exec otherwise */ INT16 CGEN_PUBLIC CPMproc::Fill(CData *idSrc, CData* idDst, INT32 n, const char* method) { INT32 i = 0; INT32 n_new = 0; INT32 sum = 0; INT16 mean_s = 0; FLOAT64 mean = 0.0; const char* method_default = "mean"; if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC; if(n <= 0) return NOT_EXEC; if(method == NULL) method = method_default; CREATEVIRTUAL(CData,idSrc,idDst); DLPASSERT(CData_GetNComps(idSrc) == 2); CData_Reset(idDst, TRUE); CData_Copy(idDst,idSrc); for(i = 0; i < idSrc->GetNRecs(); i++) { sum += (INT32)idSrc->Dfetch(i,0); } if(!strcmp(method, "mean")) { mean = (FLOAT64)sum / (FLOAT64)idSrc->GetNRecs(); n_new = (INT32)((FLOAT64)(n-sum) / mean); if(n_new >= 0) { n_new = MAX(n_new,1); i = idDst->GetNRecs(); idDst->AddRecs(n_new, 1); while((sum<n) && (i < idDst->GetNRecs())) { mean_s = (INT16)((FLOAT64)(n-sum) / (FLOAT64)(idDst->GetNRecs()-i)); idDst->Dstore(mean_s,i,0); idDst->Dstore(0,i,1); i++; sum += mean_s; } } } while((n-sum) > idDst->Dfetch(idDst->GetNRecs()-1,0)) { sum -= (INT32)idDst->Dfetch(idDst->GetNRecs()-1,0); idDst->Delete(idDst,idDst->GetNRecs()-1,1); } idDst->Dstore(idDst->Dfetch(idDst->GetNRecs()-1,0)-(sum-n),idDst->GetNRecs()-1,0); CData_CopyDescr(idDst,idSrc); /* clean up */ DESTROYVIRTUAL(idSrc,idDst) return(O_K); }
/* * 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)
/** * Convert (unequal spaced) pitch markers to f0-contour with equal spaced * sampling points. * * @param idSrc source pitch marks * @param idDst target fo-contour * @param n target number of sampling points of f0-contour * @param srate sampling rate * @return O_K if sucessfull, not exec otherwise */ INT16 CGEN_PUBLIC CPMproc::Pm2f0(CData *idSrc, CData* idDst, INT32 n, INT32 srate) { if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC; if(n <= 0) return NOT_EXEC; DLPASSERT(CData_GetNComps(idSrc) == 2); CREATEVIRTUAL(CData,idSrc,idDst); CData_Reset(idDst, TRUE); CData_AddComp(idDst, "~F0", T_DOUBLE); CData_Allocate(idDst, n); dlm_pm2f0((INT16*)idSrc->XAddr(0,0), idSrc->GetNRecs(), (FLOAT64*)idDst->XAddr(0,0), idDst->GetNRecs(), srate); ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate); /* clean up */ DESTROYVIRTUAL(idSrc,idDst) return(O_K); }
/** * Returns the number of statistics classes (labels) C. The number of classes is * defined by the number of blocks in the statistics data table * {@link dat m_idDat}. * * @param _this * Pointer to CStatistics instance * @return The number of classes or 0 in case of errors */ INT32 CGEN_PUBLIC CStatistics_GetNClasses(CStatistics* _this) { CHECK_THIS_RV(0); if (CData_IsEmpty(_this->m_idDat)) return 0; return CData_GetNBlocks(_this->m_idDat); }
/* * 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 */ }
void CGEN_PUBLIC CVmap_MapVectorF #else void CGEN_PUBLIC CVmap_MapVectorD #endif ( CVmap* _this, VMAP_FTYPE* lpX, VMAP_FTYPE* lpY, INT32 nXdim, INT32 nYdim ) { BOOL f = 1; /* First non-zero summand flag */ INT32 n = 0; /* Input dimension loop counter */ INT32 m = 0; /* Output dimension loop counter */ INT32 N = 0; /* Input dimensionality of mapping */ INT32 M = 0; /* Output dimensionality of mapping */ VMAP_FTYPE* W = NULL; /* Pointer to transformation matrix */ VMAP_FTYPE* Wm = NULL; /* Pointer to column m of trafo.mtx. */ /* Initialize */ /* --------------------------------- */ CHECK_THIS(); /* Check this pointer */ if (!lpY) return; /* No output buffer, no service */ DLPASSERT(lpX!=lpY); /* Check in-/output ptrs. not equal */ for (m=0; m<nYdim; m++) lpY[m]=_this->m_nZero; /* Initialize output vector */ if (!lpX) return; /* If no input vector -> all done */ N = CData_GetNComps(AS(CData,_this->m_idTmx)); /* Get mapping input dimensionality */ M = CData_GetNRecs(AS(CData,_this->m_idTmx)); /* Get mapping output dimensionality */ if (nXdim>N) nXdim = N; /* Clip input dim. to mapping dim. */ if (nYdim>M) nYdim = M; /* Clip output dim. to mapping dim. */ if(CData_IsEmpty(AS(CData,_this->m_idWeakTmx))) /* Do not use weak tmx */ { /* >> */ W = (VMAP_FTYPE*)CData_XAddr(AS(CData,_this->m_idTmx),0,0); /* Get pointer to trafo. matrix */ if (!W) return; /* No trafo. mat., also no service */ /* Compute generalized scalar product for each y[m] */ /* ------------------------------- */ for (m=0; m<nYdim; m++) /* Loop over output dimensions */ for (n=0,f=1,Wm=&W[m*N]; n<nXdim; n++) /* Loop over input dimensions */ if (Wm[n]!=_this->m_nZero) /* Weight of comp. n non-zero */ { /* >> */ if (f) /* First summand */ { /* >> */ lpY[m] = DLP_SCALOP(Wm[n],lpX[n],_this->m_nWop); /* Skip aggregation op */ f = 0; /* This WAS the first one..*/ } /* << */ else /* Second and further summd's*/ lpY[m] = DLP_SCALOP(lpY[m],DLP_SCALOP(Wm[n],lpX[n],_this->m_nWop), /* Weight & aggregate */ _this->m_nAop); /* | */ } /* << */ }else{ /* << Use weak tmx >> */ BYTE* Id = NULL; /* Pointer to index vector */ INT32 nRecLen = CData_GetRecLen(AS(CData,_this->m_idWeakTmx)); /* Get size of one record */ INT16 nIType = CData_GetCompType(AS(CData,_this->m_idWeakTmx),0); nXdim = CData_GetNRecs(AS(CData,_this->m_idWeakTmx)); /* Get max. numb. of out's per in */ for (m=0;m<nYdim;m++) /* Loop over output dimensions */ { /* >> */ Id=CData_XAddr(AS(CData,_this->m_idWeakTmx),0,m*2); /* Get start adress of component */ switch(nIType){ case T_LONG: for (n=0;n<nXdim && *((INT64*)Id)>=0;n++,Id+=nRecLen) /* Loop over in's for this out */ if(!n) lpY[m]=DLP_SCALOP(*((VMAP_FTYPE *)(Id+sizeof(INT64))), /* First input => */ lpX[*((INT64*)Id)],_this->m_nWop); /* | Calc out from in */ else lpY[m]=DLP_SCALOP(lpY[m], /* Else => Calc out from */ DLP_SCALOP(*((VMAP_FTYPE *)(Id+sizeof(INT64))), /* | */ lpX[*((INT64*)Id)],_this->m_nWop),_this->m_nAop); /* | prev. out and in */ break; case T_INT: for (n=0;n<nXdim && *((INT32*)Id)>=0;n++,Id+=nRecLen) /* Loop over in's for this out */ if(!n) lpY[m]=DLP_SCALOP(*((VMAP_FTYPE *)(Id+sizeof(INT32))), /* First input => */ lpX[*((INT32*)Id)],_this->m_nWop); /* | Calc out from in */ else lpY[m]=DLP_SCALOP(lpY[m], /* Else => Calc out from */ DLP_SCALOP(*((VMAP_FTYPE *)(Id+sizeof(INT32))), /* | */ lpX[*((INT32*)Id)],_this->m_nWop),_this->m_nAop); /* | prev. out and in */ break; default: IERROR(_this,ERR_INVALARG,"weaktmx int type is wheter int nor long",0,0); } } /* << */ } /* << */ }
/* * Manual page at statistics.def */ INT16 CGEN_PUBLIC CStatistics_Update ( CStatistics* _this, CData* idVec, INT32 nIcLab, CData* idW ) { INT32 i = 0; /* Update vector loop counter */ INT32 I = 0; /* Number of update vectors */ INT32 c = 0; /* Class of current update vector */ INT32 C = 0; /* Number of classes */ INT32 n = 0; /* Dimension loop counter */ INT32 N = 0; /* Statistics' dimensionality */ FLOAT64 w = 0.; /* Weight of current update vector */ char* lpsLab = NULL; /* Symbolic label of curr. upd. vec. */ FLOAT64* lpX = NULL; /* Vector copy buffer */ INT32 nVecIgnored = 0; /* Number of ignored vectors */ /* Validate */ /* --------------------------------- */ CHECK_THIS_RV(NOT_EXEC); /* Check this pointer */ IF_NOK(CStatistics_Check(_this)) /* Check instance data */ return IERROR(_this,STA_NOTSETUP," ( use -status for details)",0,0); /* ... */ if (CData_IsEmpty(idVec)) return O_K; /* No input vector(s), no service! */ I = CData_GetNRecs(idVec); /* Get number of update vectors */ C = CStatistics_GetNClasses(_this); /* Get number of statitistics classes*/ N = CStatistics_GetDim(_this); /* Get statistics vector dimension */ if (C>1) /* Multiclass statistics needs labels*/ { /* >> */ if (_this->m_idLtb) /* Need symbolic labels */ { /* >> */ if ((nIcLab<0 || nIcLab>=CData_GetNComps(idVec))) /* Symbolic label comp. not spec.*/ for (nIcLab=0; nIcLab<CData_GetNComps(idVec); nIcLab++) /* Seek label component */ if (dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab))) /* ... */ break; /* ... */ if (!dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab))) /* Symbolic label comp. not found*/ return /* -> Error */ IERROR(_this,STA_BADCOMP,"Label",idVec->m_lpInstanceName,"symbolic"); /* | */ } /* << */ else /* Need numeric labels */ { /* >> */ if (!dlp_is_numeric_type_code(CData_GetCompType(idVec,nIcLab)) && /* Numeric label comp. not found */ (nIcLab>=0 || CData_GetNComps(idW)!=C)) /* | */ return /* -> Error */ IERROR(_this,STA_BADCOMP,"Label",idVec->m_lpInstanceName,"numeric"); /* | */ } /* << */ } /* << */ /*else if (nIcLab>=0) IERROR(_this,STA_IGNORE,"label component",0,0); / * Only one class -> ignore labels */ if (dlp_is_numeric_type_code(CData_GetCompType(idVec,nIcLab))) /* Check no. of comps. in idVec ... */ { /* >> */ if (CData_GetNNumericComps(idVec)!=N+1) /* Wrong number of numeric comps. */ IERROR(_this,STA_DIM,idVec->m_lpInstanceName,"numeric components",N+1); /* -> Warning */ } /* << */ else if (CData_GetNNumericComps(idVec)!=N) /* Wrong number of numeric comps. */ IERROR(_this,STA_DIM,idVec->m_lpInstanceName,"numeric components",N); /* -> Warning */ if (idW) /* Weigths passed -> check 'em */ { /* >> */ if (!dlp_is_numeric_type_code(CData_GetCompType(idW,0))) /* Component 0 not numeric */ return /* -> Error */ IERROR(_this,STA_BADCOMP,"Weight",idW->m_lpInstanceName,"numeric"); /* | */ if (CData_GetNComps(idW)!=1 && CData_GetNComps(idW)!=C) /* More than one component */ IERROR(_this,STA_IGNORE,"components in weight sequence",0,0); /* -> Warning */ if (CData_GetNRecs(idW)!=I) /* Not exactly one weight per vec. */ IERROR(_this,STA_DIM,idW->m_lpInstanceName,"records",I); /* -> Warning */ } /* << */ /* Initialize - NO RETURNS BEYOND THIS POINT! - */ /* --------------------------------- */ lpX = (FLOAT64*)dlp_calloc(N,sizeof(FLOAT64)); /* Allocate vector copy buffer */ /* Update statistics */ /* --------------------------------- */ for (i=0; i<I; i++) /* Loop over update vectors */ { /* >> */ /* Get vector label */ /* - - - - - - - - - - - - - - - - */ if (C>1) /* Multiclass stats. needs labels */ { /* >> */ if (_this->m_idLtb) /* idVec contains symbolic labs. */ { /* >> */ INT32 nLIdx = 0; DLPASSERT(dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab))); /* Must be checked before! */ lpsLab = (char*)CData_XAddr(idVec,i,nIcLab); /* Get string ptr. to label */ if(_this->m_bLabel){ nLIdx=strlen(lpsLab)-1; if(nLIdx && lpsLab[nLIdx]==']') nLIdx--; else nLIdx=0; if(nLIdx && lpsLab[nLIdx]>='0' && lpsLab[nLIdx]<='9') nLIdx--; else nLIdx=0; while(nLIdx && lpsLab[nLIdx]>='0' && lpsLab[nLIdx]<='9') nLIdx--; if(nLIdx && lpsLab[nLIdx]=='[') lpsLab[nLIdx]='\0'; else nLIdx=0; } c = CData_Find(_this->m_idLtb,0,C,1,0,lpsLab); /* Look up label -> class idx. */ if(nLIdx) lpsLab[nLIdx]='['; if (c<0) /* Label invalid */ { /* >> */ IERROR(_this,STA_SLAB,i,lpsLab?lpsLab:"(null)",0); /* Warning */ continue; /* Ignore record */ } /* << */ } /* << */ else if(nIcLab>=0) /* idVec contains numeric labs. */ { /* >> */ c = (INT32)CData_Dfetch(idVec,i,nIcLab); /* Fetch label */ if (c<0 || c>=C) /* Label invalid */ { /* >> */ IERROR(_this,STA_NLAB,i,c,0); /* Warning */ continue; /* Ignore record */ } /* << */ } /* << */ else c = 0; /* Default class is 0 */ } /* << */ else c = 0; /* Default class is 0 */ do /* Loop over classes */ { /* >> */ /* Get (weighted) update vector and update statistics */ /* - - - - - - - - - - - - - - - - */ if (idW) /* Using weights */ { /* >> */ w = CData_Dfetch(idW,i,_this->m_idLtb || nIcLab>=0 ? 0 : c); /* Fetch weight for this vector */ if(w==0.) continue; /* Nothing to do if no weight */ _this->m_bWeighted=TRUE; } else w=1.; /* << */ CData_DrecFetch(idVec,lpX,i,N,nIcLab); /* Fetch update vector */ fpclassify(0.); for (n=0; n<N; n++) /* Loop over vector components */ if (fabs(lpX[n])>1E100) /* Check value */ break; /* There's something wrong ... */ if (n<N) { nVecIgnored++; continue; } /* Ignore this vector */ CStatistics_UpdateVector(_this,lpX,c,w); /* Update statistics with vector */ } /* << */ while(!_this->m_idLtb && nIcLab<0 && ++c<C); /* Next class if there is one */ } /* << */ /* Clean up */ /* --------------------------------- */ if (nVecIgnored>0) IERROR(_this,STA_VECIGNORED,nVecIgnored,0,0); /* Error: some vectors ignored */ dlp_free(lpX); /* Free vector copy buffer */ return O_K; /* Done */ }