Skip to content

Commit 3c8733b

Browse files
authored
Add dim num support for ndrectangle. (#5230)
This PR adds capi and cppapi support for querying the number of slots/dimensions/axes of a current domain ndrectangle. Depends on #5229 to be merged first. --- TYPE: FEATURE DESC: Add dim num support for ndrectangle.
1 parent b8ca549 commit 3c8733b

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

examples/c_api/current_domain.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ void print_current_domain() {
155155
tiledb_datatype_to_str(dtype, &dtype_str);
156156
printf("Range 0 dtype by name: %s\n", dtype_str);
157157

158+
// Get dim num
159+
uint32_t ndim;
160+
tiledb_ndrectangle_get_dim_num(ctx, ndrect, &ndim);
161+
printf("Range 0 dtype by name: %d\n", ndim);
162+
158163
// Clean up
159164
tiledb_ndrectangle_free(&ndrect);
160165
} else {

examples/cpp_api/current_domain.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ void print_current_domain(Context& ctx) {
121121
// Print datatype of range d1
122122
std::cout << "Current domain range 0 datatype: "
123123
<< tiledb::impl::type_to_str(ndrect.range_dtype("d1")) << std::endl;
124+
125+
// Print dim num
126+
std::cout << "Current domain dim num: " << ndrect.dim_num() << std::endl;
124127
}
125128

126129
void expand_current_domain(Context& ctx) {

test/src/test-cppapi-current-domain.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ TEST_CASE_METHOD(
9898
CHECK(range[0] == 30);
9999
CHECK(range[1] == 40);
100100

101-
// CHECK range dtype
101+
// Check range dtype
102102
CHECK(ndrect.range_dtype(0) == TILEDB_INT32);
103103
CHECK(ndrect.range_dtype("x") == TILEDB_INT32);
104+
105+
// Check ndim api
106+
CHECK(ndrect.dim_num() == 2);
104107
}
105108

106109
TEST_CASE_METHOD(

tiledb/api/c_api/ndrectangle/ndrectangle_api.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ capi_return_t tiledb_ndrectangle_get_dtype_from_name(
191191
return TILEDB_OK;
192192
}
193193

194+
capi_return_t tiledb_ndrectangle_get_dim_num(
195+
tiledb_ctx_t* ctx, tiledb_ndrectangle_t* ndr, uint32_t* ndim) {
196+
ensure_context_is_valid(ctx);
197+
ensure_handle_is_valid(ndr);
198+
ensure_output_pointer_is_valid(ndim);
199+
200+
*ndim = ndr->ndrectangle()->domain()->dim_num();
201+
202+
return TILEDB_OK;
203+
}
204+
194205
} // namespace tiledb::api
195206

196207
using tiledb::api::api_entry_context;
@@ -270,3 +281,12 @@ CAPI_INTERFACE(
270281
tiledb::api::tiledb_ndrectangle_get_dtype_from_name>(
271282
ctx, ndr, name, type);
272283
}
284+
285+
CAPI_INTERFACE(
286+
ndrectangle_get_dim_num,
287+
tiledb_ctx_t* ctx,
288+
tiledb_ndrectangle_t* ndr,
289+
uint32_t* ndim) {
290+
return api_entry_with_context<tiledb::api::tiledb_ndrectangle_get_dim_num>(
291+
ctx, ndr, ndim);
292+
}

tiledb/api/c_api/ndrectangle/ndrectangle_api_external_experimental.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,27 @@ TILEDB_EXPORT capi_return_t tiledb_ndrectangle_get_dtype_from_name(
245245
const char* name,
246246
tiledb_datatype_t* type) TILEDB_NOEXCEPT;
247247

248+
/**
249+
* Get the the number of dimensions of
250+
* the N-dimensional rectangle passed as argument
251+
*
252+
* **Example:**
253+
*
254+
* @code{.c}
255+
* uint32_t ndim;
256+
* tiledb_ndrectangle_get_dim_num(ctx, ndr, &ndim);
257+
* @endcode
258+
*
259+
* @param ctx The TileDB context
260+
* @param ndr The n-dimensional rectangle to be queried
261+
* @param ndim The number of dimensions to be returned
262+
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error.
263+
*/
264+
TILEDB_EXPORT capi_return_t tiledb_ndrectangle_get_dim_num(
265+
tiledb_ctx_t* ctx,
266+
tiledb_ndrectangle_t* ndr,
267+
uint32_t* ndim) TILEDB_NOEXCEPT;
268+
248269
#ifdef __cplusplus
249270
}
250271
#endif

tiledb/api/c_api/ndrectangle/test/unit_capi_ndrectangle.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ TEST_CASE_METHOD(
165165
tiledb_ndrectangle_get_dtype_from_name(ctx, ndr, "doesntexist", &dtype) ==
166166
TILEDB_ERR);
167167

168+
CHECK(
169+
tiledb_ndrectangle_get_dim_num(nullptr, nullptr, nullptr) ==
170+
TILEDB_INVALID_CONTEXT);
171+
CHECK(tiledb_ndrectangle_get_dim_num(ctx, nullptr, nullptr) == TILEDB_ERR);
172+
CHECK(tiledb_ndrectangle_get_dim_num(ctx, ndr, nullptr) == TILEDB_ERR);
173+
168174
REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK);
169175
}
170176

@@ -215,5 +221,9 @@ TEST_CASE_METHOD(
215221
TILEDB_OK);
216222
CHECK(dtype == TILEDB_UINT64);
217223

224+
uint32_t ndim;
225+
REQUIRE(tiledb_ndrectangle_get_dim_num(ctx, ndr, &ndim) == TILEDB_OK);
226+
CHECK(ndim == 2);
227+
218228
REQUIRE(tiledb_ndrectangle_free(&ndr) == TILEDB_OK);
219229
}

tiledb/sm/cpp_api/ndrectangle.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class NDRectangle {
284284

285285
return dtype;
286286
}
287+
287288
/**
288289
* Get the data type of the range by name
289290
*
@@ -300,6 +301,21 @@ class NDRectangle {
300301
return dtype;
301302
}
302303

304+
/**
305+
* Get the number of dimensions associated with the NDRectangle.
306+
*
307+
* @return The number of dimensions.
308+
*/
309+
uint32_t dim_num() {
310+
auto& ctx = ctx_.get();
311+
312+
uint32_t ndim;
313+
ctx.handle_error(
314+
tiledb_ndrectangle_get_dim_num(ctx.ptr().get(), ndrect_.get(), &ndim));
315+
316+
return ndim;
317+
}
318+
303319
private:
304320
/* ********************************* */
305321
/* PRIVATE ATTRIBUTES */

0 commit comments

Comments
 (0)