int main()
{
	assert(seconds_difference(1800.0, 3600.0) == 1800.0);
	assert(seconds_difference(3600.0, 1800.0) == -1800.0);
	assert(seconds_difference(1800.0, 2160.0) == 360.0);
	assert(seconds_difference(1800.0, 1800.0) == 0.0);
}
Exemplo n.º 2
0
 int main()
 {
            
        assert(fabs(seconds_difference(1800.0, 3600.0) - 1800.0) < DBL_EPSILON); 
        assert(fabs(seconds_difference(3600.0, 1800.0) - -1800.0) < DBL_EPSILON );
        assert(fabs(seconds_difference(1800.0, 2160.0) - 360.0) < DBL_EPSILON);
        assert(fabs(seconds_difference(1800.0, 1800.0) -  0.00) < DBL_EPSILON);

        assert(fabs(hours_difference(1800.0, 3600.0) - 0.5) < DBL_EPSILON); 
        assert(fabs(hours_difference(3600.0, 1800.0) - -0.5) < DBL_EPSILON);
        assert(fabs(hours_difference(1800.0, 2160.0) -  0.1) < DBL_EPSILON);
        assert(fabs(hours_difference(1800.0, 1800.0) -  0.0) < DBL_EPSILON);

        assert(fabs(to_float_hours(0, 15, 0) - 0.25) < DBL_EPSILON);
        assert(fabs(to_float_hours(2, 45, 9) - 2.7525) < DBL_EPSILON);
        assert(fabs(to_float_hours(1, 0, 36) - 1.01) < DBL_EPSILON);
        
        assert(fabs(to_24_hour_clock(24) - 0) < DBL_EPSILON);
        assert(fabs(to_24_hour_clock(48) - 0) < DBL_EPSILON);
        assert(fabs(to_24_hour_clock(25) - 1) < DBL_EPSILON);
        assert(fabs(to_24_hour_clock(4) - 4) < DBL_EPSILON);
        assert(fabs(to_24_hour_clock(28.5) - 4.5) < DBL_EPSILON);
        
        assert(fabs(get_hours(3800) - 1) < DBL_EPSILON);
        assert(fabs(get_minutes(3800) - 3) < DBL_EPSILON);
        assert(fabs(get_seconds(3800) - 20) < DBL_EPSILON);

        assert(fabs(time_to_utc(+0, 12.0) - 12.0) < DBL_EPSILON);
        assert(fabs(time_to_utc(+1, 12.0) - 11.0) < DBL_EPSILON);
        assert(fabs(time_to_utc(-1, 12.0) - 13.0) < DBL_EPSILON);
        assert(fabs(time_to_utc(-11, 18.0) - 5.0) < DBL_EPSILON);
        assert(fabs(time_to_utc(-1, 0.0) - 1.0) < DBL_EPSILON);
        assert(fabs(time_to_utc(-1, 23.0) - 0.0) < DBL_EPSILON);

        assert(fabs(time_from_utc(+0, 12.0) - 12.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(+1, 12.0) - 13.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(-1, 12.0) - 11.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(+6, 6.0) - 12.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(-7, 6.0) - 23.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(-1, 0.0) - 23.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(-1, 23.0) - 22.0) < DBL_EPSILON);
        assert(fabs(time_from_utc(+1, 23.0) - 0.0) < DBL_EPSILON);

        return 0;
 }
Exemplo n.º 3
0
int main() {
	assert((seconds_difference(1800.0, 3600.0) - 1800.0 < DBL_EPSILON) && "test-1");
	assert((seconds_difference(3600.0, 1800.0) -( -1800.0) < DBL_EPSILON) && "test-2");
	assert((seconds_difference(1800.0, 2160.0) - 360.0 < DBL_EPSILON) && "test-3");
	assert((seconds_difference(1800.0, 1800.0) < DBL_EPSILON) && "test-4");

	assert((hours_difference(1800.0, 3600.0) - 0.5 < DBL_EPSILON) && "test-5");
	assert((hours_difference(3600.0, 1800.0) -(-0.5) < DBL_EPSILON) && "test-6");
	assert((hours_difference(1800.0, 2160.0) - 0.1 < DBL_EPSILON) && "test-7");
	assert((hours_difference(1800.0, 1800.0) < DBL_EPSILON) && "test-8");

	assert((to_float_hours(0, 15, 0) - 0.25 < DBL_EPSILON) && "test-9");
	assert((to_float_hours(2, 45, 9) - 2.7525 < DBL_EPSILON) && "test-10");
	assert((to_float_hours(1, 0, 36) - 1.01 < DBL_EPSILON) && "test-11");

	assert((to_24_hour_clock(24) < DBL_EPSILON) && "test-12");
	assert((to_24_hour_clock(48) < DBL_EPSILON) && "test-13");
	assert((to_24_hour_clock(25) - 1 < DBL_EPSILON) && "test-14");
	assert((to_24_hour_clock(4) - 4 < DBL_EPSILON) && "test-15");
	assert((to_24_hour_clock(28.5) - 4.5 < DBL_EPSILON) && "test-16");

	assert((get_hours(3800) == 1) && "test-17");
	assert((get_minutes(3800) == 3) && "test-18");
	assert((get_seconds(3800) == 20) && "test-19");

	assert((time_to_utc(0, 12.0) - 12.0 < DBL_EPSILON) && "test-20");
	assert((time_to_utc(1, 12.0) - 11.0 < DBL_EPSILON) && "test-21");
	assert((time_to_utc(-1, 12.0) - 13.0 < DBL_EPSILON) && "test-22");
	assert((time_to_utc(-11, 18.0) - 5.0 < DBL_EPSILON) && "test-23");
	assert((time_to_utc(-1, 0.0) - 1.0 < DBL_EPSILON) && "test-24");
	assert((time_to_utc(-1, 23.0) - 0.0 < DBL_EPSILON) && "test-25");

	assert((time_from_utc(0, 12.0) - 12.0 < DBL_EPSILON) && "test-26");
	assert((time_from_utc(1, 12.0) - 13.0 < DBL_EPSILON) && "test-27");
	assert((time_from_utc(-1, 12.0) - 11.0 < DBL_EPSILON) && "test-28");
	assert((time_from_utc(6, 6.0) - 12.0 < DBL_EPSILON) && "test-29");
	assert((time_from_utc(-7, 6.0) - 23.0 < DBL_EPSILON) && "test-30");
	assert((time_from_utc(-1, 0.0) - 23.0 < DBL_EPSILON) && "test-31");
	assert((time_from_utc(-1, 23.0) - 22.0 < DBL_EPSILON) && "test-32");
	assert((time_from_utc(1, 23.0) < DBL_EPSILON) && "test-33");
}
Exemplo n.º 4
0
double hours_difference(double time_1, double time_2)
{
   return seconds_difference(time_1, time_2) / 3600;
   
}
// ----------------------------------------------------------------- detect
void cupedro_detect(void* cupedro, uint32_t* argb_pixels, int width, int height)
{
  const int n_channels = 3; // always 3 channels
  float transform_time = 0.0, copy_time = 0.0, detect_time = 0.0;
  timespec start_ts, end_ts;
  cupedro_rsrcs& rsrc = *CUPEDRO;

  // No effect if the size is already correct
  rsrc.im_buffer.set_size(width * height * n_channels);

  // We need the image in column-major-RGB-float format
  clock_gettime(CLOCK_REALTIME, &start_ts);
  transform_to_col_major_RBG(argb_pixels, rsrc.im_buffer.ptr(), width, height, n_channels);
  clock_gettime(CLOCK_REALTIME, &end_ts);
  transform_time = seconds_difference(end_ts, start_ts);

  // Deallocate image_col_major_device if it is the wrong size
  if(rsrc.image_col_major_device && (width != rsrc.width || height != rsrc.height)) {
    CudaFelzDetector::deallocateDeviceImage(rsrc.image_col_major_device);
    rsrc.image_col_major_device = NULL;
  }

  // Allocate space for image on GPU if necessary
  if(!rsrc.image_col_major_device) {
    rsrc.image_col_major_device = CudaFelzDetector::allocateDeviceImage(width, height, n_channels);
    rsrc.width = width;
    rsrc.height = height;
    // Pre-allocate detector data structures for given image size -- NOTE must this be done every time
    rsrc.cupedro->initDetector(rsrc.width, rsrc.height);
  }
  
  // Transfer image to GPU
  clock_gettime(CLOCK_REALTIME, &start_ts);
  CudaFelzDetector::copyImageToDevice(rsrc.im_buffer.ptr(), 
						  rsrc.image_col_major_device, width, height);
  clock_gettime(CLOCK_REALTIME, &end_ts);
  copy_time = seconds_difference(end_ts, start_ts);

  // Run detector
  clock_gettime(CLOCK_REALTIME, &start_ts);
  rsrc.cupedro->runDetector(width, height, rsrc.image_col_major_device);
  clock_gettime(CLOCK_REALTIME, &end_ts);
  detect_time = seconds_difference(end_ts, start_ts);

  // Gather results
  int num_results = rsrc.cupedro->getDetectionsCount();
  felz_result* results_host = rsrc.cupedro->getDetections();
  if(!rsrc.quiet) printf("%d detections total in %0.3fs (transform=%0.3fs, copy=%0.3fs, detect=%0.3fs)", num_results, (transform_time + copy_time + detect_time), transform_time, copy_time, detect_time);

  // Need to marshall the number of detects per file before writing them out...
  SmartArray<int> detection_counts(rsrc.model_filenames.size());
  detection_counts.memset(0);
  for(int i=0; i < num_results; ++i) {
    int model_idx = results_host[i].model_idx;
    detection_counts.ptr()[model_idx] += 1;
    const char* detect_name = basename(rsrc.model_filenames[model_idx].c_str());
    
    // Do we need to open a file?
    if(rsrc.outdir.size() > 0 && !rsrc.fptrs[model_idx]) {
	SmartArray<char>& buffer = rsrc.buffer;
	snprintf(buffer.ptr(), buffer.size(), "%s/voc4_%s.boxes", rsrc.outdir.ptr(), detect_name);
	rsrc.fptrs[model_idx] = fopen(buffer.ptr(), "w");
	if(!rsrc.fptrs[model_idx]) {
	  fprintf(stderr, 
		    "Failed to open file %s for writing -- some results will be missing.\n",
		    buffer.ptr());
	} else if(!rsrc.quiet) {
	  printf("Opening boxes file for writing: %s\n", buffer.ptr());
	}
    }
  }

  // Store the number of detections for each model type
  for(int i=0; i < rsrc.model_filenames.size(); ++i) {
    int count = detection_counts.ptr()[i];
    if(rsrc.fptrs[i]) {
	fprintf(rsrc.fptrs[i], "%d\n", count);
    }
    if(!rsrc.quiet) printf("%s%s=%d", (i==0 ? ": " : ", "), cupedro_get_model_name(cupedro, i), count);
    rsrc.results[i].clear();
    rsrc.results[i].reserve(count);
  }

  // Write/store results
  for(int i=0; i < num_results; ++i) {
    int model_idx = results_host[i].model_idx;
    rsrc.results[model_idx].push_back(std::vector<double>());
    // Write out to file
    write_detect_result(rsrc.fptrs[model_idx], results_host[i], 
				cupedro_get_model_name(cupedro, model_idx),
				rsrc.results[model_idx].back());
  }

  // End feedback line
  if(!rsrc.quiet) printf("\n");
}