From 1867c05efb2527e435776808720572e31ab95bb7 Mon Sep 17 00:00:00 2001 From: Leon Arber Date: Thu, 6 May 2004 17:44:38 -0500 Subject: [svn-r8488] Purpose: Bug fix. Description: Fixed handling of trivial data transform expressions (like 5/3 + 3) and some data coversion fixes. Also added more tests to dtransform.c Solution: Added some more checks in the H5Z_xform_reduce_tree function to see if perhaps the transform expression is complicated and is a non-trivial reduction. Added tests for data conversion to dtransform as well as tests for a trivial data transform expression. Platforms tested: h5committest'ed, except used arabica instead of sol and didn't do on copper b/c no logon there. Problem noted with mtime test...doesn't appear to be related to anything having to do with data transforms. --- src/H5D.c | 1 - src/H5Dio.c | 53 ++-- src/H5P.c | 1 + src/H5Zprivate.h | 3 +- src/H5Ztrans.c | 833 +++++++++++++++++++++++++----------------------------- test/dtransform.c | 166 ++++++++--- 6 files changed, 542 insertions(+), 515 deletions(-) diff --git a/src/H5D.c b/src/H5D.c index afc4d16..c17dd11 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -453,7 +453,6 @@ H5D_term_interface(void) FUNC_LEAVE_NOAPI(n) } - /*------------------------------------------------------------------------- * Function: H5D_xfer_xform_del * diff --git a/src/H5Dio.c b/src/H5Dio.c index 8fc2982..4bcc9aa 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -1207,18 +1207,22 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, HGOTO_ERROR (H5E_IO, H5E_READERROR, FAIL, "mem gather failed") } /* end if */ - /* + /* * Perform data type conversion. */ if (H5T_convert(tpath, src_id, dst_id, smine_nelmts, 0, 0, tconv_buf, bkg_buf, dxpl_id)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") + - - /* Added by LA to do data transforms */ + /* Do the data transform after the conversion (since we're using type mem_type) */ if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) - H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type); + { + if( H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Error performing data transform") + } /* end of LA additions */ + /* * Scatter the data into memory. */ @@ -1445,12 +1449,23 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 HGOTO_ERROR (H5E_IO, H5E_WRITEERROR, FAIL, "file gather failed") } /* end if */ - /* + + + /* * Perform data type conversion. */ if (H5T_convert(tpath, src_id, dst_id, smine_nelmts, 0, 0, tconv_buf, bkg_buf, dxpl_id)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") + /* Do the data transform after the type conversion (since we're using dataset->type). */ + if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) + { + if( H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Error performing data transform") + } + /* End of LA modifications */ + + /* * Scatter the data out to the file. */ @@ -1458,15 +1473,11 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5 H5_timer_begin(&timer); #endif - /* LA additions for data transforms */ - if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) - H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type); - /* End of LA modifications */ - - status = H5S_select_fscat(dataset->ent.file, &(dataset->layout), + status = H5S_select_fscat(dataset->ent.file, &(dataset->layout), &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), file_space, &file_iter, smine_nelmts, dxpl_cache, dxpl_id, tconv_buf); + #ifdef H5S_DEBUG H5_timer_end(&(sconv->stats[0].scat_timer), &timer); sconv->stats[0].scat_nbytes += smine_nelmts * dst_type_size; @@ -1734,9 +1745,12 @@ UNUSED tconv_buf, bkg_buf, dxpl_id)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") - /* LA additions for data transforms */ + /* Do the data transform after the conversion (since we're using type mem_type) */ if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) - H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type); + { + if( H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, mem_type) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Error performing data transform") + } /* * Scatter the data into memory. @@ -2070,17 +2084,22 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space, if (n!=smine_nelmts) HGOTO_ERROR (H5E_IO, H5E_WRITEERROR, FAIL, "file gather failed") } /* end if */ - - /* + + + + /* * Perform data type conversion. */ if (H5T_convert(tpath, src_id, dst_id, smine_nelmts, 0, 0, tconv_buf, bkg_buf, dxpl_id)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "data type conversion failed") - /* LA additions for data transforms */ + /* Do the data transform after the type conversion (since we're using dataset->type) */ if(!H5Z_xform_noop(dxpl_cache->data_xform_prop)) - H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type); + { + if( H5Z_xform_eval(dxpl_cache->data_xform_prop, tconv_buf, smine_nelmts, dataset->type) < 0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Error performing data transform") + } /* * Scatter the data out to the file. diff --git a/src/H5P.c b/src/H5P.c index 570684f..cc0eca8 100644 --- a/src/H5P.c +++ b/src/H5P.c @@ -4455,6 +4455,7 @@ H5P_get(H5P_genplist_t *plist, const char *name, void *value) assert(plist); assert(name); + assert(value); /* Check if the property has been deleted */ diff --git a/src/H5Zprivate.h b/src/H5Zprivate.h index 33b7da9..0c43bf7 100644 --- a/src/H5Zprivate.h +++ b/src/H5Zprivate.h @@ -66,10 +66,11 @@ H5_DLL herr_t H5Z_delete(struct H5O_pline_t *pline, H5Z_filter_t filter); /* Data Transform Functions */ typedef struct H5Z_data_xform_t H5Z_data_xform_t; /* Defined in H5Ztrans.c */ + H5_DLL H5Z_data_xform_t *H5Z_xform_create(const char *expr); H5_DLL herr_t H5Z_xform_copy(H5Z_data_xform_t **data_xform_prop); H5_DLL herr_t H5Z_xform_destroy(H5Z_data_xform_t *data_xform_prop); -H5_DLL void H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type); +H5_DLL herr_t H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type); H5_DLL hbool_t H5Z_xform_noop(const H5Z_data_xform_t *data_xform_prop); #endif diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 04f3a52..ff16bee 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -720,154 +720,103 @@ done: FUNC_LEAVE_NOAPI(new_node); } -#ifdef H5Z_XFORM_DEBUG - -/*------------------------------------------------------------------------- - * Function: H5Z_XFORM_DEBUG - * Purpose: Print out the expression in a nice format which displays - * the precedences explicitly with parentheses. - * Return: Nothing - * Programmer: Bill Wendling - * 26. August 2003 - * Modifications: - * - *------------------------------------------------------------------------- - */ - -static void -H5Z_XFORM_DEBUG(H5Z_node *tree) -{ - int i; - printf("Expression: "); - H5Z_result res; - res = H5Z_eval(tree); - if(res.type == H5Z_INTEGER) - printf("H5Z_result is: %d",res.value.int_val ); - else if(res.type == H5Z_FLOAT) - printf("H5Z_result is: %f",res.value.float_val ); - else - { - printf("H5Z_result is "); - for(i=0; i<5; i++) - printf("%d ", array[i]); - } - printf("\n"); -} - - /*------------------------------------------------------------------------- - * Function: H5Z_print - * Purpose: Print out the expression in a nice format which displays - * the precedences explicitly with parentheses. - * Return: Nothing - * Programmer: Bill Wendling - * 26. August 2003 + * Function: H5Z_eval_full + * Purpose: If the transform is trivial, this function applies it. + * Otherwise, it calls H5Z_xform_eval_full to do the full + * transform. + * Return: SUCCEED if transform applied succesfully, FAIL otherwise + * Programmer: Leon Arber + * 5/1/04 * Modifications: * *------------------------------------------------------------------------- */ -static void -H5Z_print(H5Z_node *tree, FILE *stream) -{ - /* check args */ - assert(stream); - - if (!tree) - return; - - if (tree->type == H5Z_INTEGER) { - fprintf(stream, "%ld", tree->value.int_val); - } else if (tree->type == H5Z_FLOAT) { - fprintf(stream, "%f", tree->value.float_val); - } else if (tree->type == SYMBOL) { - fprintf(stream, "%s", tree->value.sym_val); - } else { - fprintf(stream, "("); - H5Z_print(tree->lchild, stream); - - switch (tree->type) { - case PLUS: fprintf(stream, "+"); break; - case MINUS: fprintf(stream, "-"); break; - case MULT: fprintf(stream, "*"); break; - case DIVIDE: fprintf(stream, "/"); break; - default: fprintf(stream, "Invalid expression tree\n"); - return; - } - - H5Z_print(tree->rchild, stream); - fprintf(stream, ")"); - } -} -#endif /* H5Z_XFORM_DEBUG */ - - -void H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type) +herr_t H5Z_xform_eval(const H5Z_data_xform_t *data_xform_prop, void* array, hsize_t array_size, const H5T_t *buf_type) { H5Z_node *tree; hid_t array_type; unsigned int i; int n; float f; - - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5Z_xform_eval) - - assert(data_xform_prop); + H5Z_result res; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(H5Z_xform_eval, FAIL) + + assert(data_xform_prop); tree=data_xform_prop->parse_root; /* Get the datatype ID for the buffer's type */ - array_type = H5Z_xform_find_type(buf_type); - - if( tree->type == H5Z_INTEGER) - { - if(array_type == H5T_NATIVE_INT) - { - n = tree->value.int_val; - for(i=0; ivalue.int_val; - for(i=0; itype == H5Z_FLOAT) - { - for(i=0; ivalue.float_val; - for(i=0; ivalue.float_val; - for(i=0; itype == H5Z_INTEGER) + { + if(array_type == H5T_NATIVE_INT) + { + n = tree->value.int_val; + for(i=0; ivalue.int_val; + for(i=0; itype == H5Z_FLOAT) + { + if(array_type == H5T_NATIVE_INT) + { + n = (int)tree->value.float_val; + for(i=0; ivalue.float_val; + for(i=0; itype == PLUS) || (tree->type == DIVIDE) ||(tree->type == MULT) ||(tree->type == MINUS)) { @@ -1487,14 +1405,19 @@ void H5Z_xform_reduce_tree(H5Z_node* tree) { H5Z_xform_reduce_tree(tree->lchild); if(((tree->lchild->type == H5Z_INTEGER) || (tree->lchild->type == H5Z_FLOAT)) && ((tree->rchild->type == H5Z_INTEGER) || (tree->rchild->type == H5Z_FLOAT))) - H5Z_do_op(tree); + { + H5Z_do_op(tree); + HGOTO_DONE(SUCCEED) + } H5Z_xform_reduce_tree(tree->rchild); if(((tree->lchild->type == H5Z_INTEGER) || (tree->lchild->type == H5Z_FLOAT)) && ((tree->rchild->type == H5Z_INTEGER) || (tree->rchild->type == H5Z_FLOAT))) - H5Z_do_op(tree); + { + H5Z_do_op(tree); + HGOTO_DONE(SUCCEED) + } } } - goto done; done: FUNC_LEAVE_NOAPI_VOID; diff --git a/test/dtransform.c b/test/dtransform.c index b3a0943..5e67986 100644 --- a/test/dtransform.c +++ b/test/dtransform.c @@ -2,18 +2,18 @@ #define ROWS 12 #define COLS 18 -#define TOL 2 -int compare(int* a, int* b); +int compare_int(int* a, int* b, int tol); +int compare_float(float* a, float* b, float tol); int main() { - - hid_t file_id, dxpl_id_f_to_c, dxpl_id_c_to_f, dset_id, datatype, dataspace; + hid_t file_id, dxpl_id_f_to_c, dxpl_id_c_to_f, dxpl_id_simple, dset_id_int, dset_id_float, datatype, dataspace; hsize_t dim[2] = {ROWS, COLS}; - char* f_to_c = "(5/9.0)*(x-32)"; - char* c_to_f = "(9/5.0)*x + 32"; - int windchillF[ROWS][COLS] = + const char* f_to_c = "(5/9.0)*(x-32)"; + const char* c_to_f = "(9/5.0)*x + 32"; + const char* simple = "(4/2) * ( (2 + 4)/(5 - 2.5))"; /* this equals 4.8 */ + int windchillFint[ROWS][COLS] = { {36, 31, 25, 19, 13, 7, 1, -5, -11, -16, -22, -28, -34, -40, -46, -52, -57, -63 }, {34, 27, 21, 15, 9, 3, -4, -10, -16, -22, -28, -35, -41, -47, -53, -59, -66, -72 } , {32, 25, 19, 13, 6, 0, -7, -13, -19, -26, -32, -39, -45, -51, -58, -64, -71, -77 }, @@ -27,59 +27,135 @@ int main() {25, 18, 11, 4, -3, -11, -18, -25, -32, -39, -46, -54, -61, -68, -75, -82, -89, -97}, {25, 17, 10, 3, -4, -11, -19, -26, -33, -40, -48, -55, -62, -69, -76, -84, -91, -98} }; - int windchillCread[ROWS][COLS]; - int windchillFread[ROWS][COLS]; - int windchillCcalc[ROWS][COLS]; + int windchillFintread[ROWS][COLS]; + float windchillFfloat[ROWS][COLS] = + { {36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0 }, + {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0 } , + {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0 }, + {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0 }, + {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0 }, + {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0 }, + {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0 }, + {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0 }, + {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0 }, + {26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0}, + {25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0}, + {25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0} + }; + float windchillFfloatread[ROWS][COLS]; + int windchillCint[ROWS][COLS]; herr_t err; int row, col; - - TESTING("data transform"); + for(row = 0; rowint)") + /* Read in the integer data with a data transform. */ + err = H5Dread(dset_id_int, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillFintread); - if( (compare((int*)windchillCread, (int*)windchillCcalc)) == 0) + if( (compare_int(*windchillFintread, *windchillFint, 2)) == 0) { fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); TEST_ERROR; } else + PASSED(); + + TESTING("data transform, no data type conversion (float->float)") + err = H5Dread(dset_id_float, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillFfloatread); + if( (compare_float(*windchillFfloat, *windchillFfloatread, 2.0)) == 0) { - err = H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillFread); - if( (compare((int *)windchillF, (int *)windchillFread)) == 0) - { - fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); - TEST_ERROR; - } - } - + fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); + TEST_ERROR; + } + else + PASSED(); + + TESTING("data transform, with data type conversion (int->float)") + err = H5Dread(dset_id_int, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillFfloatread); + if( (compare_float(*windchillFfloat, *windchillFfloatread, 2.0)) == 0) + { + fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); + TEST_ERROR; + } + else + PASSED(); + + TESTING("data transform, with data type conversion (float->int)") + err = H5Dread(dset_id_float, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillFintread); + if( (compare_int(*windchillFint, *windchillFintread, 2)) == 0) + { + fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); + TEST_ERROR; + } + else + PASSED(); + + TESTING("data transform, trivial transform, without type conversion") + err = H5Dread(dset_id_float, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_simple, windchillFfloatread); + for(row = 0; row 0.0001) + { + fprintf(stderr, "ERROR: Conversion failed to match computed data\n"); + TEST_ERROR; + } + } + } + PASSED(); + + TESTING("data transform, trivial transform, with type conversion") + err = H5Dread(dset_id_float, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl_id_simple, windchillFintread); + for(row = 0; row= (b[row*COLS + col] - TOL))) ) - return 0; - } + if( !((a[i] <= (b[i] + tol)) && (a[i] >= (b[i] - tol)))) + return 0; } return 1; + } +int compare_float(float* a, float* b, float tol) +{ + int i; + for(i=0; i= (b[i] - tol))) ) + return 0; + } + return 1; +} -- cgit v0.12