@@ -165,7 +165,7 @@ Character codes for data types:
165
165
Function name suffix naming convention:
166
166
167
167
``` text
168
- stdlib_ndarray_ <input_data_type>_<output_data_type>[_as_<callback_arg_data_type>_<callback_return_data_type>]
168
+ stdlib_ndarray_every_ <input_data_type>_<output_data_type>[_as_<callback_arg_data_type>_<callback_return_data_type>]
169
169
```
170
170
171
171
For example,
@@ -176,14 +176,30 @@ For example,
176
176
void stdlib_ndarray_every_d_x (...) {...}
177
177
```
178
178
179
+ is a function which accepts one double-precision floating-point input ndarray and one boolean output ndarray.
180
+
181
+ Function name suffix naming convention for applying a predicate function:
182
+
183
+ ```text
184
+ stdlib_ndarray_every_by_<input_data_type>_<output_data_type>[_as_<callback_arg_data_type>_<callback_return_data_type>]
185
+ ```
186
+
187
+ For example,
188
+
189
+ <!-- run-disable -->
190
+
191
+ ``` c
192
+ void stdlib_ndarray_every_by_d_x (...) {...}
193
+ ```
194
+
179
195
is a function which accepts one double-precision floating-point input ndarray and one boolean output ndarray. In other words, the suffix encodes the function type signature.
180
196
181
197
To support callbacks whose input arguments are of a different data type than the input ndarray data type, the naming convention supports appending an `as` suffix. For example,
182
198
183
199
<!-- run-disable -->
184
200
185
201
```c
186
- void stdlib_ndarray_every_f_x_as_d_x (...) {...}
202
+ void stdlib_ndarray_every_by_f_x_as_d_x (...) {...}
187
203
```
188
204
189
205
is a function which accepts one single-precision floating-point input ndarray and one boolean output ndarray. However, the callback accepts double-precision floating-point numbers. Accordingly, the input values need to be cast using the following conversion sequence
@@ -276,12 +292,13 @@ static bool fcn( const uint8_t x ) {
276
292
}
277
293
278
294
int main( void ) {
279
- // Define the ndarray data type:
280
- enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_UINT8;
295
+ // Define the ndarray data types:
296
+ enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8;
297
+ enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_BOOL;
281
298
282
299
// Create underlying byte arrays:
283
- uint8_t xbuf[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
284
- bool ybuf[] = { false };
300
+ uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
301
+ uint8_t ybuf[] = { 0 };
285
302
286
303
// Define the number of input array dimensions:
287
304
int64_t ndims = 3;
@@ -309,14 +326,14 @@ int main( void ) {
309
326
int64_t nsubmodes = 1;
310
327
311
328
// Create an input ndarray:
312
- struct ndarray *x = stdlib_ndarray_allocate( dtype , xbuf, ndims, shx, sx, ox, order, imode, nsubmodes, submodes );
329
+ struct ndarray *x = stdlib_ndarray_allocate( xdtype , xbuf, ndims, shx, sx, ox, order, imode, nsubmodes, submodes );
313
330
if ( x == NULL ) {
314
331
fprintf( stderr, "Error allocating memory.\n" );
315
332
exit( EXIT_FAILURE );
316
333
}
317
334
318
335
// Create an output ndarray:
319
- struct ndarray *y = stdlib_ndarray_allocate( dtype , ybuf, 0, shy, sy, oy, order, imode, nsubmodes, submodes );
336
+ struct ndarray *y = stdlib_ndarray_allocate( ydtype , ybuf, 0, shy, sy, oy, order, imode, nsubmodes, submodes );
320
337
if ( y == NULL ) {
321
338
fprintf( stderr, "Error allocating memory.\n" );
322
339
exit( EXIT_FAILURE );
@@ -326,7 +343,7 @@ int main( void ) {
326
343
struct ndarray *arrays[] = { x, y };
327
344
328
345
// Test elements:
329
- int8_t status = stdlib_ndarray_every_b_x ( arrays, (void *)fcn );
346
+ int8_t status = stdlib_ndarray_every_by_b_x ( arrays, (void *)fcn );
330
347
if ( status != 0 ) {
331
348
fprintf( stderr, "Error during computation.\n" );
332
349
exit( EXIT_FAILURE );
0 commit comments