mclMatrix* mclDiagOrdering ( const mclMatrix* M , mclVector** vecp_attr ) { int n_cols = N_COLS(M) ; mclMatrix* diago = mclxAllocZero(NULL, NULL) ; long col ; if (*vecp_attr != NULL) mclvFree(vecp_attr) ; *vecp_attr = mclvResize(NULL, n_cols) ; for (col=0;col<n_cols;col++) { ofs offset = -1 ; double selfval = mclvIdxVal(M->cols+col, col, &offset) ; double center = mclvPowSum(M->cols+col, 2.0) /* double maxval = mclvMaxValue(M->cols+col) */ ; double bar = MCX_MAX(center, selfval) - dpsd_delta ; mclIvp* ivp = (*vecp_attr)->ivps+col ; ivp->idx = col ; ivp->val = center ? selfval / center : 0 ; if (offset >= 0) /* take only higher valued entries */ mclvSelectGqBar(diago->cols+col, bar) ; } ; return diago ; }
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 ; }
static void set_cl_to_projection ( mclMatrix* cl , mclMatrix* el_on_cl ) { dim i, j ; for (i=0;i<N_COLS(cl);i++) { mclv* clvec = cl->cols+i ; long clid = clvec->vid ; mclv* elclvec = NULL ; mclp* valivp = NULL ; for (j=0;j<clvec->n_ivps;j++) { long elid = clvec->ivps[j].idx ; elclvec = mclxGetVector(el_on_cl, elid, EXIT_ON_FAIL, elclvec) ; valivp = mclvGetIvp(elclvec, clid, NULL) ; if (!valivp && clvec->n_ivps > 1) mcxErr("clmCastActors", "match error: el %ld cl %ld", elid, clid) ; clvec->ivps[j].val = valivp ? MCX_MAX(0.01, valivp->val) : 0.01 ; } } }
void mcxHashStats ( FILE* fp , mcxHash* h ) { dim buckets = h->n_buckets ; dim buckets_used = 0 ; float ctr = 0.0 ; float cb = 0.0 ; dim max = 0 ; dim entries = 0 ; const char* me = "mcxHashStats" ; int j, k, distr[32] ; mcx_bucket *buck ; for (j=0;j<32;j++) distr[j] = 0 ; for (buck=h->buckets; buck<h->buckets + h->n_buckets; buck++) { dim d = hash_link_size(buck->base) ; hash_link* this= buck->base ; if (d) { buckets_used++ ; entries += d ; ctr += (float) d * d ; cb += (float) d * d * d ; max = MCX_MAX(max, d) ; } while(this) { u32 u = (h->hash)(this->kv.key) ; int ct = bitcount(u) ; this = this->next ; distr[ct]++ ;if (0) fprintf(stderr, "bucket [%d] key [%s]\n", (int)d, ((mcxTing*) this->kv.key)->str) ; } } ctr = ctr / MCX_MAX(1, entries) ; cb = sqrt(cb / MCX_MAX(1, entries)) ; if (buckets && buckets_used) mcxTellf ( fp , me , "%4.2f bucket usage (%ld available, %ld used, %ld entries)" , (double) ((double) buckets_used) / buckets , (long) buckets , (long) buckets_used , (long) entries ) , mcxTellf ( fp , me , "bucket average: %.2f, center: %.2f, cube: %.2f, max: %ld" , (double) entries / ((double) buckets_used) , (double) ctr , (double) cb , (long) max ) ; mcxTellf(fp, me, "bit distribution (promilles):") ; fprintf ( fp , " %-37s %s\n" , "Current bit distribution" , "Ideally random distribution" ) ; for (k=0;k<4;k++) { for (j=k*8;j<(k+1)*8;j++) fprintf(fp, "%3.0f ", entries ? (1000 * (float)distr[j]) / entries : 0.0) ; fprintf(fp, " "); ; for (j=k*8;j<(k+1)*8;j++) fprintf(fp, "%3d ", promilles[j]) ; fprintf(fp, "\n") ; } mcxTellf(fp, me, "link count: %ld", (long) (mcxGrimCount(h->src_link))) ; mcxTellf(fp, me, "link mem count: %ld", (long) (mcxGrimMemSize(h->src_link))) ; mcxTellf(fp, me, "done") ; }
void mclpMergeMax ( void* i1 , const void* i2 ) { ((mclIvp*)i1)->val = MCX_MAX(((mclIvp*)i1)->val,((mclIvp*)i2)->val) ; }