Esempio n. 1
0
/* Do smoothness scaling check & return results */
static double do_stest(
	int verb,			/* Verbosity */
	int di,				/* Dimensions */
	int its,			/* Number of function tests */
	int res				/* RSPL grid resolution */
) {
	funcp fp;			/* Function parameters */
	DCOUNT(gc, MXDIDO, di, 1, 1, res-1);
	int it;
	double atse = 0.0;

	/* Make repeatable by setting random seed before a test set. */
	rand32(0x12345678);

	for (it = 0; it < its; it++) {
		double tse;
		setup_func(&fp, di);		/* New function */

		DC_INIT(gc)
		tse = 0.0;
		for (; !DC_DONE(gc);) {
			double g[MXDI];
			int e, k;
			double y1, y2, y3;
			double del;

			for (e = 0; e < di; e++)
				g[e] = gc[e]/(res-1.0);
			y2 = lookup_func(&fp, g);

			del = 1.0/(res-1.0);

			for (k = 0 ; k < di; k++) {
				double err;

				g[k] -= del;
				y1 = lookup_func(&fp, g);
				g[k] += 2.0 * del;
				y3 = lookup_func(&fp, g);
				g[k] -= del;

				err = 0.5 * (y3 + y1) - y2;
				tse += err * err;
			}

			DC_INC(gc);
		}
		/* Apply adjustments and corrections */
		tse *= pow((res-1.0), 4.0);					/* Aprox. geometric resolution factor */
		tse /= pow((res-2.0),(double)di);			/* Average squared non-smoothness */

		if (verb)
			printf("smf for it %d = %f\n",it,tse);
		atse += tse;
	}

	return atse/(double)its;
}
Esempio n. 2
0
void ObjEmitReloc( owl_section_handle section, void *target, owl_reloc_type type, bool align, bool named_sym ) {
//**************************************************************************************************************
// Should be called before emitting the data that has the reloc.
// (named_sym == TRUE) iff the target is a named label

    owl_offset          offset;

    if( align ) { // If data is aligned, we should also align this reloc offset!
        offset = ObjAlign( section, CurrAlignment );
    } else {
        offset = OWLTellOffset( section );
    }
    ObjFlushLabels();
#ifdef AS_PPC
    doEmitReloc( section, offset, target, type, named_sym );
#else
    {
        sym_reloc       reloc;
        bool            match_high;
        owl_offset      offset_hi, offset_lo;
        sym_handle      (*lookup_func)( void * );

        if( type != OWL_RELOC_HALF_HI && type != OWL_RELOC_HALF_LO ) {
            doEmitReloc( section, offset, target, type, named_sym );
        } else {
            lookup_func = named_sym ?
                (sym_handle (*)(void *))SymLookup :
                (sym_handle (*)(void *))AsNumLabelSymLookup;
            match_high = ( type == OWL_RELOC_HALF_LO );    // hi match lo etc.
            reloc = SymMatchReloc( match_high, lookup_func( target ), section );
            if( reloc ) {       // got a match
                if( match_high ) {
                    offset_hi = reloc->location.offset;
                    offset_lo = offset;
                } else {
                    offset_hi = offset;
                    offset_lo = reloc->location.offset;
                }
                doEmitReloc( section, offset_hi, target, OWL_RELOC_HALF_HI, named_sym );
                doEmitReloc( section, offset_lo, target, OWL_RELOC_PAIR, named_sym );
                doEmitReloc( section, offset_lo, target, OWL_RELOC_HALF_LO, named_sym );
                SymDestroyReloc( lookup_func( target ), reloc );
            } else {    // no match; stack it up with the (aligned) offset!
                SymStackReloc( !match_high, lookup_func( target ), section, offset, named_sym );
            }
        }
    }
#endif
}
Esempio n. 3
0
File: menu.c Progetto: Cougar/pwm
void init_menus()
{
	WFuncBinder binder={&dummy_func, 0, ARGTYPE_NONE};

	add_binding(ACT_BUTTONPRESS, ACTX_MENU, 0, AnyButton, &binder);
	add_binding(ACT_BUTTONMOTION, ACTX_MENU, 0, AnyButton, &binder);
	add_binding(ACT_BUTTONCLICK, ACTX_MENU, 0, AnyButton, &binder);
	
	binder.func=lookup_func("menu_raisekeep", ARGTYPE_NONE);
	add_binding(ACT_BUTTONPRESS, ACTX_MENUTITLE, 0, AnyButton, &binder);
	binder.func=lookup_func("menu_close", ARGTYPE_NONE);
	add_binding(ACT_BUTTONDBLCLICK, ACTX_MENUTITLE, 0, AnyButton, &binder);
	binder.func=lookup_func("move", ARGTYPE_NONE);
	add_binding(ACT_BUTTONMOTION, ACTX_MENUTITLE, 0, AnyButton, &binder);
}
Esempio n. 4
0
/*-----------------------------------------------------------------
 * MAIN
 *----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    byte*     buf;
    int       size = BUF_SIZE;

    if (argc > 1) {
	test(argc, argv);
	return 0;
    }

    fprintf(stderr, "gssapi started\r\n");

    if ((buf = malloc(size)) == NULL)
	return -1;
    
    while ( (buf = read_cmd(buf, &size)) ) {
	int res = 0;
	int index = 0;
	int version, arity;
	char command[MAXATOMLEN];
	ei_x_buff result;
	port_func func;

	/* Ensure that we are receiving the binary term by reading and 
	 * stripping the version byte */
	EI(ei_decode_version(buf, &index, &version));
    
	/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
	EI(ei_decode_tuple_header(buf, &index, &arity));
    
	EI(arity != 2);
    
	EI(ei_decode_atom(buf, &index, command));

	/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
	EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
    
/* 	fprintf(stderr, "command: %s\r\n", command); */
	func = lookup_func(command);

	if (func) {
	    res = func(buf, index, &result);
	} else {
	    EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
	}

	write_cmd(&result);

	ei_x_free(&result);
    }

/* error: */
    fprintf(stderr, "No more command, exiting\r\n");

    return 0;
}
Esempio n. 5
0
int get_token(void)
    {
    int i;
    while (is_white(*cur_pos) && *cur_pos) cur_pos++;

    if (*cur_pos == NULL)
        {
        cur_token[0] = NULL;
        token_type = Unknown;
        return 0;   /* end of line */
        }

    /* check relation operator */
    if (strchr("!<>=", *cur_pos))
        {
        cur_token[0] = *cur_pos++;  /* get first char */
        cur_token[1] = NULL;
        if (*cur_pos == '=')   /*  ==, !=, >=, <=  */
            {
            cur_token[1] = *cur_pos++;
            cur_token[2] = NULL;
            }
        if (strcmp(cur_token, "=") == 0) token_type = Operator;
        else token_type = Rel_Op;
        return 1;
        }
    if (is_delim(*cur_pos))
        {
        cur_token[0] = *cur_pos++;
        cur_token[1] = NULL;
        token_type = Unknown;
        return 1;
        }
    if (is_alpha(*cur_pos))
        {
        i = 0;
        while (!is_delim(*cur_pos))
            cur_token[i++] = *cur_pos++;
        cur_token[i] = NULL;
        if (lookup_var(cur_token) != -1) token_type = Variable;
        else if (lookup_func(cur_token) != -1) token_type = Function;
        else token_type = Unknown;
        return 1;
        }
    if (is_digit(*cur_pos))
        {
        i = 0;
        while (is_digit(*cur_pos))
            cur_token[i++] = *cur_pos++;
        cur_token[i] = NULL;
        token_type = Number;
        return 1;
        }
    return 0;
    }
Esempio n. 6
0
void proc_exp_atom(double *result)
    {
    double arg;
    char *endptr;
    char *temp_cur_pos;
    int i;
    int p;
    if (token_type == Function)
        {
        i = lookup_func(cur_token);
        if (!get_token())
            {
            status = Lparen_Needed;
            return;
            }
        if (strcmp(cur_token, "(") != 0)
            {
            status = Lparen_Needed;
            return;
            }
        temp_cur_pos = cur_pos;
        for (p = 0; *temp_cur_pos && (*temp_cur_pos != ')' || p != 0);
             temp_cur_pos++)
            {
            if (*temp_cur_pos == '(') p++;
            if (*temp_cur_pos == ')') p--;
            }
        if (*temp_cur_pos == NULL)
            {
            status = Rparen_Needed;
            return;
            }
        *temp_cur_pos = NULL;
        get_token();
        proc_exp_assign(&arg);
        *temp_cur_pos = ')';
        get_token(); get_token();
        *result = function[i](arg);
        return;
        }
    if (token_type == Variable)
        {
        *result = get_var(cur_token[0]);
        get_token();
        return;
        }
    if (token_type == Number)
        {
        *result = strtod(cur_token, &endptr);
        get_token();
        return;
        }
    status = Syntax_Error;
    }
Esempio n. 7
0
/*
 * Solaris Kerberos (illumos)
 *
 * Allow main programs to provide an override function for _locate_server,
 * named _krb5_override_service_locator().  If that function is found in
 * the main program, it's called like a service locator plugin function.
 * If it returns KRB5_PLUGIN_NO_HANDLE, continue with other _locate_server
 * functions.  If it returns anything else (zero or some other error),
 * that return is "final" (no other _locate_server functions are called).
 * This mechanism is used by programs like "idmapd" that want to completely
 * control service location.
 */
static krb5_error_code
override_locate_server (krb5_context ctx, const krb5_data *realm,
		      struct addrlist *addrlist,
		      enum locate_service_type svc, int socktype, int family)
{
    struct module_callback_data cbdata = { 0, };
    krb5_error_code code;
    void *dlh;
    krb5_lookup_func lookup_func;

    Tprintf("in override_locate_server\n");
    cbdata.lp = addrlist;

    if ((dlh = dlopen(0, RTLD_FIRST | RTLD_LAZY)) == NULL) {
	Tprintf("dlopen failed\n");
	return KRB5_PLUGIN_NO_HANDLE;
    }
    lookup_func = (krb5_lookup_func) dlsym(
	dlh, "_krb5_override_service_locator");
    dlclose(dlh);
    if (lookup_func == NULL) {
	Tprintf("dlsym failed\n");
	return KRB5_PLUGIN_NO_HANDLE;
    }

    code = lookup_func(ctx, svc, realm->data, socktype, family,
		       module_callback, &cbdata);
    if (code == KRB5_PLUGIN_NO_HANDLE) {
	Tprintf("override lookup routine returned KRB5_PLUGIN_NO_HANDLE\n");
	return code;
    }
    if (code != 0) {
	/* Module encountered an actual error.  */
	Tprintf("override lookup routine returned error %d: %s\n",
		    code, error_message(code));
	return code;
    }

    /* Got something back, yippee.  */
    Tprintf("now have %d addrs in list %p\n", addrlist->naddrs, addrlist);
    print_addrlist(addrlist);

    return 0;
}
Esempio n. 8
0
File: macroexp.c Progetto: 5kg/gdb
/* If the single token in SRC_FIRST followed by the tokens in SRC_REST
   constitute a macro invokation not forbidden in NO_LOOP, append its
   expansion to DEST and return non-zero.  Otherwise, return zero, and
   leave DEST unchanged.

   SRC_FIRST and SRC_REST must be shared buffers; DEST must not be one.
   SRC_FIRST must be a string built by get_token.  */
static int
maybe_expand (struct macro_buffer *dest,
              struct macro_buffer *src_first,
              struct macro_buffer *src_rest,
              struct macro_name_list *no_loop,
              macro_lookup_ftype *lookup_func,
              void *lookup_baton)
{
  gdb_assert (src_first->shared);
  gdb_assert (src_rest->shared);
  gdb_assert (! dest->shared);

  /* Is this token an identifier?  */
  if (src_first->is_identifier)
    {
      /* Make a null-terminated copy of it, since that's what our
         lookup function expects.  */
      char *id = xmalloc (src_first->len + 1);
      struct cleanup *back_to = make_cleanup (xfree, id);

      memcpy (id, src_first->text, src_first->len);
      id[src_first->len] = 0;
          
      /* If we're currently re-scanning the result of expanding
         this macro, don't expand it again.  */
      if (! currently_rescanning (no_loop, id))
        {
          /* Does this identifier have a macro definition in scope?  */
          struct macro_definition *def = lookup_func (id, lookup_baton);

          if (def && expand (id, def, dest, src_rest, no_loop,
                             lookup_func, lookup_baton))
            {
              do_cleanups (back_to);
              return 1;
            }
        }

      do_cleanups (back_to);
    }

  return 0;
}
Esempio n. 9
0
void *thread_func(void *arg) {
	long long thread_num = (long long)arg;
	// insert elements
	int start_elem = thread_num * num_iterations;
	int end_elem = start_elem + num_iterations - 1;
	int i, hash;
	for (i = start_elem; i <= end_elem; i++) {
		hash = list_hash(list_elements[i]->key);
		insert_func(sorted_lists[hash], list_elements[i]);
	}
	//printf("printing list:\n");
	//SortedList_print(sorted_list);

	// count lengths
	int total_length = 0;
	for (i = 0; i < num_lists; i++) {
		int list_size = length_func(sorted_lists[i]);
		if (list_size == -1) {
			fprintf(stderr, "length() detected corrupted list!\n");
			exit(1);
		}
		total_length += list_size;
	}

	// lookup, deletes
	SortedListElement_t *found;
	for (i = start_elem; i <= end_elem; i++) {
		const char *key = list_elements[i]->key;
		hash = list_hash(key);
		found = lookup_func(sorted_lists[hash], key);

		if (found == NULL) {
			fprintf(stderr, "lookup() did not find key!\n");
			exit(1);
		}
		if (delete_func(found)) {
			fprintf(stderr, "delete() detected corrupted list!\n");
			exit(1);
		}
	}
	return (void*)arg;
}
Esempio n. 10
0
/* Do one set of tests and return the results */
static void do_test(
	double *trmse,		/* RETURN total RMS error */
	double *tmaxe,		/* RETURN total maximum error */
	double *tavge,		/* RETURN total average error */
	int verb,			/* Verbosity */
	int plot,			/* Plot graphs */
	int di,				/* Dimensions */
	int its,			/* Number of function tests */
	int res,			/* RSPL grid resolution */
	int ntps,			/* Number of sample points */
	double noise,		/* Sample point noise volume (total = 4 x average deviation) */
	int unif,			/* NZ if uniform rather than standard deistribution noise */
	double smooth,		/* Smoothness to test, +ve for extra, -ve for underlying */
	int autosm,			/* Use auto smoothing */
	int seed			/* Random seed value offset */
) {
	funcp fp;			/* Function parameters */
	sobol *so;			/* Sobol sequence generator */
	co *tps = NULL;
	rspl *rss;	/* Multi-resolution regularized spline structure */
	datai low,high;
	double avgdev[MXDO];
	int gres[MXDI];
	int i, j, it;
	int flags = RSPL_NOFLAGS;

	if (autosm)
		flags |=  RSPL_AUTOSMOOTH;

	*trmse = 0.0;
	*tmaxe = 0.0;
	*tavge = 0.0;

	for (j = 0; j < di; j++) {
		low[j] = 0.0;
		high[j] = 1.0;
		gres[j] = res;
	}
	
	if ((so = new_sobol(di)) == NULL)
		error("Creating sobol sequence generator failed");

	for (it = 0; it < its; it++) {
		double rmse, avge, maxe;
		double tnoise = 0.0;

		/* Make repeatable by setting random seed before a test set. */
		rand32(0x12345678 + seed + 0x1000 * it);

		/* New function */
		setup_func(&fp, di);

		/* Create the object */
		rss = new_rspl(RSPL_NOFLAGS,di, 1);

		/* Create the list of sampling points */
		if ((tps = (co *)malloc(ntps * sizeof(co))) == NULL)
			error ("malloc failed");

		so->reset(so);

		if (verb) printf("Generating the sample points\n");

		for (i = 0; i < ntps; i++) {
			double out, n;
			so->next(so, tps[i].p);
			out = lookup_func(&fp, tps[i].p);
			if (unif)
				n = d_rand(-0.5 * noise, 0.5 * noise);
			else
				n = noise * 0.25 * 1.2533 * norm_rand();

			tps[i].v[0] = out + n;
//printf("~1 data %d: %f %f %f -> %f, inc noise %f\n", i, tps[i].p[0], tps[i].p[1], tps[i].p[2], out, tps[i].v[0]);

			tnoise += fabs(n);
		}
		tnoise /= (double) ntps;
		if (verb) printf("Measured noise average deviation = %f%%\n",tnoise * 100.0); 

		/* Fit to scattered data */
		if (verb) printf("Fitting the scattered data, smooth = %f, avgdev = %f\n",smooth,avgdev != NULL ? avgdev[0] : 0.0);
		avgdev[0] = 0.25 * noise;
		rss->fit_rspl(rss,
		           flags,				/* Non-mon and clip flags */
		           tps,					/* Test points */
		           ntps,				/* Number of test points */
		           low, high, gres,		/* Low, high, resolution of grid */
		           low, high,			/* Default data scale */
		           smooth,				/* Smoothing to test */
		           avgdev,				/* Average deviation */
		           NULL);				/* iwidth */

		/* Plot out function values */
		if (plot) {
			int slice;
			printf("Black is target, Red is rspl\n");
			for (slice = 0; slice < (di+1); slice++) {
				co tp;	/* Test point */
				double x[PLOTRES];
				double ya[PLOTRES];
				double yb[PLOTRES];
				double yc[PLOTRES];
				double pp[MXDI], p1[MXDI], p2[MXDI], ss[MXDI];
				int n = PLOTRES;

				/* setup slices on each axis at 0.5 and diagonal */
				if (slice < di) {
					for (j = 0; j < di; j++)
						p1[j] = p2[j] = 0.5;
					p1[slice] = 0.0;
					p2[slice] = 1.0;
					printf("Slice along axis %d\n",slice);
				} else {
					for (j = 0; j < di; j++) {
						p1[j] = 0.0;
						p2[j] = 1.0;
					}
					printf("Slice along diagonal\n");
				}

				/* Start point and step increment */
				for (j = 0; j < di; j++) {
					ss[j] = (p2[j] - p1[j])/n;
					pp[j] = p1[j];
				}
				
				for (i = 0; i < n; i++) {
					double vv = i/(n-1.0);
					x[i] = vv;

					/* Reference */
					ya[i] = lookup_func(&fp, pp);

					/* RSPL aproximation */
					for (j = 0; j < di; j++)
						tp.p[j] = pp[j];

					if (rss->interp(rss, &tp))
						tp.v[0] = -0.1;
					yb[i] = tp.v[0];

					/* Crude way of setting the scale: */
					yc[i] = 0.0;
					if (i == (n-1))
						yc[0] = 1.0;

					for (j = 0; j < di; j++)
						pp[j] += ss[j];
				}

				/* Plot the result */
				do_plot(x,ya,yb,yc,n);
			}
		}

		/* Compute statistics */
		rmse = 0.0;
		avge = 0.0;
		maxe = 0.0;
//		so->reset(so);

		/* Fit to scattered data */
		if (verb) printf("Fitting the scattered data\n");
		for (i = 0; i <100000; i++) {
			co tp;	/* Test point */
			double aa, bb, err;

			so->next(so, tp.p);

			/* Reference */
			aa = lookup_func(&fp, tp.p);

			/* RSPL aproximation */
			rss->interp(rss, &tp);
			bb = tp.v[0];

			err = fabs(aa - bb);
			avge += err;
			rmse += err * err;
			if (err > maxe)
				maxe = err;
		}
		avge /= (double)i;
		rmse /= (double)i;

		if (verb)
			printf("Dim %d, res %d, noise %f, points %d, maxerr %f%%, rmserr %f%%, avgerr %f%%\n",
		       di, res, noise, ntps, maxe * 100.0, sqrt(rmse) * 100.0, avge * 100.0);

		*trmse += rmse;
		*tmaxe += maxe;
		*tavge += avge;

		rss->del(rss);
		free(tps);
	}
	so->del(so);

	*trmse = sqrt(*trmse/(double)its);
	*tmaxe /= (double)its;
	*tavge /= (double)its;
}