Example #1
0
static void* at_cmds_loop(void *arg)
{
	unsigned long current, deadline;

	INFO("AT commands thread starting (thread=%d)...\n", (int)pthread_self());

	user_input = MYKONOS_NO_TRIM;
	ocurrent = get_time_ms();
	while (at_thread_alive) {
		if (get_mask_from_state(mykonos_state, MYKONOS_NAVDATA_BOOTSTRAP)) {
			boot_drone(nb_sequence++);
			continue;
		}

//		INFO("Comm_attempt %i\n",mykonos_state);
		// compute next loop iteration deadline
		deadline = get_time_ms() + MYKONOS_REFRESH_MS;

		// send pilot command
		send_command(0);

		// sleep until deadline
		current = get_time_ms();
		if (current < deadline) {
			usleep(1000*(deadline-current));
		}
	}

	INFO("AT commands thread stopping\n");
    return NULL;
}
Example #2
0
void test_mink()
{
  double x[10] = {0, 90, 70, 40, 20, 10, 30, 80, 50, 60};
  int idx[5];

  mink(x, idx, 10, 5);

  printf("idx = [ ");
  int i;
  for (i = 0; i < 5; i++)
    printf("%d ", idx[i]);
  printf("]\n");


  // get timing info
  int n = 100000;
  double y[n];
  for (i = 0; i < n; i++)
    y[i] = normrand(0,1);
  int yi[n];

  double t = get_time_ms();
  sort_indices(y, yi, n);
  printf("sorted %d numbers in %f ms\n", n, get_time_ms() - t);
  
  t = get_time_ms();
  mink(y, yi, n, 100);
  printf("got the min %d numbers in %f ms\n", 100, get_time_ms() - t);
}
Example #3
0
void test_bingham_sample_pmf(int argc, char *argv[])
{
  if (argc < 6) {
    printf("usage: %s <z1> <z2> <z3> <num_cells> <num_samples>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);
  int ncells = atoi(argv[4]);
  int nsamples = atoi(argv[5]);

  double Z[3] = {z1, z2, z3};
  double V[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};

  bingham_t B;
  bingham_new(&B, 4, Vp, Z);

  bingham_pmf_t pmf;
  double t0 = get_time_ms();
  bingham_discretize(&pmf, &B, ncells);
  printf("Created PMF with %d cells in %.0f ms\n", pmf.n, get_time_ms() - t0);

  t0 = get_time_ms();
  double **X = new_matrix2(nsamples, 4);
  bingham_sample_pmf(X, &pmf, nsamples);
  printf("Sampled %d points in %.0f ms\n", nsamples, get_time_ms() - t0);

  bingham_fit(&B, X, nsamples, 4);

  print_bingham(&B);
}
Example #4
0
static void
pandora_update()
{
    static unsigned int last_time;
    unsigned int now;
    GLES_Data* data = G_Data;

    if (data->eglDisplay!=EGL_NO_DISPLAY && data->eglSurface!=EGL_NO_SURFACE)
    {
        eglSwapBuffers(data->eglDisplay, data->eglSurface);
        now = get_time_ms();

        if (data->fbdev >= 0 && now - last_time < 16)
        {
            int arg = 0;
            ioctl( data->fbdev, FBIO_WAITFORVSYNC, &arg );
        }

        last_time = get_time_ms();

       // GLES_TestError("eglSwapBuffers");
#ifdef APKENV_DEBUG
        // printf("%d swap\n",pthread_self());
#endif
    }
}
Example #5
0
void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
{
	unsigned int i = 0;
	unsigned long long stop_time = 0;
	int cont = 1;

	tst_test = self;
	TCID = tst_test->tid;

	do_setup(argc, argv);

	if (duration > 0)
		stop_time = get_time_ms() + (unsigned long long)(duration * 1000);

	for (;;) {
		cont = 0;

		if (i < (unsigned int)iterations) {
			i++;
			cont = 1;
		}

		if (stop_time && get_time_ms() < stop_time)
			cont = 1;

		if (!cont)
			break;

		run_tests();
	}

	do_cleanup();
	do_exit();
}
Example #6
0
static idevice_error_t idevice_connection_receive_all(idevice_connection_t connection, char * data, uint32_t length, unsigned int timeout)
{
    size_t cur_bytes_received = 0;
    size_t total_bytes_received = 0;
    size_t bytes_left = length;
    idevice_error_t res = IDEVICE_E_SUCCESS;

    uint64_t start_time = get_time_ms();
    uint64_t time_passed = 0;
    while ((total_bytes_received < length) && (time_passed <= timeout)) {
        res = idevice_connection_receive_timeout(connection,
                data + total_bytes_received,
                bytes_left,
                &cur_bytes_received,
                timeout - (unsigned int)time_passed);
        if (IDEVICE_E_SUCCESS != res) {
            error("ERROR: Unable to receive data\n");
            break;
        }

        total_bytes_received += cur_bytes_received;
        bytes_left -= cur_bytes_received;

        time_passed = get_time_ms() - start_time;
    }

    /* Check if we've failed to receive the requested amount of data */
    if ((IDEVICE_E_SUCCESS == res) && (total_bytes_received < length)) {
        /* Timeout */
        return IDEVICE_E_NOT_ENOUGH_DATA;
    }

    return res;
}
Example #7
0
static void testrun(void)
{
	unsigned int i = 0;
	unsigned long long stop_time = 0;
	int cont = 1;

	add_paths();
	do_test_setup();

	if (duration > 0)
		stop_time = get_time_ms() + (unsigned long long)(duration * 1000);

	for (;;) {
		cont = 0;

		if (i < (unsigned int)iterations) {
			i++;
			cont = 1;
		}

		if (stop_time && get_time_ms() < stop_time)
			cont = 1;

		if (!cont)
			break;

		run_tests();
		heartbeat();
	}

	do_test_cleanup();
	exit(0);
}
Example #8
0
void test_bingham_sample_ridge(int argc, char *argv[])
{
  if (argc < 6) {
    printf("usage: %s <z1> <z2> <z3> <num_samples> <pthresh>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);
  int nsamples = atoi(argv[4]);
  double pthresh = atof(argv[5]);

  double Z[3] = {z1, z2, z3};
  double V[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};

  bingham_t B;
  bingham_new(&B, 4, Vp, Z);
  //printf("B.F = %f\n", B.F);

  double t0 = get_time_ms();
  double **X = new_matrix2(nsamples, 4);
  bingham_sample_ridge(X, &B, nsamples, pthresh);
  printf("Sampled %d points in %.0f ms\n", nsamples, get_time_ms() - t0);

  //printf("X = [ ...\n");
  //int i;
  //for (i = 0; i < nsamples; i++) {
  //  printf("%f, %f, %f, %f ; ...\n", X[i][0], X[i][1], X[i][2], X[i][3]);
  //}
  //printf("];\n\n");
}
Example #9
0
int main(int argc, char **argv)
{

	printf("system time %lldms\n", get_time_ms());
	sleep(1);
	printf("system tmie %lldms\n", get_time_ms());
	
	
}
Example #10
0
void test_bingham_discretize(int argc, char *argv[])
{
  if (argc < 5) {
    printf("usage: %s <z1> <z2> <z3> <ncells>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);
  int ncells = atoi(argv[4]);

  double Z[3] = {z1, z2, z3};
  double V[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};

  bingham_t B;
  bingham_new(&B, 4, Vp, Z);

  bingham_pmf_t pmf;
  bingham_discretize(&pmf, &B, ncells);

  // check if pmf sums to 1
  //double tot_mass = sum(pmf.mass, pmf.n);
  //printf("tot_mass = %f\n", tot_mass);

  int i;

  //printf("break 1\n");
  int *colors; safe_malloc(colors, pmf.n, int);
  //printf("break 2\n");

  double max_mass = arr_max(pmf.mass, pmf.n);
  for (i = 0; i < pmf.n; i++)
    colors[i] = (int)(255*(pmf.mass[i] / max_mass));

  //printf("Calling tetramesh_meshgraph()...");
  double t = get_time_ms();
  meshgraph_t *graph = tetramesh_meshgraph(pmf.tessellation->tetramesh);
  //printf("%f ms\n", get_time_ms() - t);

  //printf("Calling tetramesh_graph()...");
  t = get_time_ms();
  tetramesh_graph(pmf.tessellation->tetramesh);
  //printf("%f ms\n", get_time_ms() - t);

  //printf("Calling tetramesh_save_PLY_colors()...\n");

  //tetramesh_save_PLY_colors(pmf.tessellation->tetramesh, graph, "mesh.ply", colors);
  tetramesh_save_PLY(pmf.tessellation->tetramesh, graph, "mesh.ply");

  // print out the points
  //printf("pmf.points = [ ");
  //for (i = 0; i < pmf.n; i++)
  //  printf("%f %f %f %f ; ", pmf.points[i][0], pmf.points[i][1], pmf.points[i][2], pmf.points[i][3]);
  //printf("];\n");
}
Example #11
0
void test_bingham_sample(int argc, char *argv[])
{
  if (argc < 5) {
    printf("usage: %s <z1> <z2> <z3> <num_samples>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);
  int nsamples = atoi(argv[4]);

  double Z[3] = {z1, z2, z3};
  double V[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};

  bingham_t B;
  bingham_new(&B, 4, Vp, Z);
  print_bingham(&B);

  printf("---------------------------\n");

  bingham_stats(&B);

  printf("Original scatter matrix:\n");
  int i, j, d=4;
  for (i = 0; i < d; i++) {
    for (j = 0; j < d; j++)
      printf("%.4f, ", B.stats->scatter[i][j]);
    printf("\n");
  }

  double t0 = get_time_ms();
  double **X = new_matrix2(nsamples, 4);
  bingham_sample(X, &B, nsamples);
  printf("Sampled %d points in %.0f ms\n", nsamples, get_time_ms() - t0);

  bingham_fit(&B, X, nsamples, 4);

  print_bingham(&B);

  int n = nsamples;
  double **Xt = new_matrix2(d, n);
  transpose(Xt, X, n, d);
  double **S = new_matrix2(d, d);
  matrix_mult(S, Xt, X, d, n, d);
  mult(S[0], S[0], 1/(double)n, d*d);

  printf("Sample scatter matrix:\n");
  for (i = 0; i < d; i++) {
    for (j = 0; j < d; j++)
      printf("%.4f, ", S[i][j]);
    printf("\n");
  }

}
Example #12
0
void test_time()
{
    ulong t2, t1 = get_time_ms();

    sleep_msec(1234); /* don't remove 1234, cause it tests overflow of tv.tv_nsec */
    t2 = get_time_ms() - t1;

    assert(t2 >= 1234);
    fprintf(stdout, "%s:\tpassed\n", __FUNCTION__);
}
Example #13
0
void test_bingham_init()
{
  double t0 = get_time_ms();

  bingham_init();

  double t1 = get_time_ms();

  fprintf(stderr, "Initialized bingham library in %.0f ms\n", t1-t0);
}
Example #14
0
void test_bingham_mult(int argc, char *argv[])
{
  if (argc < 7) {
    printf("usage: %s <z11> <z12> <z13> <z21> <z22> <z23> \n", argv[0]);
    exit(1);
  }

  double z11 = atof(argv[1]);
  double z12 = atof(argv[2]);
  double z13 = atof(argv[3]);
  double z21 = atof(argv[4]);
  double z22 = atof(argv[5]);
  double z23 = atof(argv[6]);
 
  double Z1[3] = {z11, z12, z13};
  double V1[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp1[3] = {&V1[0][0], &V1[1][0], &V1[2][0]};
  bingham_t B1;
  B1.d = 4;
  B1.Z = Z1;
  B1.V = Vp1;
  //bingham_new(&B1, 4, Vp1, Z1);

  double Z2[3] = {z21, z22, z23};
  double V2[3][4] = {{0,1,0,0}, {0,0,1,0}, {0,0,0,1}};
  //double V2[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp2[3] = {&V2[0][0], &V2[1][0], &V2[2][0]};
  bingham_t B2;
  B2.d = 4;
  B2.Z = Z2;
  B2.V = Vp2;
  //bingham_new(&B2, 4, Vp2, Z2);

  double Z[3];
  double V[3][4];
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};
  bingham_t B;
  B.Z = Z;
  B.V = Vp;
  //bingham_new(&B, 4, Vp, Z);

  double t0 = get_time_ms();
  int i, n=10000;
  for (i = 0; i < n; i++)
    bingham_mult(&B, &B1, &B2);
  double t1 = get_time_ms();
  printf("Performed %d same Bingham multiplications in %.0f ms\n", n, t1-t0);

  printf("B.F = %f\n", B.F);
  printf("B.Z = [%f %f %f]\n", B.Z[0], B.Z[1], B.Z[2]);
  printf("B.V[0] = [%f %f %f %f]\n", B.V[0][0], B.V[0][1], B.V[0][2], B.V[0][3]);
  printf("B.V[1] = [%f %f %f %f]\n", B.V[1][0], B.V[1][1], B.V[1][2], B.V[1][3]);
  printf("B.V[2] = [%f %f %f %f]\n", B.V[2][0], B.V[2][1], B.V[2][2], B.V[2][3]);
}
Example #15
0
File: pause.c Project: cran/profvis
SEXP profvis_pause (SEXP seconds) {
  if (TYPEOF(seconds) != REALSXP)
    error("`seconds` must be a numeric");

  double start = get_time_ms();
  double sec = asReal(seconds);

  while(get_time_ms() - start < sec) {
    R_CheckUserInterrupt();
  }

  return R_NilValue;
}
Example #16
0
int main(int argc, char *argv[])
{
  double t0 = get_time_ms();
  bingham_init();
  double t1 = get_time_ms();
  fprintf(stderr, "Initialized bingham library in %.0f ms\n", t1-t0);

  if (argc < 3)
    usage(argc, argv);

  int load_scatter = 0;
  if (argc >= 4) {
    if (!strcmp(argv[1], "-s"))
      load_scatter = 1;
    else
      usage(argc, argv);
  }

  char *fin = (load_scatter ? argv[2] : argv[1]);
  char *fout = (load_scatter ? argv[3] : argv[2]);

  int n, d;
  bingham_mix_t BM;

  if (load_scatter) {
    double **S = load_matrix(fin, &n, &d);
    if (n == d) {
      bingham_t B;
      bingham_fit_scatter(&B, S, d);
      double w = 1.0;
      BM.B = &B;
      BM.w = &w;
      BM.n = 1;
    }
    else if (n > d) {  // fit multiple scatter matrices
      BM.n = n/d;
      safe_calloc(BM.B, BM.n, bingham_t);
      safe_calloc(BM.w, BM.n, double);
      int i;
      for (i = 0; i < BM.n; i++) {
	if (norm(S[d*i], d*d) < .00001)  // S = [0]  -->  uniform
	  bingham_new_uniform(&BM.B[i], d);
	else
	  bingham_fit_scatter(&BM.B[i], &S[d*i], d);
	BM.w[i] = 1;
      }
    }
  }
Example #17
0
static void* at_cmds_loop(void *arg)
{
  
  INFO("AT commands thread starting (thread=%d)...\n", (int)pthread_self());
  
  user_input = MYKONOS_NO_TRIM;
  ocurrent = get_time_ms();
  
  while (at_thread_alive) {
    
    if (get_mask_from_state(mykonos_state, ARDRONE_NAVDATA_BOOTSTRAP)) {
      INFO("attempting to boot drone...\n");
      boot_drone();
      nb_sequence = 0;
      continue;
    }
    
    send_command( nb_sequence++ );
    
    // sleep until deadline
    usleep(200 * 1000);

  }
  
  INFO("AT commands thread stopping\n");
  return NULL;
}
Example #18
0
namespace TimeManager
{
	unsigned long g_last_time = get_time_ms(); // ms
	unsigned long g_last_steptime = 0; // ms

	unsigned long get_time_ms() // ms
	{
#if defined WIN32
		return ( unsigned long ) timeGetTime();
#else
		struct timeval tv;
		struct timezone tz;
		gettimeofday ( &tv, &tz );
		unsigned long time_ms = ( tv.tv_sec * 1000 ) + ( tv.tv_usec / 1000 );
		return time_ms;
#endif
	}

	void update_steptime()
	{
		unsigned long new_time = get_time_ms();
		g_last_steptime = ( new_time > g_last_time ) ? ( new_time - g_last_time ) : 0;
		g_last_time = new_time;
	}

	void sleep ( unsigned long sleep_time )
	{
#if defined WIN32
		::Sleep ( sleep_time );
#else
		::usleep ( ( useconds_t ) ( sleep_time * 1000 ) );
#endif
	}
}
Example #19
0
static void send_command(int nab_sequence)
{
	unsigned long current;

	// send command to drone
	current = get_time_ms();

	pthread_mutex_lock( &at_cmd_lock );
    snprintf(str, AT_BUFFER_SIZE, "AT*PCMD=%d,%d,%d,%d,%d,%d\r",nb_sequence++,*(int*)&radiogp_cmd.hover,*(int*)&radiogp_cmd.pitch,*(int*)&radiogp_cmd.roll,*(int*)&radiogp_cmd.gaz,*(int*)&radiogp_cmd.yaw);
	pthread_mutex_unlock( &at_cmd_lock );
	at_write((int8_t*)str, strlen (str));

/*	pthread_mutex_lock( &at_cmd_lock );
	snprintf(str,AT_BUFFER_SIZE,"AT*COMWDG=%i\r",nb_sequence++);
	pthread_mutex_unlock( &at_cmd_lock );
	at_write((int8_t*)str, strlen (str));*/
	//snprintf(str,AT_BUFFER_SIZE,"AT*COMWDG=%i\r",nb_sequence);


	// check 30 ms overflow
	if (current > ocurrent + 30) {
		overflow += current - ocurrent - MYKONOS_REFRESH_MS;
	}
	ocurrent = current;

	/* dump command every 2s */
	if ((nb_sequence & 63) == 0) {
		pthread_mutex_lock( &at_cmd_lock );
		//INFO("seq=%d radgp(%f,%f,%f,%f) ui=0x%08x over=%d\n", nb_sequence,radiogp_cmd.pitch, radiogp_cmd.roll, radiogp_cmd.gaz, radiogp_cmd.yaw, user_input, overflow);
		pthread_mutex_unlock( &at_cmd_lock );
		overflow = 0;
	}
}
Example #20
0
void chrono_lap_button() {
  unsigned int ms;
 
  ms = get_time_ms();

  if (chrono_data.lap_paused) {
    // If we were already paused, this resumes the motion, jumping
    // ahead to the currently elapsed time.
    chrono_data.lap_paused = false;
    vibes_enqueue_custom_pattern(tap);
    update_hands(NULL);
  } else {
    // If we were not already paused, this pauses the hands here (but
    // does not stop the timer).
    unsigned int lap_ms = ms - chrono_data.start_ms;
    record_chrono_lap(lap_ms);
    if (!chrono_digital_window_showing) {
      // Actually, we only pause the hands if we're not looking at the
      // digital timer.
      chrono_data.hold_ms = lap_ms;
      chrono_data.lap_paused = true;
    }
    vibes_enqueue_custom_pattern(tap);
    update_hands(NULL);
  }
}
Example #21
0
/*
 * Pre-cache some tessellations of hyperspheres.
 */
void hypersphere_init()
{
    double t0 = get_time_ms();

    int i;
    const int levels = 5; //7;

    memset(tessellations, 0, MAX_LEVELS*sizeof(hypersphere_tessellation_t));

    for (i = 0; i < levels; i++) {
        octetramesh_t *mesh = build_octetra(i);
        octetramesh_to_tessellation(&tessellations[i], mesh);
    }

    fprintf(stderr, "Initialized %d hypersphere tessellations (up to %d cells) in %.0f ms\n",
            levels, tessellations[levels-1].n, get_time_ms() - t0);
}
Example #22
0
void test_bingham_stats(int argc, char *argv[])
{
  if (argc < 4) {
    printf("usage: %s <z1> <z2> <z3>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);

  double Z[3] = {z1, z2, z3};
  double V[3][4] = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}};
  double *Vp[3] = {&V[0][0], &V[1][0], &V[2][0]};

  bingham_t B;
  bingham_new(&B, 4, Vp, Z);

  print_bingham(&B);

  int i, j, n = 1; //1000000;
  double t0 = get_time_ms();
  for (i = 0; i < n; i++)
    bingham_stats(&B);
  printf("Computed stats %d times in %.0f ms\n", n, get_time_ms() - t0);

  printf("B.stats->mode = [ %f %f %f %f ]\n", B.stats->mode[0], B.stats->mode[1], B.stats->mode[2], B.stats->mode[3]);
  printf("B.stats->dF = [ %f %f %f ]\n", B.stats->dF[0], B.stats->dF[1], B.stats->dF[2]);
  printf("B.stats->entropy = %f\n", B.stats->entropy);
  for (i = 0; i < B.d; i++) {
    printf("B.stats->scatter[%d] = [ ", i);
    for (j = 0; j < B.d; j++)
      printf("%f ", B.stats->scatter[i][j]);
    printf("]\n");
  }

  int yi = 9;
  printf("bingham_F_table[%d][%d][%d] = %f\n", yi, yi, yi, bingham_F_table_get(yi,yi,yi));
  printf("bingham_dF1_table[%d][%d][%d] = %f\n", yi, yi, yi, bingham_dF1_table_get(yi,yi,yi));
  printf("bingham_dF2_table[%d][%d][%d] = %f\n", yi, yi, yi, bingham_dF2_table_get(yi,yi,yi));
  printf("bingham_dF3_table[%d][%d][%d] = %f\n", yi, yi, yi, bingham_dF3_table_get(yi,yi,yi));

  bingham_fit_scatter(&B, B.stats->scatter, B.d);

  print_bingham(&B);
}
Example #23
0
void test_bingham_F_lookup_3d(int argc, char *argv[])
{
  if (argc < 4) {
    printf("usage: %s <z1> <z2> <z3>\n", argv[0]);
    exit(1);
  }

  double z1 = atof(argv[1]);
  double z2 = atof(argv[2]);
  double z3 = atof(argv[3]);

  double Z[3] = {z1, z2, z3};

  double t0 = get_time_ms();
  int i, n=1000000;
  for (i = 0; i < n; i++)
    bingham_F_lookup_3d(Z);
  double t1 = get_time_ms();
  printf("Performed %d same F-lookups in %.0f ms\n", n, t1-t0);

  t0 = get_time_ms();
  int j, k, m=200;
  n=0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= i; j++) {
      for (k = 1; k <= j; k++) {
	Z[0] = -i;
	Z[1] = -j;
	Z[2] = -k;
	bingham_F_lookup_3d(Z);
	n++;
      }
    }
  }
  t1 = get_time_ms();
  printf("Performed %d unique F-lookups in %.0f ms\n", n, t1-t0);



  //double F_interp = bingham_F_lookup_3d(Z);
  //double F_series = bingham_F_3d(z1, z2, z3);
  //double error = F_interp - F_series;

  //printf("\nF_interp = %f, F_series = %f, error = %f\n\n", F_interp, F_series, error);
}
Example #24
0
int main(int argc, char *argv[])
{
  double t0 = get_time_ms();
  bingham_init();
  double t1 = get_time_ms();
  fprintf(stderr, "Initialized bingham library in %.0f ms\n", t1-t0);

  if (argc < 2)
    usage(argc, argv);

  char *filename = argv[1];

  int n, d, i, j, c;
  double **X = load_data(filename, &n, &d);

  bingham_mix_t BM;
  bingham_cluster(&BM, X, n, d);

  printf("B_num = %d\n\n", BM.n);
  printf("B_weights = [ ");
  for (c = 0; c < BM.n; c++)
    printf("%f ", BM.w[c]);
  printf("]\n\n");

  for (c = 0; c < BM.n; c++) {
    printf("B(%d).V = [ ", c+1);
    for (i = 0; i < d; i++) {
      for (j = 0; j < d-1; j++)
  printf("%f ", BM.B[c].V[j][i]);
      printf("; ");
    }
    printf("];\n\n");

    printf("B(%d).Z = [ ", c+1);
    for (i = 0; i < d-1; i++)
      printf("%f ", BM.B[c].Z[i]);
    printf("];\n\n");

    printf("B(%d).F = %f;\n\n", c+1, BM.B[c].F);
  }

  save_bmx(&BM, 1, argv[2]);

  return 0;
}
Example #25
0
/* printf with a timestamp */
static void ts_printf(const char *fmt, ...)
{
	va_list ap;

	printf("%d: ", get_time_ms());
	va_start(ap, fmt);
	vfprintf(stdout, fmt, ap);
	va_end(ap);
}
Example #26
0
svc_client_handle_t * cproxy_connect(int service_id,
		void(*cb)(struct cfw_message *, void*), void *data)
{
	svc_client_handle_t *sh = NULL;
	/* Allocate a service handle structure */
	struct _svc_cnx *cnx = balloc(sizeof(*cnx), NULL);
	cnx->cb = cb;
	cnx->data = data;
	cnx->sh = NULL;
	cnx->src_port = 0;
	cnx->service_id = service_id;
	cfw_register_svc_available(_proxy_handle, cnx->service_id, cnx);
	uint32_t start = get_time_ms();
	while (!(sh = cnx->sh) && (get_time_ms() < (start + 100))) {
		queue_process_message(_queue);
	}
	return sh;
}
Example #27
0
long CTimerCpu::get_time_sec(){
#ifndef USE_CUSTOM_TIMER
    return get_time_ms() / 1000;
#else
    if( isRunning == true ){
        clock_gettime(CLOCK_MONOTONIC, &t_stop);
    }
    return diff_sec( t_start, t_stop );
#endif    
}
Example #28
0
inline void print_progress (int csol, arraylist_t &solutions, arraylist_t &extensions, double Tstart, colindex_t col) {
        time_t seconds;
        struct tm *tminfo;

        time (&seconds);
        tminfo = localtime (&seconds);
        log_print (QUIET, "Extending column %d of array %i/%i ~ %4.1f%% (total collected %d), time %.2f s, %s",
                   col + 1, csol, (int)solutions.size (), 100.0 * ((float)csol) / (float)solutions.size (),
                   (int)extensions.size (), (get_time_ms () - Tstart), asctime (tminfo));
}
Example #29
0
/**
 * Silly little helper function, determines if the caller needs a visual update
 * since the last time this function was called.
 * This is made for the two progress bar functions, to prevent flicker.
 * @param first_call 1 on first call for initialization purposes, 0 otherwise
 * @return number of milliseconds since last call
 */
static int64_t get_update_timediff(int first_call)
{
	int64_t retval = 0;
	static int64_t last_time = 0;

	/* on first call, simply set the last time and return */
	if(first_call) {
		last_time = get_time_ms();
	} else {
		int64_t this_time = get_time_ms();
		retval = this_time - last_time;

		/* do not update last_time if interval was too short */
		if(retval < 0 || retval >= UPDATE_SPEED_MS) {
			last_time = this_time;
		}
	}

	return retval;
}
Example #30
0
void change_zoom_and_turn_off_zoom_mode(xy_t pos, double zoom_scale)
{
	zc.offset_u = pos;
	zc.zoomscale = zoom_scale;
	zc.zoom_key_time = get_time_ms();

	if (mouse.zoom_flag)
		zoom_key_released(&zc, &mouse.zoom_flag, 1);

	calc_screen_limits(&zc);
}