[Assorted-commits] SF.net SVN: assorted: [864] tcq-wavelets/trunk/Test
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-07-02 06:48:08
|
Revision: 864 http://assorted.svn.sourceforge.net/assorted/?rev=864&view=rev Author: yangzhang Date: 2008-07-01 23:48:11 -0700 (Tue, 01 Jul 2008) Log Message: ----------- forgot tests; updated wavelet.[ch] to latest? Modified Paths: -------------- tcq-wavelets/trunk/Test/wavelet.c tcq-wavelets/trunk/Test/wavelet.h Added Paths: ----------- tcq-wavelets/trunk/Test/tests.tar.bz2 Added: tcq-wavelets/trunk/Test/tests.tar.bz2 =================================================================== (Binary files differ) Property changes on: tcq-wavelets/trunk/Test/tests.tar.bz2 ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: tcq-wavelets/trunk/Test/wavelet.c =================================================================== --- tcq-wavelets/trunk/Test/wavelet.c 2008-07-02 06:41:27 UTC (rev 863) +++ tcq-wavelets/trunk/Test/wavelet.c 2008-07-02 06:48:11 UTC (rev 864) @@ -5,9 +5,13 @@ // TODO how to get rid of blanket noise? // TASKS +// TODO move all decls to top +// TODO change // ... to /* ... */ // TODO output as table +// TODO add checks / assertions on integrity of wcs (as fred did for hist) // TODO handle multiple join, proj dimensions at a time (did I already do this? I forget....) // TODO change dims to arrays, rename vars, remove the need for toasting, work with giant structure directly! +// TODO add profiling calls // TODO speed up equijoin // TODO pfree stuff @@ -43,6 +47,7 @@ #else +#include "telegraphcq/histogram.h" #include "telegraphcq/wavelet.h" // TODO check @@ -1733,7 +1738,7 @@ return l < r ? -1 : l > r ? 1 : 0; } -void renderhelper(WCS* wcs, LL* coeff, int i, double** c) { +void renderhelper(WCS* wcs, LL* coeff, int i, double** c, mhist* h) { //PL("\n"); //PL("renderhelper start (i = %d)\n", i); //PI(); @@ -1780,6 +1785,11 @@ return; } +#ifdef RENDER_HIST + int* minvals = (int*) malloc(wcs->dims.count * sizeof(int)); + int* maxvals = (int*) malloc(wcs->dims.count * sizeof(int)); +#endif + // output (w.r.boundary, count) PL("v = % 2.3f\n", count); if (mwc != NULL) { // TODO check @@ -1790,8 +1800,14 @@ Assert(j < wcs->dims.count); DI* di = (DI*) lln->value; DN* dn = mwc->a[j]; +#ifdef RENDER_HIST + // TODO change to use unseg() instead? + minvals[j] = (int) dn->rl; + maxvals[j] = (int) dn->rh; +#else PL("\t%d : [ %d : %d ] or [ %f : %f ]\n", j, dn->rl, dn->rh, unseg(wcs, di, dn->rl), unseg(wcs, di, dn->rh + 1)); +#endif if (c != NULL) { switch (j) { case 0: @@ -1815,6 +1831,10 @@ } } +#ifdef RENDER_HIST + add_bucket_to_mhist(hist, minvals, maxvals, count); +#endif + //PUI(); //PL("renderhelper end\n"); //PL("\n"); @@ -1931,7 +1951,7 @@ LL_add(&temp2, plln); } } - renderhelper(wcs, &temp2, i + 1, c); + renderhelper(wcs, &temp2, i + 1, c, h); prev = topkey; } @@ -2124,7 +2144,20 @@ c[i] = (double*) wcalloc(s, sizeof(double)); } } - renderhelper(wcs, &ll, 0, c); + mhist* h = NULL; +#ifdef RENDER_HIST + // TODO be more conservative with size estimate, use create_bigger_mhist as needed +#define MAX_BUCKETS 65536 + int nbuckets = min(MAX_BUCKETS, pow(1 << wcs->m, wcs->dims.count)); + h = create_mhist(nbuckets, wcs->dims.count); + char** cols = (char**) malloc(sizeof(char*) * wcs->dims.count); + int j = 0; + for (j = 0; j < wcs->dims.count; j++) { + cols[j] = wcs->dims[j]; + } + mhist_set_nameinfo(h, /* TODO change */ "placeholder", cols, wcs->dims.count); + renderhelper(wcs, &ll, 0, c, hist, &h); +#endif // RENDER_HIST if (c != NULL) { int i, j; for (i = 0; i < s; i++) { @@ -2417,6 +2450,166 @@ } #endif +//void render_table(WCS* wcs) { +// FuncCallContext *funcctx = NULL; +// wcs_to_table_state *state = NULL; +///* TupleDesc tupdesc;*/ +// char typename[128]; +// +// if (SRF_IS_FIRSTCALL()) { +// MemoryContext oldcontext; +// +// funcctx = SRF_FIRSTCALL_INIT(); +// +// /*elog(LOG, "mhist_to_table(): Starting first-call setup.");*/ +// +// +// /* Create the data structure that will remember the status of this +// * function. */ +// oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); +// state = palloc(sizeof(*state)); +// MemoryContextSwitchTo(oldcontext); +// +// state->current_wavelet = 0; +// state->num_wavelets = wcs->coefs.count; +// +// /* Generate the name of the type that corresponds to the histogram's +// * number of dimensions. */ +// snprintf(typename, sizeof(typename), "__wcs%d", wcs->dims.count); +// +// /* Postgres SRF crap has been moved to this function: */ +// srf_firstcall_junk(funcctx, state, +// wcs->coefs.count, typename); +// +// /*elog(LOG, "mhist_to_table(): Done with first-call setup.");*/ +// } +// +// /* Stuff that gets done every time the function is called: */ +// funcctx = SRF_PERCALL_SETUP(); +// +// state = (wcs_to_table_state*)(funcctx->user_fctx); +// +// while (state->current_wavelet < state->num_wavelets) { +// WC* wc = (WC*) wcs->coefs.nodes[state->current_wavelet]; +// if (wc->e) +// break; +// state->current_wavelet++; +// } +// +// /* Are we done returning tuples? */ +// if (state->current_wavelet < state->num_wavelets) { +// char **values; +// int numvalues = -1; +// HeapTuple tuple; +// Datum result; +// int valid = -1; +// +// /* +// elog(LOG, "mhist_to_table(): Generating tuple for bucket %d (%d total).", +// state->current_bucket, state->num_buckets); +// */ +// +// /* Not done returning tuples -- construct the next one. */ +// /* For the sake of simplicity, we convert the field values into strings +// * and then back into values. */ +// +// numvalues = 2 * hist->dims.count + 2; +// /* Number of items in row == 2 + (2 x number of dimensions: +// * 1 column for the bucketID (not strictly necessary) +// * 1 column for the bucket's count +// * 2 columns per dimension to hold min and max values. +// */ +// +// /*elog(LOG, "mhist_to_table(): This tuple has %d fields.", +// numvalues);*/ +// +// /* Build up the array of string values. */ +// values = (char**)palloc(sizeof(char*) * (numvalues)); +// +// for (valid = 0; valid < numvalues; valid++) { +// values[valid] = (char*)palloc(32 * sizeof(char)); +// } +// +// /* Fill in the array. */ +// for (valid = 0; valid < numvalues; valid++) { +// if (0 == valid) { +// /* First entry is the bucketid. */ +// snprintf(values[valid], 32, "%d", state->current_wavelet); +// +// } else if (numvalues - 1 == valid) { +// /* Last entry is the bucket count. */ +// mhist_bucket *cur_bucket = +// MHIST_BUCKET_PTR(hist, state->current_bucket); +// /* +// snprintf(values[valid], 32, "%d", +// (int)(cur_bucket->count + 0.5)); +// */ +// /* Round up if necessary */ +// snprintf(values[valid], 32, "%f", +// (cur_bucket->count)); +// +// } else { +// /* valid > 0 and < (numvalues-1) */ +// /* Entries between first and last are the bounds of the +// * rectangle that comprises this bucket. These entries +// * alternate between the lower and upper bound. */ +// int dimid = (valid - 1) / 2; +// bool is_min = (valid % 2 == 1); +// /* Is this a lower or upper bound? */ +// mhist_bucket *cur_bucket = +// MHIST_BUCKET_PTR(hist, state->current_bucket); +// snprintf(values[valid], 32, "%d", +// is_min ? +// cur_bucket->diminfo[dimid].min_val +// : cur_bucket->diminfo[dimid].max_val); +// } +// +// /*elog(LOG, "mhist_to_table(): Value %d is '%s'.", +// valid, values[valid]);*/ +// +// } +// +// /*elog(LOG, "mhist_to_table(): Done generating values.");*/ +// +// /* Construct the tuple for the strings. */ +// tuple = BuildTupleFromCStrings(funcctx->attinmeta, values); +// +// /*elog(LOG, "mhist_to_table(): Done building tuple.");*/ +// +// /* Make the tuple into a datum. */ +// result = TupleGetDatum(funcctx->slot, tuple); +// +// /* Clean up. */ +// for (valid = 0; valid < hist->hdr.numDims; valid++) { +// /*elog(LOG, "mhist_to_table(): Freeing field %d of a tuple.", +// valid);*/ +// pfree(values[valid]); +// } +// /*elog(LOG, "mhist_to_table(): Freeing holder for tuple %d.", +// state->current_bucket);*/ +// pfree(values); +// +// /*elog(LOG, "mhist_to_table(): Done generating tuple for bucket %d.", +// state->current_bucket);*/ +// +// ++(state->current_bucket); +// +// // PROF_EXIT_FUNCTION("mhist_to_table"); +// +// SRF_RETURN_NEXT(funcctx, result); +// } else { +// /*elog(LOG, "mhist_to_table(): Cleaning up.");*/ +// +// /* here we are done returning items, and just need to clean up: */ +// srf_cleanup(funcctx); +// +// // PROF_EXIT_FUNCTION("mhist_to_table"); +// +// SRF_RETURN_DONE(funcctx); +// } +//} + + #ifndef STANDALONE // renders the WCS to human-readable form to the log (and returns "blah"). // Currently simpleRender() is used, but it's inefficient, Modified: tcq-wavelets/trunk/Test/wavelet.h =================================================================== --- tcq-wavelets/trunk/Test/wavelet.h 2008-07-02 06:41:27 UTC (rev 863) +++ tcq-wavelets/trunk/Test/wavelet.h 2008-07-02 06:48:11 UTC (rev 864) @@ -34,6 +34,11 @@ #define false ((bool) 0) #endif +// this structure is not used +typedef struct mhist { + int dummy; +} mhist; + typedef struct HeapTupleData { double* values; //uint32 t_len; /* length of *t_data */ @@ -76,6 +81,7 @@ #else ///////////////////////////////////////////////////// +#define RENDER_HIST #define STDERR #include "postgres.h" @@ -218,7 +224,7 @@ // typedef struct PQ { int maxCount; - int count; + int count; // this is the number of occupied slots in the PQ, not the number of enabled nodes void** nodes; int (*compare)(void*, void*); } PQ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |