summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Shyper.c105
-rw-r--r--src/H5Spublic.h3
-rw-r--r--test/tselect.c164
3 files changed, 272 insertions, 0 deletions
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index c97c9b6..93a93b7 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -8856,3 +8856,108 @@ H5S_hyper_get_seq_list(const H5S_t *space, unsigned UNUSED flags, H5S_sel_iter_t
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_hyper_get_seq_list() */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5Sis_regular_hyperslab
+ PURPOSE
+ Determine if a hyperslab selection is regular
+ USAGE
+ htri_t H5Sis_regular_hyperslab(dsid)
+ hid_t dsid; IN: Dataspace ID of hyperslab selection to query
+ RETURNS
+ TRUE/FALSE for hyperslab selection, FAIL on error or when querying other
+ selection types.
+ DESCRIPTION
+ If a hyperslab can be represented as a single call to H5Sselect_hyperslab,
+ with the H5S_SELECT_SET option, it is regular. If the hyperslab selection
+ would require multiple calls to H5Sselect_hyperslab, it is irregular.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+htri_t
+H5Sis_regular_hyperslab(hid_t spaceid)
+{
+ H5S_t *space; /* Dataspace to query */
+ htri_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE1("Hs", "i", spaceid);
+
+ /* Check args */
+ if(NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
+ if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_HYPERSLABS)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a hyperslab selection")
+
+ ret_value = H5S_hyper_is_regular(space);
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Sis_regular_hyperslab() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5Sgetregular_hyperslab
+ PURPOSE
+ Retrieve a regular hyperslab selection
+ USAGE
+ herr_t H5Sget_regular_hyperslab(dsid, start, stride, block, count)
+ hid_t dsid; IN: Dataspace ID of hyperslab selection to query
+ hsize_t start[]; OUT: Offset of start of hyperslab
+ hsize_t stride[]; OUT: Hyperslab stride
+ hsize_t count[]; OUT: Number of blocks included in hyperslab
+ hsize_t block[]; OUT: Size of block in hyperslab
+ RETURNS
+ Non-negative on success/Negative on failure. (It is an error to query
+ the regular hyperslab selections for non-regular hyperslab selections)
+ DESCRIPTION
+ Retrieve the start/stride/count/block for a regular hyperslab selection.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ Note that if a hyperslab is originally regular, then becomes irregular
+ through selection operations, and then becomes regular again, the new
+ final regular selection may be equivalent but not identical to the
+ original regular selection.
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5Sget_regular_hyperslab(hid_t spaceid, hsize_t start[], hsize_t stride[],
+ hsize_t count[], hsize_t block[])
+{
+ H5S_t *space; /* Dataspace to query */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+
+ /* Check args */
+ if(NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
+ if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_HYPERSLABS)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a hyperslab selection")
+ if(TRUE != H5S_hyper_is_regular(space))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a regular hyperslab selection")
+
+ /* Retrieve hyperslab parameters */
+ if(start)
+ for(u = 0; u < space->extent.rank; u++)
+ start[u] = space->select.sel_info.hslab->app_diminfo[u].start;
+ if(stride)
+ for(u = 0; u < space->extent.rank; u++)
+ stride[u] = space->select.sel_info.hslab->app_diminfo[u].stride;
+ if(count)
+ for(u = 0; u < space->extent.rank; u++)
+ count[u] = space->select.sel_info.hslab->app_diminfo[u].count;
+ if(block)
+ for(u = 0; u < space->extent.rank; u++)
+ block[u] = space->select.sel_info.hslab->app_diminfo[u].block;
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Sget_regular_hyperslab() */
+
diff --git a/src/H5Spublic.h b/src/H5Spublic.h
index 0a39ce1..37d3866 100644
--- a/src/H5Spublic.h
+++ b/src/H5Spublic.h
@@ -137,6 +137,9 @@ H5_DLL herr_t H5Sselect_all(hid_t spaceid);
H5_DLL herr_t H5Sselect_none(hid_t spaceid);
H5_DLL herr_t H5Soffset_simple(hid_t space_id, const hssize_t *offset);
H5_DLL htri_t H5Sselect_valid(hid_t spaceid);
+H5_DLL htri_t H5Sis_regular_hyperslab(hid_t spaceid);
+H5_DLL htri_t H5Sget_regular_hyperslab(hid_t spaceid, hsize_t start[],
+ hsize_t stride[], hsize_t count[], hsize_t block[]);
H5_DLL hssize_t H5Sget_select_hyper_nblocks(hid_t spaceid);
H5_DLL hssize_t H5Sget_select_elem_npoints(hid_t spaceid);
H5_DLL herr_t H5Sget_select_hyper_blocklist(hid_t spaceid, hsize_t startblock,
diff --git a/test/tselect.c b/test/tselect.c
index d5a1f4c..b34d095 100644
--- a/test/tselect.c
+++ b/test/tselect.c
@@ -162,6 +162,12 @@
/* #defines for shape same / different rank tests */
#define SS_DR_MAX_RANK 5
+/* Information for regular hyperslab query test */
+#define SPACE13_RANK 3
+#define SPACE13_DIM1 50
+#define SPACE13_DIM2 50
+#define SPACE13_DIM3 50
+#define SPACE13_NPOINTS 4
/* Location comparison function */
@@ -13069,6 +13075,161 @@ test_select_bounds(void)
/****************************************************************
**
+** test_hyper_regular(): Tests query operations on regular hyperslabs
+**
+****************************************************************/
+static void
+test_hyper_regular(void)
+{
+ hid_t sid; /* Dataspace ID */
+ const hsize_t dims[SPACE13_RANK] = {SPACE13_DIM1, SPACE13_DIM2, SPACE13_DIM3}; /* Dataspace dimensions */
+ hsize_t coord[SPACE13_NPOINTS][SPACE13_RANK]; /* Coordinates for point selection */
+ hsize_t start[SPACE13_RANK]; /* The start of the hyperslab */
+ hsize_t stride[SPACE13_RANK]; /* The stride between block starts for the hyperslab */
+ hsize_t count[SPACE13_RANK]; /* The number of blocks for the hyperslab */
+ hsize_t block[SPACE13_RANK]; /* The size of each block for the hyperslab */
+ hsize_t t_start[SPACE13_RANK]; /* Temporary start of the hyperslab */
+ hsize_t t_count[SPACE13_RANK]; /* Temporary number of blocks for the hyperslab */
+ hsize_t q_start[SPACE13_RANK]; /* The queried start of the hyperslab */
+ hsize_t q_stride[SPACE13_RANK]; /* The queried stride between block starts for the hyperslab */
+ hsize_t q_count[SPACE13_RANK]; /* The queried number of blocks for the hyperslab */
+ hsize_t q_block[SPACE13_RANK]; /* The queried size of each block for the hyperslab */
+ htri_t is_regular; /* Whether a hyperslab selection is regular */
+ unsigned u; /* Local index variable */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(6, ("Testing queries on regular hyperslabs\n"));
+
+ /* Create dataspace */
+ sid = H5Screate_simple(SPACE13_RANK, dims, NULL);
+ CHECK(sid, FAIL, "H5Screate_simple");
+
+ /* Query if 'all' selection is regular hyperslab (should fail) */
+ H5E_BEGIN_TRY {
+ is_regular = H5Sis_regular_hyperslab(sid);
+ } H5E_END_TRY;
+ VERIFY(is_regular, FAIL, "H5Sis_regular_hyperslab");
+
+ /* Query regular hyperslab selection info (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* Set 'none' selection */
+ ret = H5Sselect_none(sid);
+ CHECK(ret, FAIL, "H5Sselect_none");
+
+ /* Query if 'none' selection is regular hyperslab (should fail) */
+ H5E_BEGIN_TRY {
+ is_regular = H5Sis_regular_hyperslab(sid);
+ } H5E_END_TRY;
+ VERIFY(is_regular, FAIL, "H5Sis_regular_hyperslab");
+
+ /* Query regular hyperslab selection info (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* Set point selection */
+ coord[0][0] = 3; coord[0][1] = 3; coord[0][2] = 3;
+ coord[1][0] = 3; coord[1][1] = 48; coord[1][2] = 48;
+ coord[2][0] = 48; coord[2][1] = 3; coord[2][2] = 3;
+ coord[3][0] = 48; coord[3][1] = 48; coord[3][2] = 48;
+ ret = H5Sselect_elements(sid, H5S_SELECT_SET, (size_t)SPACE13_NPOINTS, (const hsize_t *)coord);
+ CHECK(ret, FAIL, "H5Sselect_elements");
+
+ /* Query if 'point' selection is regular hyperslab (should fail) */
+ H5E_BEGIN_TRY {
+ is_regular = H5Sis_regular_hyperslab(sid);
+ } H5E_END_TRY;
+ VERIFY(is_regular, FAIL, "H5Sis_regular_hyperslab");
+
+ /* Query regular hyperslab selection info (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* Set "regular" hyperslab selection */
+ start[0] = 2; start[1] = 2; start[2] = 2;
+ stride[0] = 5; stride[1] = 5; stride[2] = 5;
+ count[0] = 3; count[1] = 3; count[2] = 3;
+ block[0] = 4; block[1] = 4; block[2] = 4;
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, start, stride, count, block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Query if 'hyperslab' selection is regular hyperslab (should be TRUE) */
+ is_regular = H5Sis_regular_hyperslab(sid);
+ VERIFY(is_regular, TRUE, "H5Sis_regular_hyperslab");
+
+ /* Retrieve the hyperslab parameters */
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ CHECK(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* Verify the hyperslab parameters */
+ for(u = 0; u < SPACE13_RANK; u++) {
+ if(start[u] != q_start[u])
+ ERROR("H5Sget_regular_hyperslab, start");
+ if(stride[u] != q_stride[u])
+ ERROR("H5Sget_regular_hyperslab, stride");
+ if(count[u] != q_count[u])
+ ERROR("H5Sget_regular_hyperslab, count");
+ if(block[u] != q_block[u])
+ ERROR("H5Sget_regular_hyperslab, block");
+ } /* end for */
+
+ /* 'OR' in another point */
+ t_start[0] = 0; t_start[1] = 0; t_start[2] = 0;
+ t_count[0] = 1; t_count[1] = 1; t_count[2] = 1;
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_OR, t_start, NULL, t_count, NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Query if 'hyperslab' selection is regular hyperslab (should be FALSE) */
+ is_regular = H5Sis_regular_hyperslab(sid);
+ VERIFY(is_regular, FALSE, "H5Sis_regular_hyperslab");
+
+ /* Query regular hyperslab selection info (should fail) */
+ H5E_BEGIN_TRY {
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ } H5E_END_TRY;
+ VERIFY(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* 'XOR' in the point again, to remove it, which should make it regular again */
+ t_start[0] = 0; t_start[1] = 0; t_start[2] = 0;
+ t_count[0] = 1; t_count[1] = 1; t_count[2] = 1;
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_XOR, t_start, NULL, t_count, NULL);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Query if 'hyperslab' selection is regular hyperslab (should be TRUE) */
+ is_regular = H5Sis_regular_hyperslab(sid);
+ VERIFY(is_regular, TRUE, "H5Sis_regular_hyperslab");
+
+ /* Retrieve the hyperslab parameters */
+ ret = H5Sget_regular_hyperslab(sid, q_start, q_stride, q_count, q_block);
+ CHECK(ret, FAIL, "H5Sget_regular_hyperslab");
+
+ /* Verify the hyperslab parameters */
+ for(u = 0; u < SPACE13_RANK; u++) {
+ if(start[u] != q_start[u])
+ ERROR("H5Sget_regular_hyperslab, start");
+ if(stride[u] != q_stride[u])
+ ERROR("H5Sget_regular_hyperslab, stride");
+ if(count[u] != q_count[u])
+ ERROR("H5Sget_regular_hyperslab, count");
+ if(block[u] != q_block[u])
+ ERROR("H5Sget_regular_hyperslab, block");
+ } /* end for */
+
+ /* Close the dataspace */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+} /* test_hyper_regular() */
+
+/****************************************************************
+**
** test_select(): Main H5S selection testing routine.
**
****************************************************************/
@@ -13228,6 +13389,9 @@ test_select(void)
/* Test selection bounds with & without offsets */
test_select_bounds();
+ /* Test 'regular' hyperslab query routines */
+ test_hyper_regular();
+
} /* test_select() */