Esempio n. 1
0
/*
 * 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;
}
Esempio n. 2
0
/*
 * 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                              */
}
Esempio n. 3
0
/*
 * 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;
}
Esempio n. 4
0
/*
 * 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                            */
}