diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2007-12-20 22:37:21 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2007-12-20 22:37:21 (GMT) |
commit | bffc42f6ac251d7a4d6b77721563ba2122fdddd6 (patch) | |
tree | c133f51e7ab6b01f7659e7e1d3ccd6120b5d12dc | |
parent | 491971980d68bb763899d42946a63fc127f9c4cb (diff) | |
download | hdf5-bffc42f6ac251d7a4d6b77721563ba2122fdddd6.zip hdf5-bffc42f6ac251d7a4d6b77721563ba2122fdddd6.tar.gz hdf5-bffc42f6ac251d7a4d6b77721563ba2122fdddd6.tar.bz2 |
[svn-r14356] Description:
Refactor work for bug #956 to simplify a bit and to cover some corner
cases.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
-rw-r--r-- | src/H5Shyper.c | 119 | ||||
-rw-r--r-- | src/H5Sprivate.h | 6 | ||||
-rw-r--r-- | src/H5Sselect.c | 10 |
3 files changed, 58 insertions, 77 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 7e3b30c..56bb552 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -277,14 +277,17 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) /* Don't flatten adjacent elements into contiguous block if the * element size is 0. This is for the H5S_select_shape_same() code. */ - if(iter->elmt_size>0) { + if(iter->elmt_size > 0) { /* Check for any "contiguous" blocks that can be flattened */ - for(u=rank-1; u>0; u--) { - if(tdiminfo[u].count==1 && tdiminfo[u].block==mem_size[u]) { + for(u = (rank - 1); u > 0; u--) { + if(tdiminfo[u].count == 1 && tdiminfo[u].block == mem_size[u]) { cont_dim++; - iter->dims_flatten[u] = TRUE; - } + iter->u.hyp.flattened[u] = TRUE; + } /* end if */ + else + iter->u.hyp.flattened[u] = FALSE; } /* end for */ + iter->u.hyp.flattened[0] = FALSE; } /* end if */ /* Check if the regular selection can be "flattened" */ @@ -420,7 +423,6 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) * *------------------------------------------------------------------------- */ -#ifdef TMP static herr_t H5S_hyper_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords) { @@ -435,79 +437,62 @@ H5S_hyper_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords) /* Check for a single "regular" hyperslab */ if(iter->u.hyp.diminfo_valid) { /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank!=0 && iter->u.hyp.iter_rank<iter->rank) { - unsigned flat_dim; /* The rank of the flattened dimension */ - unsigned dim = iter->rank - iter->u.hyp.iter_rank; - - /* Get the rank of the flattened dimension */ - flat_dim=iter->u.hyp.iter_rank-1; - - /* Copy the coordinates up to where things got flattened */ -#ifdef TMP - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*flat_dim); - - /* Compute the coordinates for the flattened dimensions */ - H5V_array_calc(iter->u.hyp.off[flat_dim],iter->rank-flat_dim,&(iter->dims[flat_dim]),&(coords[flat_dim])); -#else - /* Compute the coords for the flattened dimensions */ - H5V_array_calc(iter->u.hyp.off[0],dim+1,iter->dims,coords); - - /* Copy the coords for the unflattened dimensions */ - if(dim+1 < iter->rank) - HDmemcpy(&(coords[dim+1]),&(iter->u.hyp.off[1]),sizeof(hsize_t)*(iter->u.hyp.iter_rank -1)); -#endif - } /* end if */ - else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); - } /* end if */ - else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < iter->rank) { + int u, v; /* Dimension indices */ - FUNC_LEAVE_NOAPI(SUCCEED); -} /* H5S_hyper_iter_coords() */ -#else -static herr_t -H5S_hyper_iter_coords (const H5S_sel_iter_t *iter, hsize_t *coords) -{ - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_iter_coords); + /* Set the starting rank of both the "natural" & "flattened" dimensions */ + u = iter->rank - 1; + v = iter->u.hyp.iter_rank - 1; - /* Check args */ - assert (iter); - assert (coords); + /* Construct the "natural" dimensions from a set of flattened coordinates */ + while(u >= 0) { + if(iter->u.hyp.flattened[u]) { + int begin = u; /* The rank of the first flattened dimension */ - /* Copy the offset of the current point */ + /* Walk up through as many flattened dimensions as possible */ + do { + u--; + } while(u >= 0 && iter->u.hyp.flattened[u]); - /* Check for a single "regular" hyperslab */ - if(iter->u.hyp.diminfo_valid) { - /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank!=0 && iter->u.hyp.iter_rank<iter->rank) { - unsigned dim = iter->rank - iter->u.hyp.iter_rank; - int u, v; - int begin = -1; - - for(u=iter->rank-1, v=iter->u.hyp.iter_rank-1; u>=0, v>=0; u--) { - if(!iter->dims_flatten[u]) { - if(begin > 0) { - /* Compute the coords for the flattened dimensions */ - H5V_array_calc(iter->u.hyp.off[v],begin-u+1,&(iter->dims[u]),&(coords[u])); - begin = -1; - } else - HDmemcpy(&(coords[u]), &(iter->u.hyp.off[v]), sizeof(hsize_t)); + /* Compensate for possibly overshooting dim 0 */ + if(u < 0) + u = 0; + + /* Sanity check */ + HDassert(v >= 0); + + /* Compute the coords for the flattened dimensions */ + H5V_array_calc(iter->u.hyp.off[v], (unsigned)((begin - u) + 1), &(iter->dims[u]), &(coords[u])); + + /* Continue to faster dimension in both indices */ + u--; v--; - } - else if(iter->dims_flatten[u] && (begin == -1)) - begin = u; - } + } /* end if */ + else { + /* Walk up through as many non-flattened dimensions as possible */ + while(u >= 0 && !iter->u.hyp.flattened[u]) { + /* Sanity check */ + HDassert(v >= 0); + + /* Copy the coordinate */ + coords[u] = iter->u.hyp.off[v]; + + /* Continue to faster dimension in both indices */ + u--; + v--; + } /* end while */ + } /* end else */ + } /* end while */ + HDassert(v < 0); } /* end if */ else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); + HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); } /* end if */ else - HDmemcpy(coords,iter->u.hyp.off,sizeof(hsize_t)*iter->rank); + HDmemcpy(coords, iter->u.hyp.off, sizeof(hsize_t) * iter->rank); FUNC_LEAVE_NOAPI(SUCCEED); } /* H5S_hyper_iter_coords() */ -#endif /*------------------------------------------------------------------------- diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 64bf3a5..aa8a418 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -78,8 +78,9 @@ typedef struct { /* "Flattened" regular hyperslab selection fields */ H5S_hyper_dim_t diminfo[H5S_MAX_RANK]; /* "Flattened" regular selection information */ - hsize_t size[H5S_MAX_RANK]; /* "Flattened" dataspace extent information */ - hssize_t sel_off[H5S_MAX_RANK]; /* "Flattened" selection offset information */ + hsize_t size[H5S_MAX_RANK]; /* "Flattened" dataspace extent information */ + hssize_t sel_off[H5S_MAX_RANK]; /* "Flattened" selection offset information */ + hbool_t flattened[H5S_MAX_RANK]; /* Whether this dimension has been flattened */ /* Irregular hyperslab selection fields */ H5S_hyper_span_info_t *spans; /* Pointer to copy of the span tree */ @@ -103,7 +104,6 @@ typedef struct H5S_sel_iter_t { /* Information common to all iterators */ unsigned rank; /* Rank of dataspace the selection iterator is operating on */ hsize_t *dims; /* Dimensions of dataspace the selection is operating on */ - hbool_t *dims_flatten; hsize_t elmt_left; /* Number of elements left to iterate over */ size_t elmt_size; /* Size of elements to iterate over */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 09083fa..fa413a5 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -801,13 +801,9 @@ H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, size_t elmt_s /* Save the dataspace's rank */ sel_iter->rank=space->extent.rank; - if(sel_iter->rank>0) { - /* Point to the dataspace dimensions */ - sel_iter->dims=space->extent.size; - - /* Allocate space for the flags whether the dimension is flattened */ - sel_iter->dims_flatten = (hbool_t*)H5MM_calloc(sel_iter->rank*sizeof(hbool_t)); - } /* end if */ + /* Point to the dataspace dimensions, if there are any */ + if(sel_iter->rank > 0) + sel_iter->dims = space->extent.size; else sel_iter->dims = NULL; |