Skip to content

Commit 5a1e80f

Browse files
committed
Add function to retrieve an ndarray data element specified by a byte array ptr
1 parent b9dc181 commit 5a1e80f

File tree

2 files changed

+29
-7
lines changed
  • lib/node_modules/@stdlib/ndarray/ctor

2 files changed

+29
-7
lines changed

lib/node_modules/@stdlib/ndarray/ctor/include/stdlib/ndarray/ctor.h

+5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ int8_t stdlib_ndarray_disable_flags( struct ndarray *arr, const int64_t flags );
263263
*/
264264
uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub );
265265

266+
/**
267+
* Returns an ndarray data element specified by a byte array pointer.
268+
*/
269+
int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out );
270+
266271
/**
267272
* Returns an ndarray data element.
268273
*/

lib/node_modules/@stdlib/ndarray/ctor/src/main.c

+24-7
Original file line numberDiff line numberDiff line change
@@ -330,23 +330,19 @@ uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub
330330
}
331331

332332
/**
333-
* Returns an ndarray data element.
333+
* Returns an ndarray data element specified by a byte array pointer.
334334
*
335335
* ## Notes
336336
*
337337
* - The function returns `-1` if unable to get an element and `0` otherwise.
338338
* - The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types.
339339
*
340340
* @param arr input ndarray
341-
* @param sub ndarray subscripts
341+
* @param idx byte array pointer to an ndarray data element
342342
* @param out output address
343343
* @return status code
344344
*/
345-
int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out ) {
346-
uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub );
347-
if ( idx == NULL ) {
348-
return -1;
349-
}
345+
int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out ) {
350346
switch ( arr->dtype ) {
351347
case STDLIB_NDARRAY_FLOAT64:
352348
*(double *)out = *(double *)idx;
@@ -382,6 +378,27 @@ int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *
382378
return -1;
383379
}
384380

381+
/**
382+
* Returns an ndarray data element.
383+
*
384+
* ## Notes
385+
*
386+
* - The function returns `-1` if unable to get an element and `0` otherwise.
387+
* - The function requires a `void` pointer for the output address `out` in order to provide a generic API supporting ndarrays having different data types.
388+
*
389+
* @param arr input ndarray
390+
* @param sub ndarray subscripts
391+
* @param out output address
392+
* @return status code
393+
*/
394+
int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out ) {
395+
uint8_t *idx = stdlib_ndarray_get_ptr( arr, sub );
396+
if ( idx == NULL ) {
397+
return -1;
398+
}
399+
return stdlib_ndarray_get_ptr_value( arr, idx, out );
400+
}
401+
385402
/**
386403
* Returns a double-precision floating-point ndarray data element.
387404
*

0 commit comments

Comments
 (0)