Ejemplo n.º 1
0
int main(int argc, char *argv[]){

	int n = 10, m = 51;
	int i;
	int *f; f = (int*)malloc(sizeof(int)*n);
	setvals(f,n,m);
	
	for(i=0;i<n;i++){
		printf("%d\n",f[i]);
	}

	return 0;
}
Ejemplo n.º 2
0
Archivo: cs_supp.c Proyecto: nasa/QuIP
static void init_cstepit_params(SINGLE_QSP_ARG_DECL)
{
	double xmin[MAX_OPT_PARAMS];
	double xmax[MAX_OPT_PARAMS];
	double deltx[MAX_OPT_PARAMS];
	double delmn[MAX_OPT_PARAMS];
	double ans[MAX_OPT_PARAMS];
	List *lp;
	Node *np;
	Opt_Param *opp;
	int i,n;
	int nfmax;		/* max. # function calls */

#ifdef THREAD_SAFE_QUERY
	cs_qsp = THIS_QSP;
#endif // THREAD_SAFE_QUERY

	lp = opt_param_list();
	if( lp == NULL ) return;

	n_prms=eltcount(lp);
	n=reset_n_params(n_prms);
	if( n != n_prms ) n_prms = n;

	np=QLIST_HEAD(lp);
	i=0;
	while( np!= NULL && i < n_prms ){
		opp = (Opt_Param *)(np->n_data);

		xmin[i]=opp->minv;
		xmax[i]=opp->maxv;
		deltx[i]=opp->delta;
		delmn[i]=opp->mindel;
		ans[i]=opp->ans;

		i++;
		np=np->n_next;
	}
	nfmax=100000;

	/* copy to fortran */

	setvals(QSP_ARG  ans,n_prms);
	setminmax(QSP_ARG  xmin,xmax,n_prms);
	setdelta(QSP_ARG  deltx,delmn,n_prms);
//advise("SETTING ntrace to 1 FOR MAX DEBUG!");
//	settrace(1);
	setmaxcalls(nfmax);
}
Ejemplo n.º 3
0
int main(int argc,char *argv[]) {
    codebook *b;
    static_codebook *c;
    int entries=-1,dim=-1;
    float min,del;
    char *name;
    long i,j;
    float *suggestions;
    int suggcount=0;

    if(argv[1]==NULL) {
        fprintf(stderr,"Need a lattice book on the command line.\n");
        exit(1);
    }

    {
        char *ptr;
        char *filename=strdup(argv[1]);

        b=codebook_load(filename);
        c=(static_codebook *)(b->c);

        ptr=strrchr(filename,'.');
        if(ptr) {
            *ptr='\0';
            name=strdup(filename);
        } else {
            name=strdup(filename);
        }
    }

    if(c->maptype!=1) {
        fprintf(stderr,"Provided book is not a latticebook.\n");
        exit(1);
    }

    entries=b->entries;
    dim=b->dim;
    min=_float32_unpack(c->q_min);
    del=_float32_unpack(c->q_delta);

    /* Do we want to gen a threshold hint? */
    if(c->q_sequencep==0) {
        /* yes. Discard any preexisting threshhold hint */
        long quantvals=_book_maptype1_quantvals(c);
        long **quantsort=alloca(quantvals*sizeof(long *));
        encode_aux_threshmatch *t=_ogg_calloc(1,sizeof(encode_aux_threshmatch));
        c->thresh_tree=t;

        fprintf(stderr,"Adding threshold hint to %s...\n",name);

        /* partial/complete suggestions */
        if(argv[2]) {
            char *ptr=strdup(argv[2]);
            suggestions=alloca(sizeof(float)*quantvals);

            for(suggcount=0; ptr && suggcount<quantvals; suggcount++) {
                char *ptr2=strchr(ptr,',');
                if(ptr2)*ptr2++='\0';
                suggestions[suggcount]=atof(ptr);
                ptr=ptr2;
            }
        }

        /* simplest possible threshold hint only */
        t->quantthresh=_ogg_calloc(quantvals-1,sizeof(float));
        t->quantmap=_ogg_calloc(quantvals,sizeof(int));
        t->threshvals=quantvals;
        t->quantvals=quantvals;

        /* the quantvals may not be in order; sort em first */
        for(i=0; i<quantvals; i++)quantsort[i]=c->quantlist+i;
        qsort(quantsort,quantvals,sizeof(long *),longsort);

        /* ok, gen the map and thresholds */
        for(i=0; i<quantvals; i++)t->quantmap[i]=quantsort[i]-c->quantlist;
        for(i=0; i<quantvals-1; i++) {
            float v1=*(quantsort[i])*del+min;
            float v2=*(quantsort[i+1])*del+min;

            for(j=0; j<suggcount; j++)
                if(v1<suggestions[j] && suggestions[j]<v2) {
                    t->quantthresh[i]=suggestions[j];
                    break;
                }

            if(j==suggcount) {
                t->quantthresh[i]=(v1+v2)*.5;
            }
        }
    }

    /* Do we want to gen a pigeonhole hint? */
#if 0
    for(i=0; i<entries; i++)if(c->lengthlist[i]==0)break;
    if(c->q_sequencep || i<entries) {
        long **tempstack;
        long *tempcount;
        long *temptrack;
        float *tempmin;
        float *tempmax;
        long totalstack=0;
        long pigeons;
        long subpigeons;
        long quantvals=_book_maptype1_quantvals(c);
        int changep=1,factor;

        encode_aux_pigeonhole *p=_ogg_calloc(1,sizeof(encode_aux_pigeonhole));
        c->pigeon_tree=p;

        fprintf(stderr,"Adding pigeonhole hint to %s...\n",name);

        /* the idea is that we quantize uniformly, even in a nonuniform
           lattice, so that quantization of one scalar has a predictable
           result on the next sequential scalar in a greedy matching
           algorithm.  We generate a lookup based on the quantization of
           the vector (pigeonmap groups quantized entries together) and
           list the entries that could possible be the best fit for any
           given member of that pigeonhole.  The encode process then has a
           much smaller list to brute force */

        /* find our pigeonhole-specific quantization values, fill in the
           quant value->pigeonhole map */
        factor=3;
        p->del=del;
        p->min=min;
        p->quantvals=quantvals;
        {
            int max=0;
            for(i=0; i<quantvals; i++)if(max<c->quantlist[i])max=c->quantlist[i];
            p->mapentries=max;
        }
        p->pigeonmap=_ogg_malloc(p->mapentries*sizeof(long));
        p->quantvals=(quantvals+factor-1)/factor;

        /* pigeonhole roughly on the boundaries of the quantvals; the
           exact pigeonhole grouping is an optimization issue, not a
           correctness issue */
        for(i=0; i<p->mapentries; i++) {
            float thisval=del*i+min; /* middle of the quant zone */
            int quant=0;
            float err=fabs(c->quantlist[0]*del+min-thisval);
            for(j=1; j<quantvals; j++) {
                float thiserr=fabs(c->quantlist[j]*del+min-thisval);
                if(thiserr<err) {
                    quant=j/factor;
                    err=thiserr;
                }
            }
            p->pigeonmap[i]=quant;
        }

        /* pigeonmap complete.  Now do the grungy business of finding the
        entries that could possibly be the best fit for a value appearing
        in the pigeonhole. The trick that allows the below to work is the
        uniform quantization; even though the scalars may be 'sequential'
        (each a delta from the last), the uniform quantization means that
        the error variance is *not* dependant.  Given a pigeonhole and an
        entry, we can find the minimum and maximum possible errors
        (relative to the entry) for any point that could appear in the
        pigeonhole */

        /* must iterate over both pigeonholes and entries */
        /* temporarily (in order to avoid thinking hard), we grow each
           pigeonhole separately, the build a stack of 'em later */
        pigeons=1;
        subpigeons=1;
        for(i=0; i<dim; i++)subpigeons*=p->mapentries;
        for(i=0; i<dim; i++)pigeons*=p->quantvals;
        temptrack=_ogg_calloc(dim,sizeof(long));
        tempmin=_ogg_calloc(dim,sizeof(float));
        tempmax=_ogg_calloc(dim,sizeof(float));
        tempstack=_ogg_calloc(pigeons,sizeof(long *));
        tempcount=_ogg_calloc(pigeons,sizeof(long));

        while(1) {
            float errorpost=-1;
            char buffer[80];

            /* map our current pigeonhole to a 'big pigeonhole' so we know
               what list we're after */
            int entry=0;
            for(i=dim-1; i>=0; i--)entry=entry*p->quantvals+p->pigeonmap[temptrack[i]];
            setvals(dim,p,temptrack,tempmin,tempmax,c->q_sequencep);
            sprintf(buffer,"Building pigeonhole search list [%ld]...",totalstack);


            /* Search all entries to find the one with the minimum possible
               maximum error.  Record that error */
            for(i=0; i<entries; i++) {
                if(c->lengthlist[i]>0) {
                    float this=maxerror(dim,b->valuelist+i*dim,p,
                                        temptrack,tempmin,tempmax);
                    if(errorpost==-1 || this<errorpost)errorpost=this;
                    spinnit(buffer,subpigeons);
                }
            }

            /* Our search list will contain all entries with a minimum
               possible error <= our errorpost */
            for(i=0; i<entries; i++)
                if(c->lengthlist[i]>0) {
                    spinnit(buffer,subpigeons);
                    if(minerror(dim,b->valuelist+i*dim,p,
                                temptrack,tempmin,tempmax)<errorpost)
                        totalstack+=addtosearch(entry,tempstack,tempcount,i);
                }

            for(i=0; i<dim; i++) {
                temptrack[i]++;
                if(temptrack[i]<p->mapentries)break;
                temptrack[i]=0;
            }
            if(i==dim)break;
            subpigeons--;
        }