Exemple #1
0
static int test_cycle
(  const mclx* mx
,  dim n_limit
)
   {  mclv* starts = run_through(mx), *starts2
   ;  if (starts->n_ivps)
      {  dim i
      ;  if (n_limit)
         {  mclx* mxt = mclxTranspose(mx)
         ;  starts2 = run_through(mxt)
         ;  mclxFree(&mxt)
         ;  mclvBinary(starts, starts2, starts, fltMultiply)

         ;  mcxErr
            (me, "cycles detected (%u nodes)", (unsigned) starts->n_ivps)

         ;  if (starts->n_ivps)
            {  fprintf(stdout, "%lu", (ulong) starts->ivps[0].idx)
            ;  for (i=1; i<MCX_MIN(starts->n_ivps, n_limit); i++)
               fprintf(stdout, " %lu", (ulong) starts->ivps[i].idx)
            ;  fputc('\n', stdout)
         ;  }
            else
            mcxErr(me, "strange, no nodes selected")
      ;  }
         else
         mcxErr(me, "cycles detected")
      ;  return 1
   ;  }

      mcxTell(me, "no cycles detected")
   ;  return 0
;  }
Exemple #2
0
double mclvNormalize
(  mclVector*  vec
)  
   {  dim      vecsize  = vec->n_ivps
   ;  mclIvp*  vecivps  = vec->ivps
   ;  double   sum      = mclvSum(vec)

   ;  vec->val =  sum

   ;  if (vec->n_ivps && sum == 0.0)
      {  mcxErr
         (  "mclvNormalize"
         ,  "warning: zero sum <%f> for vector <%ld>"
         ,  (double) sum
         ,  (long) vec->vid
         )
      ;  return 0.0
   ;  }
      else if (sum < 0.0)
      mcxErr("mclvNormalize", "warning: negative sum <%f>", (double) sum)

   ;  while (vecsize-- > 0)      /* careful with unsignedness */
      (vecivps++)->val /= sum
   ;  return sum
;  }
Exemple #3
0
mcxstatus mcxIOexpectNum
(  mcxIO*        xf
,  long*         lngp
,  mcxOnFail     ON_FAIL
)
   {  int   n_read   =  0
   ;  int   n_conv   =  0
   ;  mcxstatus status = STATUS_OK

   ;  if (inbuffer(xf))
      buffer_spout(xf, "mcxIOexpectNum")

   ;  mcxIOskipSpace(xf)      /* keeps accounting correct */

   ;  errno = 0
   ;  n_conv   =  fscanf(xf->fp, "%ld%n", lngp, &n_read)

   ;  xf->bc += n_read  /* fixme do fscanf error handling */
   ;  xf->lo += n_read

   ;  if (1 != n_conv)
         mcxErr("mcxIOexpectNum", "parse error: expected to find integer")
      ,  status = STATUS_FAIL
   ;  else if (errno == ERANGE)
         mcxErr("mcxIOexpectNum", "range error: not in allowable range")
      ,  status = STATUS_FAIL

   ;  if (status)
      {  mcxIOpos(xf, stderr)
      ;  if (ON_FAIL == EXIT_ON_FAIL)
         mcxExit(1)
   ;  }

      return status
;  }
Exemple #4
0
static void stream_state_set_map
(  mcxbool symmetric
,  stream_state *iface
,  mclxIOstreamer* streamer
,  mcxbits* bitsp
)
   {  mcxbits newbits = 0

   ;  if (symmetric)       /* work from input tab */
      {  iface->map_c->tab = streamer->tab_sym_in
      ;  if (iface->map_c->tab != NULL)
         {  iface->map_c->map = mclTabHash(iface->map_c->tab)
         ;  if (!(bitsp[0] & (MCLXIO_STREAM_CTAB | MCLXIO_STREAM_RTAB)))
            {  mcxErr(module, "PBD suggest explicit tab mode (now extending)")
            ;  newbits |= (MCLXIO_STREAM_CTAB_EXTEND | MCLXIO_STREAM_RTAB_EXTEND)
         ;  }
            iface->map_c->max_seen = MCLV_MAXID(iface->map_c->tab->domain)
      ;  }
         else
         {  iface->map_c->map = mcxHashNew(1024, mcxTingDPhash, mcxTingCmp)
      ;  }
         iface->map_r = iface->map_c
   ;  }
      else
      {  iface->map_c->tab = streamer->tab_col_in
      ;  if (streamer->tab_col_in != NULL)
         {  iface->map_c->map = mclTabHash(iface->map_c->tab)
         ;  if (!(bitsp[0] & MCLXIO_STREAM_CTAB))
            {  mcxErr(module, "PBD suggest explicit ctab mode (now extending)")
            ;  newbits |= MCLXIO_STREAM_CTAB_EXTEND
         ;  }
            iface->map_c->max_seen = MCLV_MAXID(iface->map_c->tab->domain)
      ;  }
         else if (!(bitsp[0] & (MCLXIO_STREAM_ETC_AI | MCLXIO_STREAM_235_AI)))
         iface->map_c->map = mcxHashNew(1024, mcxTingDPhash, mcxTingCmp)

      ;  iface->map_r->tab = streamer->tab_row_in
      ;  if (streamer->tab_row_in != NULL)
         {  iface->map_r->map = mclTabHash(iface->map_r->tab)
         ;  if (!(bitsp[0] & MCLXIO_STREAM_RTAB))
            {  mcxErr(module, "PBD suggest explicit rtab mode (now extending)")
            ;  newbits |= MCLXIO_STREAM_RTAB_EXTEND
         ;  }
            iface->map_r->max_seen = MCLV_MAXID(iface->map_r->tab->domain)
      ;  }
         else
         iface->map_r->map = mcxHashNew(1024, mcxTingDPhash, mcxTingCmp)
   ;  }

         /* alloc number below is some positive number if a restrict or extend tab was given
          * Otherwise it is 0.
         */
      pars_realloc(iface, (iface->map_c->max_seen + 1))
   ;  bitsp[0] |= newbits
;  }
Exemple #5
0
void mclgTFgraph
(  mclx* mx
,  pnum  mode
,  pval  val
)
   {  switch(mode)
      {        case MCLG_TF_MAX:       mclxMergeTranspose(mx, fltMax, 1.0)
   ;  break ;  case MCLG_TF_MIN:       mclxMergeTranspose(mx, fltMin, 1.0)
   ;  break ;  case MCLG_TF_ADD:       mclxMergeTranspose(mx, fltAdd, 1.0)
   ;  break ;  case MCLG_TF_SELFRM:    mclxAdjustLoops(mx, mclxLoopCBremove, NULL)
   ;  break ;  case MCLG_TF_SELFMAX:   mclxAdjustLoops(mx, mclxLoopCBmax, NULL)
   ;  break ;  case MCLG_TF_NORMSELF:  mclxNormSelf(mx)
   ;  break ;  case MCLG_TF_MUL:       mclxMergeTranspose(mx, fltMultiply, 1.0)
   ;  break ;  case MCLG_TF_ARCMAX:    mclxMergeTranspose(mx, fltArcMax, 1.0)

   ;  break ;  case MCLG_TF_ARCMAXGQ:  mclxMergeTranspose3(mx, fltArcMaxGQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMAXGT:  mclxMergeTranspose3(mx, fltArcMaxGT, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMAXLQ:  mclxMergeTranspose3(mx, fltArcMaxLQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMAXLT:  mclxMergeTranspose3(mx, fltArcMaxLT, 1.0, val)

   ;  break ;  case MCLG_TF_ARCMINGQ:  mclxMergeTranspose3(mx, fltArcMinGQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMINGT:  mclxMergeTranspose3(mx, fltArcMinGT, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMINLQ:  mclxMergeTranspose3(mx, fltArcMinLQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCMINLT:  mclxMergeTranspose3(mx, fltArcMinLT, 1.0, val)

   ;  break ;  case MCLG_TF_ARCDIFFGQ: mclxMergeTranspose3(mx, fltArcDiffGQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCDIFFGT: mclxMergeTranspose3(mx, fltArcDiffGT, 1.0, val)
   ;  break ;  case MCLG_TF_ARCDIFFLQ: mclxMergeTranspose3(mx, fltArcDiffLQ, 1.0, val)
   ;  break ;  case MCLG_TF_ARCDIFFLT: mclxMergeTranspose3(mx, fltArcDiffLT, 1.0, val)

   ;  break ;  case MCLG_TF_ARCSUB:    mclxMergeTranspose(mx, fltSubtract, 1.0)
   ;  break ;  case MCLG_TF_TUG:       mclxPerturb(mx, val, MCLX_PERTURB_SYMMETRIC)
   ;  break ;  case MCLG_TF_TRANSPOSE: { mclx* tp = mclxTranspose(mx); mclxTransplant(mx, &tp); }
   ;  break ;  case MCLG_TF_SHRUG:     mclxPerturb(mx, val, MCLX_PERTURB_SYMMETRIC | MCLX_PERTURB_RAND)
   ;  break ;  case MCLG_TF_ILS:       mclxILS(mx)
   ;  break ;  case MCLG_TF_TOPN:      mclxKNNdispatch(mx, val+0.5, mclx_n_thread_g, 0)
   ;  break ;  case MCLG_TF_KNN:       mclxKNNdispatch(mx, val+0.5, mclx_n_thread_g, 1)
   ;  break ;  case MCLG_TF_MCL:       tf_do_mcl(mx, val, FALSE)
   ;  break ;  case MCLG_TF_ARC_MCL:   tf_do_mcl(mx, val, TRUE)
   ;  break ;  case MCLG_TF_THREAD:    mclx_n_thread_g = val + 0.5
   ;  break ;  case MCLG_TF_CEILNB:    { mclv* cv = mclgCeilNB(mx, val+0.5, NULL, NULL, NULL); mclvFree(&cv); }
   ;  break ;  case MCLG_TF_STEP:      mclg_tf_step(mx, val+0.5)
   ;  break ;  case MCLG_TF_QT:        mclxQuantiles(mx, val)
   ;  break ;  case MCLG_TF_SSQ:       tf_ssq(mx, val)
   ;  break ;  case MCLG_TF_SHUFFLE:   mcxErr("mclgTFgraph", "shuffle not yet done (lift from mcxrand)")
   ;  break ;  default:                mcxErr("mclgTFgraph", "unknown mode")
   ;  break
   ;  }
   }
Exemple #6
0
double mclpUnary
(  mclp*    ivp
,  mclpAR*  ar       /* idx: MCLX_UNARY_mode, val: arg */
)
   {  dim i
   ;  double val = ivp->val
   ;  for (i=0;i<ar->n_ivps;i++)
      {  int mode = ar->ivps[i].idx
      ;  double arg = ar->ivps[i].val
      ;  if (mode == MCLX_UNARY_UNUSED)   /* sentinel used by callers to implement #knn(5) etc */
         continue
      ;  else if (mode < 0 || mode > MCLX_UNARY_UNUSED)
         {  mcxErr("mclpUnary", "not a mode: %d", mode)
         ;  break
      ;  }
         val = mclp_unary_tab[mode](val, &arg)
      ;  if (!val)
         switch(mode)            /* edges have disappeared, do not process further */
         {  case MCLX_UNARY_LT
         :  case MCLX_UNARY_LQ
         :  case MCLX_UNARY_GQ
         :  case MCLX_UNARY_GT
         :  return val
      ;  }
      }
      return val
;  }
Exemple #7
0
void mclvMean
(  const mclv*    vec
,  dim      N           /* vec does/might not store zeroes */
,  double   *meanp
,  double   *stdp
)
   {  dim d
   ;  double sum, mean, std = 0.0

   ;  *meanp = 0.0
   ;  *stdp  = 0.0

   ;  if (!N && !(N = vec->n_ivps))
      return
   ;  else if (N < vec->n_ivps)
      mcxErr("mclvMean PBD", "N < vec->n_ivps (vid %ld)", (long) vec->vid)

   ;  sum  = mclvSum(vec)
   ;  mean = sum/N

   ;  for (d=0;d<vec->n_ivps;d++)
      {  double dif = vec->ivps[d].val - mean
      ;  std += dif * dif
   ;  }

      if (N > vec->n_ivps)
      std += (N-vec->n_ivps) * mean * mean

   ;  *stdp = sqrt(std/N)
   ;  *meanp = mean
;  }
Exemple #8
0
mclVector*  mcxAttractivityScale
(  const mclMatrix*           M
)
{   dim n_cols = N_COLS(M)
                 ;
    dim d

    ;
    mclVector* vec_values = mclvResize(NULL, n_cols)

                            ;
    for (d=0; d<n_cols; d++)
    {   mclVector*  vec   =  M->cols+d
                             ;
        double   selfval  =  mclvIdxVal(vec, d, NULL)
                             ;
        double   maxval   =  mclvMaxValue(vec)
                             ;
        if (maxval <= 0.0)
        {   mcxErr
            (  "mcxAttractivityScale"
               ,  "encountered nonpositive maximum value"
            )
            ;
            maxval = 1.0
                     ;
        }
        (vec_values->ivps+d)->idx = d
                                    ;
        (vec_values->ivps+d)->val = selfval / maxval
                                    ;
    }
    return vec_values
           ;
}
Exemple #9
0
mclVector* mclvCanonicalExtend
(  mclv*       dst
,  dim         N
,  double      val
)
   {  dim j, N_old
   ;  ofs idx
   ;  if (!dst)
      return mclvCanonical(NULL, N, val)

   ;  N_old = dst->n_ivps
   ;  if (N < N_old)          /* fixme: err? */
      return dst

   ;  if (N_old)
      {  idx = dst->ivps[N_old-1].idx+1
      ;  if ((dim) idx != N_old)
         mcxErr("mclvCanonicalExtend", "argument not canonical (proceeding)")
   ;  }
      else
      idx = 0

   ;  mclvResize(dst, N)
   ;  for (j=N_old; j<N; j++)
         dst->ivps[j].idx = idx++ 
      ,  dst->ivps[j].val = val
   ;  return dst
;  }
Exemple #10
0
int mcxIOexpect
(  mcxIO          *xf
,  const char     *str
,  mcxOnFail      ON_FAIL
)
   {  const char* s  =  str
   ;  int         c  =  0
   ;  int         d  =  0
   ;  int         n_trailing

  /*  
   *  no functional behaviour yet attached to this state change
   *  fixme: semantics for STDIN agree between stdlib and us?
  */

   ;  while
      (  c = (uchar) s[0]
      ,  
         (  c
         && (  d = mcxIOstep(xf)
            ,  c == d
            )
         )
      )
      s++

   ;  n_trailing = strlen(s)     /* truncintok */

   ;  if (c && ON_FAIL == EXIT_ON_FAIL)
      {  mcxErr("mcxIOexpect", "parse error: expected to see <%s>", str)
      ;  mcxIOpos(xf, stderr)
      ;  mcxExit(1)
   ;  }
      return n_trailing
;  }
Exemple #11
0
static void erdos_link_together
(  mcxIO* xfout
,  mclx* mx
,  mclv* tails
,  mclv* heads
)
   {  dim v = 0
   ;  mclv* relevant = mclvInit(NULL)
   ;  fprintf(xfout->fp, "(");
   ;  for (v=0;v<tails->n_ivps;v++)
      {  long t = tails->ivps[v].idx
      ;  dim j
      ;  mclv* nb = mclxGetVector(mx, t, EXIT_ON_FAIL, NULL)
      ;  mcldMeet(nb, heads, relevant)
      ;  for (j=0;j<relevant->n_ivps;j++)
         {  if (tab_g)
            {  long u = relevant->ivps[j].idx
            ;  const char* sx = mclTabGet(tab_g, (long) t, NULL)
            ;  const char* sy = mclTabGet(tab_g, (long) u, NULL)
            ;  if (!sx)
               sx = "NAx"
            ;  if (!sy)
               sy = "NAy"
            ;  fprintf(xfout->fp, " (%s %s)", sx, sy)
         ;  }
            else
            fprintf(xfout->fp, " (%ld %ld)", (long) t, (long) relevant->ivps[j].idx)
      ;  }
         if (!relevant->n_ivps)
         mcxErr(me, "odd, %d has no friends\n", (int) t)
   ;  }
      fprintf(xfout->fp, " )\n");
   ;  mclvFree(&relevant)
;  }
Exemple #12
0
dim mclgTFexecx
(  mclx*    mx
,  mclgTF*  tf
,  mcxbool  allow_graph_ops
)
   {  dim offset = 0, k = 0
   ;  mclpAR* par_edge = tf->par_edge
   ;  mclpAR* par_graph = tf->par_graph
   ;  while (offset < par_edge->n_ivps || k < par_graph->n_ivps)
      {  dim top = offset
      ;  while (top < par_edge->n_ivps && par_edge->ivps[top].idx != MCLX_UNARY_UNUSED)
         top++
      ;  if (top > offset)
         {  mclpAR* par = mclpARfromIvps(NULL, par_edge->ivps+offset, top-offset)
;fprintf(stderr, "unary exec %d %d\n", (int) offset, (int) top)
         ;  mclxUnaryList(mx, par)
         ;  mclpARfree(&par)
      ;  }

         if (par_edge->ivps[top].idx == MCLX_UNARY_UNUSED)
         {  if (k >= par_graph->n_ivps)
            {  mcxErr("mclgTFexec", "off the rails")
            ;  break
         ;  }
            if (allow_graph_ops)
            mclgTFgraph(mx, par_graph->ivps[k].idx, par_graph->ivps[k].val)
         ;  k++
;fprintf(stderr, "graph %s top=%d k=%d\n", allow_graph_ops ? "exec" : "skip", (int) offset, (int) k)
      ;  }
         offset = top+1
   ;  }
      return mclxNrofEntries(mx)
;  }
Exemple #13
0
static mcxstatus pars_realloc
(  stream_state* iface
,  dim n_needed
)
   {  dim n_alloc = MCX_MAX(n_needed+8, iface->pars_n_alloc * 1.2)
   ;  mclpAR* p

   ;  if (n_needed <= iface->pars_n_alloc)
      {  if (n_needed > iface->pars_n_used)
         iface->pars_n_used = n_needed
      ;  return STATUS_OK
   ;  }

      p
      =  mcxNRealloc
         (  iface->pars
         ,  n_alloc
         ,  iface->pars_n_alloc
         ,  sizeof p[0]
         ,  my_par_init_v
         ,  RETURN_ON_FAIL
         )
;if(DEBUG3)fprintf(stderr, "realloc pars %lu (requested = %lu)\n", (ulong) n_alloc, (ulong) n_needed)
   ;  if (!p)
      {  mcxErr(module, "failure allocing p array (%lu units)", (ulong) n_alloc)
      ;  return STATUS_FAIL
   ;  }

      iface->pars = p
   ;  iface->pars_n_used  = n_needed
   ;  iface->pars_n_alloc = n_alloc
   ;  return STATUS_OK
;  }
Exemple #14
0
mcxstatus mcxIOexpectReal
(  mcxIO*        xf
,  double*       dblp
,  mcxOnFail     ON_FAIL
)
   {  int   n_read   =  0
   ;  int   n_conv   =  0

   ;  if (inbuffer(xf))
      buffer_spout(xf, "mcxIOexpectReal")

   ;  mcxIOskipSpace(xf)      /* keeps accounting correct */

   ;  n_conv   =  fscanf(xf->fp, " %lf%n", dblp, &n_read)

   ;  xf->bc += n_read  /* fixme do fscanf error handling */
   ;  xf->lo += n_read

   ;  if (1 != n_conv)
      {  if (ON_FAIL == EXIT_ON_FAIL)
         {  mcxIOpos(xf, stderr)
         ;  mcxErr("parseReal", "parse error: expected to find real")
         ;  mcxExit(1)
      ;  }
         return STATUS_FAIL
   ;  }
      return STATUS_OK
;  }
Exemple #15
0
int mcxIOstepback
(  int c
,  mcxIO*    xf
)
   {  if (c == EOF)
      return EOF
   ;  else
      {  if (inbuffer(xf) && xf->buffer_consumed > 0)
         c = xf->buffer->str[--xf->buffer_consumed]
   /* insert a new branch for zlib aware reading here; splice into buffer */
      ;  else if (ungetc(c, xf->fp) == EOF)
         {  mcxErr
            (  "mcxIOstepback"
            ,  "failed to push back <%d> on stream <%s>\n"
            ,  c
            ,  xf->fn->str
            )
         ;  return EOF
      ;  }

         xf->bc--
      ;  if (c == '\n')
            xf->lc--
         ,  xf->lo = xf->lo_
         ,  xf->lo_ = 0
      ;  else
         xf->lo--
   ;  }
      return c
;  }
Exemple #16
0
mcxHash* mcxHashNew
(  dim         n_buckets
,  u32         (*hash)(const void *a)
,  int         (*cmp) (const void *a, const void *b)
)
   {  mcxHash  *h
   ;  mcxbool ok  = FALSE
      
   ;  u8 n_bits   =  0

   ;  if (!n_buckets)
      {  mcxErr("mcxHashNew strange", "void alloc request")
      ;  n_buckets = 2
   ;  }

      if (!(h = mcxAlloc(sizeof(mcxHash), RETURN_ON_FAIL)))
      return NULL

   ;  while(n_buckets)
      {  n_buckets >>=  1
      ;  n_bits++
   ;  }

      h->load           =  0.5
   ;  h->n_entries      =  0
   ;  h->n_buckets      =  n_buckets = (1 << n_bits)
   ;  h->cmp            =  cmp
   ;  h->hash           =  hash
   ;  h->options        =  MCX_HASH_OPT_DEFAULTS

   ;  h->src_link       =  NULL

   ;  while (1)                        /* fixme 2nd arg below, have better choice? */
      {  h->src_link = mcxGrimNew(sizeof(hash_link), h->n_buckets, MCX_GRIM_ARITHMETIC)
      ;  if (!h->src_link)
         break

      ;  if
         (! (  h->buckets
            =  mcxNAlloc
               (  h->n_buckets
               ,  sizeof(mcx_bucket)
               ,  mcx_bucket_init
               ,  RETURN_ON_FAIL
         )  )  )
         break

      ;  ok = TRUE
      ;  break
   ;  }

      if (!ok)
      {  mcxGrimFree(&(h->src_link))
      ;  mcxFree(h)
      ;  return NULL
   ;  }

      return h
;  }
Exemple #17
0
void mclvRuntime
(  const mclVector* vec
,  const char* caller
)
   {  if (!vec)
         mcxErr(caller, "void vector argument")
      ,  mcxExit(1)
;  }
Exemple #18
0
double mclvNorm
(  const mclVector*        vec
,  double                  power
)  
   {  if(power > 0.0)
         mcxErr("mclvNorm", "pbd: negative power argument <%f>", (double) power)
      ,  mcxExit(1)

   ;  return pow((double) mclvPowSum(vec, power), 1.0 / power)
;  }
Exemple #19
0
void handle_tf
(  mclx*    mx
,  mcxTing* sa
)
   {  mclgTF* transform = mclgTFparse(NULL, sa)
   ;  if (!transform)
      mcxErr(me, "tf spec does not parse")
   ;  else
      mclgTFexec(mx, transform)
   ;  mclgTFfree(&transform)
;  }
Exemple #20
0
mcxIO* mcxIOnew
(  const char*       str
,  const char*       mode
)
   {  if (!str || !mode)
      {  mcxErr("mcxIOnew PBD", "void string or mode argument")
      ;  return NULL
   ;  }

      return mcxIOrenew(NULL, str, mode)
;  }
Exemple #21
0
mcxstatus mcxIOtestOpen
(  mcxIO*         xf
,  mcxOnFail      ON_FAIL
)
   {  if (!xf->fp && mcxIOopen(xf, ON_FAIL) != STATUS_OK)
      {  mcxErr
         ("mcxIO", "cannot open file <%s> in mode %s", xf->fn->str, xf->mode)
      ;  return STATUS_FAIL
   ;  }
      return  STATUS_OK
;  }
Exemple #22
0
mcxbool mcxIOwriteCookie
(  mcxIO* xf
,  const uchar abcd[4]
)
   {  dim n_written = fwrite(abcd, sizeof abcd[0], 4, xf->fp)
   ;  if (n_written != 4)
      {  mcxErr("mcxIOwriteCookie", "failed to write <%.4s>", abcd)
      ;  return FALSE
   ;  }

      return TRUE
;  }
Exemple #23
0
static mcxstatus handle_label
(  mcxTing**      keypp
,  unsigned long* z
,  map_state*     map_z
,  mcxbits        bits
,  const char*    mode
)
   {  mcxbool strict =  bits & MCLXIO_STREAM_GTAB_STRICT
   ;  mcxbool warn   =  bits & MCLXIO_STREAM_WARN
   ;  mcxbool ro     =  bits & (MCLXIO_STREAM_GTAB_STRICT | MCLXIO_STREAM_GTAB_RESTRICT)
   ;  mcxbool debug  =  bits & MCLXIO_STREAM_DEBUG

   ;  mcxstatus status = STATUS_OK
   ;  mcxKV* kv = mcxHashSearch(*keypp, map_z->map, ro ? MCX_DATUM_FIND : MCX_DATUM_INSERT)

   ;  if (!kv)      /* ro and not found */
      {  if (strict)
         {  mcxErr
            (module, "label <%s> not found (%s strict)", (*keypp)->str, mode)
         ;  status = STATUS_FAIL
      ;  }
         else
         {  if (warn)  /* restrict */
            mcxTell
            (module, "label <%s> not found (%s restrict)", (*keypp)->str, mode)
         ;  status = STATUS_IGNORE
      ;  }
      }
      else if (kv->key != *keypp)         /* seen */
      {  mcxTingFree(keypp)
      ;  *z = VOID_TO_ULONG kv->val     /* fixme theoretical signedness issue */
   ;  }
      else                             /* INSERTed */
      {  if (debug)
         mcxTell
         (  module
         ,  "label %s not found (%s extend %lu)"
         ,  (*keypp)->str
         ,  mode
         ,  (map_z->max_seen + 1)
         )
      ;  map_z->n_seen++
      ;  map_z->max_seen++
      ;  kv->val = ULONG_TO_VOID map_z->max_seen
      ;  *z = map_z->max_seen           /* fixme theoretical signedness issue */
;if(DEBUG3)fprintf(stderr, "hl insert %s <%s> to %d\n", mode, keypp[0]->str, (int) *z)
      ;  status = STATUS_NEW
   ;  }

;if(DEBUG2)fprintf(stderr, "hl final map to %d\n", (int) *z)
   ;  return status
;  }
Exemple #24
0
void mclvScale
(  mclVector*  vec
,  double      fac
)  
   {  dim      n_ivps   =  vec->n_ivps
   ;  mclIvp*  ivps     =  vec->ivps

   ;  if (!fac)
      mcxErr("mclvScale PBD", "zero")

   ;  while (n_ivps-- > 0)
      (ivps++)->val /= fac
;  }
Exemple #25
0
static void buffer_spout
(  mcxIO* xf
,  const char* me
)
   {  mcxErr
      (  "mcxIO"
      ,  "warning: reader %s in file <%s> discards buffered input <%.*s>"
      ,  me
      ,  xf->fn->str
      ,  (int) (xf->buffer->len - xf->buffer_consumed)
      ,  xf->buffer->str+xf->buffer_consumed
      )
   ;  buffer_empty(xf)
;  }
Exemple #26
0
int main
(  int               argc
,  const char*       argv[]
)
   {  const char* fn_input    =  argc > 1 ? argv[1] : ""
   ;  mclAlgParam* mlp        =  NULL
   ;  const char* me          =  "mcl"
   ;  mcxstatus status        =  STATUS_OK

   ;  srandom(mcxSeed(315))
   ;  signal(SIGALRM, mclSigCatch)
   ;  if (signal(SIGUSR1, mcxLogSig) == SIG_ERR)
      mcxErr(me, "cannot catch SIGUSR1!")

   ;  mcxLogLevel =
      MCX_LOG_AGGR | MCX_LOG_MODULE | MCX_LOG_IO | MCX_LOG_GAUGE | MCX_LOG_WARN
   ;  mclx_app_init(stderr)

   ;  if (argc < 2)
      {  mcxTell
         (  me
         ,  "usage: mcl <-|file name> [options],"
            " do 'mcl -h' or 'man mcl' for help"
         )
      ;  mcxExit(0)
   ;  }

      status
      =  mclAlgInterface
         (&mlp, (char**) (argv+2), argc-2, fn_input, NULL, ALG_DO_IO)

   ;  if (status == ALG_INIT_DONE)
      return 0
   ;  else if (status)
      mcxDie(STATUS_FAIL, me, "no tango")

   ;  if ((status = mclAlgorithm(mlp)) == STATUS_FAIL)
      mcxDie(STATUS_FAIL, me, "failed")

   ;  if (mlp->n_assimilated)
      mcxLog(MCX_LOG_MODULE, me, "%lu nodes will assimilate", (ulong) mlp->n_assimilated)

   ;  if (mlp->mx_start)
      mcxLog(MCX_LOG_MODULE, me, "cached matrix with %lu columns", (ulong) N_COLS(mlp->mx_start))

   ;  mclAlgParamFree(&mlp, TRUE)
   ;  helpful_reminder()
   ;  return STATUS_OK
;  }
Exemple #27
0
void mcxIOerr
(  mcxIO*   xf
,  const char     *complainer
,  const char     *complaint
)
   {  if (!xf)
      return

   ;  mcxErr
      (  complainer
      ,  "%s stream <%s> %s"
      ,  xf->mode
      ,  xf->fn->str
      ,  complaint
      )  
;  }
Exemple #28
0
mcxbool mcldEquate
(  const mclVector* dom1
,  const mclVector* dom2
,  mcxenum    mode
)
   {  dim meet, ldif, rdif
   ;  mcldCountParts(dom1, dom2, &ldif, &meet, &rdif)

   ;  switch(mode)
      {  case MCLD_EQT_SUPER
      :  return rdif == 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_SUB
      :  return ldif == 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_EQUAL
      :  return ldif + rdif == 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_DISJOINT
      :  return meet == 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_TRISPHERE
      :  return ldif != 0 && rdif != 0 && meet != 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_LDIFF
      :  return ldif != 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_MEET
      :  return meet != 0 ? TRUE : FALSE
      ;

         case MCLD_EQT_RDIFF
      :  return rdif != 0 ? TRUE : FALSE
      ;

         default
      :  mcxErr("mcldEquate PBD", "unknown mode <%d>", (int) mode)
      ;  break
   ;  }
      return TRUE
;  }
Exemple #29
0
static void clm_dump_line
(  const char* name
,  clmVScore*  sc
,  long        nid
,  long        cid
,  dim         ndsize
,  dim         clsize         /* for defensive check */
,  int         alien
)
   {  double sum = sc->sum_i + sc->sum_o
   ;  double eff, eff_max
   ;  mcxTing* ti = NULL, *to = NULL

   ;  clmVScoreCoverage(sc, &eff, &eff_max)
   ;  if (clsize != sc->n_ddif + sc->n_meet)
      mcxErr
      (  "clmDumpNodeScores panic"
      ,  "for cluster %ld in %s diff <%ld> meet <%ld> do not add to <%lu>"
      ,  (long) cid
      ,  name
      ,  (long) sc->n_ddif
      ,  (long) sc->n_meet
      ,  (ulong) clsize
      )

   ;  if (sum && sc->max_i > -FLT_MAX)
      ti = mcxTingPrint(NULL, "%.5f", sc->max_i / sum)

   ;  if (sum && sc->max_o > -FLT_MAX)
      to = mcxTingPrint(NULL, "%.5f", sc->max_o / sum)

   ;  fprintf
      (  stdout
      ,  "nm=%s ni=%ld ci=%ld nn=%lu nc=%lu"
         " ef=%.5f em=%.5f mf=%.5f ma=%.5f"
         " xn=%lu xc=%lu ns=%lu"
         " ti=%s to=%s"
         " al=%d"
         "\n"

      ,  name,  nid,  cid,  (ulong) ndsize, (ulong) clsize
      ,  eff,  eff_max,  sum ? sc->sum_i / sum : 0.0f,  sc->sum_e
      ,  (ulong) sc->n_vdif, (ulong) sc->n_ddif,  (ulong) sc->n_meet
      ,  (ti ? ti->str : "na"),  (to ? to->str : "na")
      ,  alien
      )
;  }
Exemple #30
0
mcxstatus mcxIOappendName
(  mcxIO*         xf
,  const char*    suffix
)
   {  if (xf->fp && !xf->stdio)
      mcxErr
      (  "mcxIOappendName PBD"
      ,  "stream open while request for name change from <%s> to <%s>"
      ,  xf->fn->str
      ,  suffix
      )
   ;  else if (!mcxTingAppend(xf->fn, suffix))
      return STATUS_FAIL

   ;  xf->stdio = begets_stdio(xf->fn->str, "-")
   ;  return STATUS_OK
;  }