Exemplo n.º 1
0
TEST(wt , quantile)
{
    uint64_t* T = (uint64_t*) malloc(4*sizeof(uint64_t));
    wt_setsym(T,6,0,7);
    wt_setsym(T,6,1,2);
    wt_setsym(T,6,2,13);
    wt_setsym(T,6,3,12);
    wt_setsym(T,6,4,9);
    wt_setsym(T,6,5,11);
    wt_setsym(T,6,6,15);
    wt_setsym(T,6,7,14);
    wt_setsym(T,6,8,17);
    wt_setsym(T,6,9,3);
    wt_setsym(T,6,10,8);
    wt_setsym(T,6,11,10);
    wt_setsym(T,6,12,11);
    wt_setsym(T,6,13,1);
    wt_setsym(T,6,14,18);
    wt_setsym(T,6,15,5);
    wt_setsym(T,6,16,6);
    wt_setsym(T,6,17,4);
    wt_setsym(T,6,18,16);

    wt_t* wt = wt_create(T,6,20,4);

    CHECK(wt_quantile(wt,8,13,1) == 1);
    CHECK(wt_quantile(wt,8,13,2) == 3);
    CHECK(wt_quantile(wt,8,13,3) == 8);
    CHECK(wt_quantile(wt,8,13,4) == 10);
    CHECK(wt_quantile(wt,8,13,5) == 11);
    CHECK(wt_quantile(wt,8,13,6) == 17);

    wt_free(wt);
}
Exemplo n.º 2
0
TEST(wt , saveload)
{
    size_t n,i,j;
    uint8_t* T = init_TRand(&n);
    uint8_t* Tcopy = (uint8_t*) malloc(n);
    memcpy(Tcopy,T,n);

    FILE* f = fopen("wt.test","w");

    wt_t* wt = wt_create((uint64_t*)T,8,n,4);
    wt_save(wt,f);
    fclose(f);

    f = fopen("wt.test","r");
    wt_t* wtl = wt_load(f);
    fclose(f);

    /* select test */
    for (i=0; i<200; i++) {
        size_t pos = rand() % n;
        size_t sym = Tcopy[pos];
        size_t cnt = 0;
        for (j=0; j<=pos; j++) if (Tcopy[j]==sym) cnt++;
        CHECK(wt_select(wt,sym,cnt) == wt_select(wtl,sym,cnt));
    }

    /* access */
    for (i=0; i<n; i++) {
        CHECK(wt_access(wt,i) == Tcopy[i]);
    }

    /* rank */
    for (i=0; i<200; i++) {
        size_t pos = rand() % n;
        for (j=0; j<255; j++) {
            CHECK(wt_rank(wt,j,pos) == wt_rank(wtl,j,pos));
        }
    }

    remove("wt.test");
    wt_free(wt);
    wt_free(wtl);
    free(Tcopy);
}
Exemplo n.º 3
0
/* 
 * Free all memory used by a WaveFile
 */
void
wf_free(WaveFile *wf)
{
	int i;
	WvTable *wt;
	for(i = 0; i < wf->tables->len; i++) {
		wt = wf_wtable(wf, i);
		wt_free(wt);
	}
	g_ptr_array_free(wf->tables, 0);
	ss_delete(wf->ss);
	g_free(wf);
}
Exemplo n.º 4
0
TEST(wt , access)
{
    size_t n,i;
    uint8_t* T = init_T(&n);
    wt_t* wt = wt_create((uint64_t*)T,8,n,4);

    for (i=0; i<n; i++) {
        CHECK(wt_access(wt,i) == (i%8));
    }

    wt_free(wt);

    T = init_TRand(&n);
    uint8_t* Tcopy = (uint8_t*) malloc(n);
    memcpy(Tcopy,T,n);
    wt = wt_create((uint64_t*)T,8,n,4);

    for (i=0; i<n; i++) {
        CHECK(wt_access(wt,i) == Tcopy[i]);
    }

    wt_free(wt);
    free(Tcopy);
}
Exemplo n.º 5
0
TEST(wt , select)
{
    size_t n,i,j;
    uint8_t* T = init_TRand(&n);
    uint8_t* Tcopy = (uint8_t*) malloc(n);
    memcpy(Tcopy,T,n);

    wt_t* wt = wt_create((uint64_t*)T,8,n,4);

    for (i=0; i<200; i++) {
        size_t pos = rand() % n;
        size_t sym = Tcopy[pos];
        size_t cnt = 0;
        for (j=0; j<=pos; j++) if (Tcopy[j]==sym) cnt++;
        CHECK(wt_select(wt,sym,cnt) == pos);
    }

    wt_free(wt);
    free(Tcopy);
}
Exemplo n.º 6
0
__USER_API__ void tch_free(void* ptr){
	if(!ptr)
		return;
	int result;
	if(WT_OK == (result = wt_cacheFree(current->cache,ptr)))
		return;
	if(result == WT_ERROR)
		goto ERR_HEAP_FREE;
	tch_mtxId mtx = current->mtx;
	if(Mtx->lock(mtx,tchWaitForever) != tchOK)
		return;
	result = wt_free(current->heap,ptr);
	Mtx->unlock(mtx);
	if(result == WT_ERROR)
		goto ERR_HEAP_FREE;
	return;

ERR_HEAP_FREE :
	tch_kernel_onSoftException(current,tchErrorHeapCorruption,"heap corrupted");
}
Exemplo n.º 7
0
TEST(wt , rank)
{
    size_t n,i,j;
    uint8_t* T = init_TRand(&n);
    uint8_t* Tcopy = (uint8_t*) malloc(n);
    memcpy(Tcopy,T,n);

    wt_t* wt = wt_create((uint64_t*)T,8,n,4);

    for (i=0; i<200; i++) {
        size_t pos = rand() % n;
        size_t count[256] = {0};
        for (j=0; j<=pos; j++) count[ Tcopy[j] ]++;
        for (j=0; j<255; j++) {
            CHECK(wt_rank(wt,j,pos) == count[j]);
        }
    }

    wt_free(wt);
    free(Tcopy);
}
Exemplo n.º 8
0
TEST(wt , mostfrequent)
{
    uint64_t* T = (uint64_t*) malloc(4*sizeof(uint64_t));
    wt_setsym(T,6,0,7);
    wt_setsym(T,6,1,2);
    wt_setsym(T,6,2,2);
    wt_setsym(T,6,3,4);
    wt_setsym(T,6,4,7);
    wt_setsym(T,6,5,4);
    wt_setsym(T,6,6,6);
    wt_setsym(T,6,7,7);
    wt_setsym(T,6,8,3);
    wt_setsym(T,6,9,6);
    wt_setsym(T,6,10,7);
    wt_setsym(T,6,11,4);
    wt_setsym(T,6,12,6);
    wt_setsym(T,6,13,5);
    wt_setsym(T,6,14,18);
    wt_setsym(T,6,15,7);
    wt_setsym(T,6,16,4);
    wt_setsym(T,6,17,2);
    wt_setsym(T,6,18,1);

    wt_t* wt = wt_create(T,6,20,4);

    wt_result_t* res = wt_mostfrequent(wt,0,18,2);

    CHECK(res->m == 2);
    CHECK(res->items[0].sym == 7);
    CHECK(res->items[1].sym == 4);
    CHECK(res->items[0].freq == 5);
    CHECK(res->items[1].freq == 4);

    wt_freeresult(res);

    wt_free(wt);
}
Exemplo n.º 9
0
/* Free any object in a handlenode */
void object_free(struct handlenode *n) {
#ifdef DEBUG_KEYS
  num_handles--;
#endif
#ifdef DEBUG_MEMORY
  printf("Enter object free of handle 0x%08X, type %d\n",n->id,n->type &
	 PG_TYPEMASK);
#endif
  if (!(n->type & HFLAG_NFREE)) {
    switch (n->type & PG_TYPEMASK) {

    case PG_TYPE_BITMAP:
      VID(bitmap_free) ((hwrbitmap)n->obj);
      break;

    case PG_TYPE_WIDGET:
      widget_remove((struct widget *)n->obj);
      break;

    case PG_TYPE_THEME:
      theme_remove((struct pgmemtheme *)n->obj);
      break;

    case PG_TYPE_DRIVER:
      unload_inlib((struct inlib *)n->obj);
      break;

    case PG_TYPE_WT:
      wt_free((struct pgmemwt *)n->obj);
      break;

    case PG_TYPE_INFILTER:
      infilter_delete((struct infilter *)n->obj);
      break;

    case PG_TYPE_CURSOR:
      cursor_delete((struct cursor *)n->obj);
      break;

    case PG_TYPE_PGSTRING:
      pgstring_delete((struct pgstring *)n->obj);
      break;

    case PG_TYPE_FONTDESC:
      font_descriptor_destroy((struct font_descriptor *)n->obj);
      break;

      /* Object types that are memory-managed independently of their handles */
    case PG_TYPE_DIVTREE:
    case PG_TYPE_PARAGRAPH:
      break;

    default:
      g_free(n->obj);
    }
  }
#ifdef DEBUG_MEMORY
  printf("Leave object free of handle 0x%08X, type %d\n",n->id,n->type &
	 PG_TYPEMASK);
#endif
}
Exemplo n.º 10
0
int main() {
	wave_object obj;
	wt_object wt;
	double *inp,*out,*diff;
	int N, i,J;

	FILE *ifp;
	double temp[1200];

	char *name = "db4";
	obj = wave_init(name);// Initialize the wavelet

	ifp = fopen(FILE_SIGNAL, "r");
	i = 0;
	if (!ifp) {
		printf("Cannot Open File");
		exit(100);
	}
	while (!feof(ifp)) {
		fscanf(ifp, "%lf \n", &temp[i]);
		i++;
	}
	N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	diff = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
		inp[i] = temp[i];
		//printf("%g \n",inp[i]);
	}
	J = 3;

	wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
	setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
	setWTConv(wt, "direct");
	
	dwt(wt, inp);// Perform DWT
	//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
	
	for (i = 0; i < wt->outlength; ++i) {
	//	printf("%g ",wt->output[i]);
	}
	
	idwt(wt, out);// Perform IDWT (if needed)
	// Test Reconstruction
	for (i = 0; i < wt->siglength; ++i) {
		diff[i] = out[i] - inp[i];
	}
	
	printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
	
	wt_summary(wt);// Prints the full summary.
	wave_free(obj);
	wt_free(wt);

	free(inp);
	free(out);
	free(diff);
	return 0;
}
Exemplo n.º 11
0
/*
 * read data for a single table (sweep or segment) from spicestream.
 * on entry:
 *	state=0: no previous data; dvals is allocated but garbage
 *	state=1: first row of data is in *ivalp, and vals[].
 * on exit:
 *	return NULL: fatal error, *statep=-1
 *	return non-NULL: valid wvtable*
 *
 *	state=-1 fatal error
 *	state=0: successful completion of reading whole file
 * 	state=1:  finished table but more tables remain,
 *			none of the next table has yet been read
 * 	state=2:  finished table but more tables remain and
 *		*ivalp,dvals[] contain first row of next table.
 */
WvTable *
wf_read_table(SpiceStream *ss, WaveFile *wf,
	      int *statep, double *ivalp, double *dvals)
{
	WvTable *wt;
	int row;
	WaveVar *dv;
	double last_ival;
	double spar;
	int rc, i, j;

	if(ss->nsweepparam > 0) {		
		if(ss->nsweepparam == 1) {
			if(ss_readsweep(ss, &spar) <= 0) {
				*statep = -1;
				return NULL;
			}
		} else {
			ss_msg(ERR, "wf_read_table", "nsweepparam=%d; multidimentional sweeps not supported\n", ss->nsweepparam);
			*statep = -1;
			return NULL;
		}
	}
	wt = wvtable_new(wf);
	if(ss->nsweepparam == 1) {	
		wt->swval = spar;
		wt->name = g_strdup(ss->spar[0].name);
	} else {
		wt->swval = 0;
	}
	
	if(*statep == 2) {
		wf_set_point(wt->iv->wds, row, *ivalp);
		for(i = 0; i < wt->wt_ndv; i++) {
			dv = &wt->dv[i];
			for(j = 0; j < dv->wv_ncols; j++)
				wf_set_point(&dv->wds[j], row,
					     dvals[dv->sv->col - 1 + j ]);
		}
		row = 1;
		wt->nvalues = 1;
		last_ival = *ivalp;
	} else {
		row = 0;
		wt->nvalues = 0;
		last_ival = -1.0e29;
	}

	while((rc = ss_readrow(ss, ivalp, dvals)) > 0) {
		if(row > 0 && *ivalp < last_ival) {
			if(row == 1) {
				ss_msg(ERR, "wavefile_read", "independent variable is not nondecreasing at row %d; ival=%g last_ival=%g\n", row, *ivalp, last_ival);
				wt_free(wt);
				*statep = -1;
				return NULL;
				
			} else {
				*statep = 2;
				return wt;
			}
		}
		last_ival = *ivalp;
		wf_set_point(wt->iv->wds, row, *ivalp);
		for(i = 0; i < wt->wt_ndv; i++) {
			dv = &wt->dv[i];
			for(j = 0; j < dv->wv_ncols; j++)
				wf_set_point(&dv->wds[j], row,
					     dvals[dv->sv->col - 1 + j ]);
		}
		row++;
		wt->nvalues++;
	}
	if(rc == -2)
		*statep = 1;
	else if(rc < 0) {
		wt_free(wt);
		*statep = -1;
		return NULL;
	} else {
		*statep = 0;
	}
	return wt;
}
Exemplo n.º 12
0
int main() {
	wave_object obj;
	wt_object wt;
	double *inp, *out, *diff;
	int N, i, J;

	FILE *ifp;
	double temp[1200];

	char *name = "db4";
	obj = wave_init(name);
	wave_summary(obj);

	ifp = fopen("signal.txt", "r");
	i = 0;
	if (!ifp) {
		printf("Cannot Open File");
		exit(100);
	}
	while (!feof(ifp)) {
		fscanf(ifp, "%lf \n", &temp[i]);
		i++;
	}
	N = 177;
	
	fclose(ifp);

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	diff = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
		inp[i] = temp[i];
		//printf("%g \n",inp[i]);
	}
	J = 2;

	wt = wt_init(obj, "modwt", N, J);// Initialize the wavelet transform object
	
	modwt(wt, inp);// Perform MODWT
	//MODWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
	
	for (i = 0; i < wt->outlength; ++i) {
		printf("%g ",wt->output[i]);
	}

	imodwt(wt, out);// Perform ISWT (if needed)
	// Test Reconstruction


	for (i = 0; i < wt->siglength; ++i) {
		diff[i] = out[i] - inp[i];
	}

	printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value.
	
	wt_summary(wt);// Prints the full summary.

	wave_free(obj);
	wt_free(wt);

	free(inp);
	free(out);
	free(diff);
	return 0;
}
Exemplo n.º 13
0
void ReconstructionTest()
{

	wave_object obj;
	wt_object wt;
	double *inp,*out;
	int N, i,J;
    double epsilon = 1e-15;
    char *type = (char*) "dwt";

    N = 79926;
    
    //N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
        inp[i] = (rand() / (double)(RAND_MAX));
	}
    std::vector<std::string > waveletNames;

    for (unsigned int j = 0; j < 36; j++)
    {
        waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
    }
    for (unsigned int j = 0; j < 17; j++)
    {
        waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
    }
    for (unsigned int j = 1; j < 20; j++)
    {
        waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
    }
    
    waveletNames.push_back("bior1.1");
    waveletNames.push_back("bior1.3");
    waveletNames.push_back("bior1.5");
    waveletNames.push_back("bior2.2");
    waveletNames.push_back("bior2.4");
    waveletNames.push_back("bior2.6");
    waveletNames.push_back("bior2.8");
    waveletNames.push_back("bior3.1");
    waveletNames.push_back("bior3.3");
    waveletNames.push_back("bior3.5");
    waveletNames.push_back("bior3.7");
    waveletNames.push_back("bior3.9");
    waveletNames.push_back("bior4.4");
    waveletNames.push_back("bior5.5");
    waveletNames.push_back("bior6.8");
    
    waveletNames.push_back("rbior1.1");
    waveletNames.push_back("rbior1.3");
    waveletNames.push_back("rbior1.5");
    waveletNames.push_back("rbior2.2");
    waveletNames.push_back("rbior2.4");
    waveletNames.push_back("rbior2.6");
    waveletNames.push_back("rbior2.8");
    waveletNames.push_back("rbior3.1");
    waveletNames.push_back("rbior3.3");
    waveletNames.push_back("rbior3.5");
    waveletNames.push_back("rbior3.7");
    waveletNames.push_back("rbior3.9");
    waveletNames.push_back("rbior4.4");
    waveletNames.push_back("rbior5.5");
    waveletNames.push_back("rbior6.8");

    for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
    {
        for (unsigned int sym_per = 0; sym_per < 2; sym_per++)
        {
            for (unsigned int j = 0; j < waveletNames.size(); j++)
            {
                char * name = new char[waveletNames[j].size() + 1];
                memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
                obj = wave_init(name);// Initialize the wavelet
                for (J = 1; J < 3; J++)
                {
                    //J = 3;

                    wt = wt_init(obj,(char*) "dwt", N, J);// Initialize the wavelet transform object
                    if (sym_per == 0)
                        setDWTExtension(wt, (char*) "sym");// Options are "per" and "sym". Symmetric is the default option
                    else
                        setDWTExtension(wt, (char*) "per");
                    if (direct_fft == 0)
                        setWTConv(wt, (char*) "direct");
                    else
                        setWTConv(wt, (char*) "fft");

                    dwt(wt, inp);// Perform DWT

                    idwt(wt, out);// Perform IDWT (if needed)
                    // Test Reconstruction

                    if (direct_fft == 0)
                        epsilon = 1e-8;
                    else
                        epsilon = 1e-10;
                    //BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
                    
					//printf("%g ",RMS_Error(out, inp, wt->siglength));
					if (RMS_Error(out, inp, wt->siglength) > epsilon) {
						printf("\n ERROR : DWT Reconstruction Unit Test Failed. Exiting. \n");
						exit(-1);
					}
                    wt_free(wt);
                }
                wave_free(obj);
                delete[] name;
            }
        }
    }
    
	free(out);
    free(inp);
}