b_k.c (68566B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "stdlib/ndarray/base/unary/b_k.h" 20 #include "stdlib/ndarray/base/unary/typedefs.h" 21 #include "stdlib/ndarray/base/unary/macros.h" 22 #include "stdlib/ndarray/base/unary/dispatch_object.h" 23 #include "stdlib/ndarray/base/unary/dispatch.h" 24 #include "stdlib/ndarray/ctor.h" 25 #include <stdint.h> 26 27 /** 28 * Applies a unary callback accepting and returning unsigned 8-bit integers to a zero-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a zero-dimensional signed 16-bit integer output ndarray. 29 * 30 * ## Notes 31 * 32 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 33 * 34 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 35 * @param fcn callback 36 * @return status code 37 * 38 * @example 39 * #include "stdlib/ndarray/base/unary/b_k.h" 40 * #include "stdlib/ndarray/dtypes.h" 41 * #include "stdlib/ndarray/index_modes.h" 42 * #include "stdlib/ndarray/orders.h" 43 * #include "stdlib/ndarray/ctor.h" 44 * #include <stdint.h> 45 * #include <stdlib.h> 46 * #include <stdio.h> 47 * 48 * // Define the ndarray data types: 49 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 50 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 51 * 52 * // Create underlying byte arrays: 53 * uint8_t xbuf[] = { 1 }; 54 * uint8_t ybuf[] = { 0, 0 }; 55 * 56 * // Define the number of dimensions: 57 * int64_t ndims = 0; 58 * 59 * // Define the array shapes: 60 * int64_t shape[] = {}; 61 * 62 * // Define the strides: 63 * int64_t sx[] = { 0 }; 64 * int64_t sy[] = { 0 }; 65 * 66 * // Define the offsets: 67 * int64_t ox = 0; 68 * int64_t oy = 0; 69 * 70 * // Define the array order: 71 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 72 * 73 * // Specify the index mode: 74 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 75 * 76 * // Specify the subscript index modes: 77 * int8_t submodes[] = { imode }; 78 * int64_t nsubmodes = 1; 79 * 80 * // Create an input ndarray: 81 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 82 * if ( x == NULL ) { 83 * fprintf( stderr, "Error allocating memory.\n" ); 84 * exit( EXIT_FAILURE ); 85 * } 86 * 87 * // Create an output ndarray: 88 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 89 * if ( y == NULL ) { 90 * fprintf( stderr, "Error allocating memory.\n" ); 91 * exit( EXIT_FAILURE ); 92 * } 93 * 94 * // Create an array containing the ndarrays: 95 * struct ndarray *arrays[] = { x, y }; 96 * 97 * // Define a callback: 98 * uint8_t scale( const uint8_t x ) { 99 * return x + 10; 100 * } 101 * 102 * // Apply the callback: 103 * int8_t status = stdlib_ndarray_b_k_0d( arrays, (void *)scale ); 104 * if ( status != 0 ) { 105 * fprintf( stderr, "Error during computation.\n" ); 106 * exit( EXIT_FAILURE ); 107 * } 108 * 109 * // ... 110 * 111 * // Free allocated memory: 112 * stdlib_ndarray_free( x ); 113 * stdlib_ndarray_free( y ); 114 */ 115 int8_t stdlib_ndarray_b_k_0d( struct ndarray *arrays[], void *fcn ) { 116 uint8_t v; 117 int8_t status = stdlib_ndarray_iget_uint8( arrays[ 0 ], 0, &v ); 118 if ( status != 0 ) { 119 return -1; 120 } 121 typedef uint8_t func_type( const uint8_t x ); 122 func_type *f = (func_type *)fcn; 123 status = stdlib_ndarray_iset_int16( arrays[ 1 ], 0, (int16_t)f( v ) ); 124 if ( status != 0 ) { 125 return -1; 126 } 127 return 0; 128 } 129 130 /** 131 * Applies a unary callback accepting and returning unsigned 8-bit integers to a one-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a one-dimensional signed 16-bit integer output ndarray. 132 * 133 * ## Notes 134 * 135 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 136 * 137 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 138 * @param fcn callback 139 * @return status code 140 * 141 * @example 142 * #include "stdlib/ndarray/base/unary/b_k.h" 143 * #include "stdlib/ndarray/dtypes.h" 144 * #include "stdlib/ndarray/index_modes.h" 145 * #include "stdlib/ndarray/orders.h" 146 * #include "stdlib/ndarray/ctor.h" 147 * #include <stdint.h> 148 * #include <stdlib.h> 149 * #include <stdio.h> 150 * 151 * // Define the ndarray data types: 152 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 153 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 154 * 155 * // Create underlying byte arrays: 156 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 157 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 158 * 159 * // Define the number of dimensions: 160 * int64_t ndims = 1; 161 * 162 * // Define the array shapes: 163 * int64_t shape[] = { 2 }; 164 * 165 * // Define the strides: 166 * int64_t sx[] = { 1 }; 167 * int64_t sy[] = { 2 }; 168 * 169 * // Define the offsets: 170 * int64_t ox = 0; 171 * int64_t oy = 0; 172 * 173 * // Define the array order: 174 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 175 * 176 * // Specify the index mode: 177 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 178 * 179 * // Specify the subscript index modes: 180 * int8_t submodes[] = { imode }; 181 * int64_t nsubmodes = 1; 182 * 183 * // Create an input ndarray: 184 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 185 * if ( x == NULL ) { 186 * fprintf( stderr, "Error allocating memory.\n" ); 187 * exit( EXIT_FAILURE ); 188 * } 189 * 190 * // Create an output ndarray: 191 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 192 * if ( y == NULL ) { 193 * fprintf( stderr, "Error allocating memory.\n" ); 194 * exit( EXIT_FAILURE ); 195 * } 196 * 197 * // Create an array containing the ndarrays: 198 * struct ndarray *arrays[] = { x, y }; 199 * 200 * // Define a callback: 201 * uint8_t scale( const uint8_t x ) { 202 * return x + 10; 203 * } 204 * 205 * // Apply the callback: 206 * int8_t status = stdlib_ndarray_b_k_1d( arrays, (void *)scale ); 207 * if ( status != 0 ) { 208 * fprintf( stderr, "Error during computation.\n" ); 209 * exit( EXIT_FAILURE ); 210 * } 211 * 212 * // ... 213 * 214 * // Free allocated memory: 215 * stdlib_ndarray_free( x ); 216 * stdlib_ndarray_free( y ); 217 */ 218 int8_t stdlib_ndarray_b_k_1d( struct ndarray *arrays[], void *fcn ) { 219 typedef uint8_t func_type( const uint8_t x ); 220 func_type *f = (func_type *)fcn; 221 STDLIB_NDARRAY_UNARY_1D_LOOP_CLBK( uint8_t, int16_t ) 222 return 0; 223 } 224 225 /** 226 * Applies a unary callback accepting and returning unsigned 8-bit integers to a two-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a two-dimensional signed 16-bit integer output ndarray. 227 * 228 * ## Notes 229 * 230 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 231 * 232 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 233 * @param fcn callback 234 * @return status code 235 * 236 * @example 237 * #include "stdlib/ndarray/base/unary/b_k.h" 238 * #include "stdlib/ndarray/dtypes.h" 239 * #include "stdlib/ndarray/index_modes.h" 240 * #include "stdlib/ndarray/orders.h" 241 * #include "stdlib/ndarray/ctor.h" 242 * #include <stdint.h> 243 * #include <stdlib.h> 244 * #include <stdio.h> 245 * 246 * // Define the ndarray data types: 247 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 248 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 249 * 250 * // Create underlying byte arrays: 251 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 252 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 253 * 254 * // Define the number of dimensions: 255 * int64_t ndims = 2; 256 * 257 * // Define the array shapes: 258 * int64_t shape[] = { 2, 2 }; 259 * 260 * // Define the strides: 261 * int64_t sx[] = { 2, 1 }; 262 * int64_t sy[] = { 4, 2 }; 263 * 264 * // Define the offsets: 265 * int64_t ox = 0; 266 * int64_t oy = 0; 267 * 268 * // Define the array order: 269 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 270 * 271 * // Specify the index mode: 272 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 273 * 274 * // Specify the subscript index modes: 275 * int8_t submodes[] = { imode }; 276 * int64_t nsubmodes = 1; 277 * 278 * // Create an input ndarray: 279 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 280 * if ( x == NULL ) { 281 * fprintf( stderr, "Error allocating memory.\n" ); 282 * exit( EXIT_FAILURE ); 283 * } 284 * 285 * // Create an output ndarray: 286 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 287 * if ( y == NULL ) { 288 * fprintf( stderr, "Error allocating memory.\n" ); 289 * exit( EXIT_FAILURE ); 290 * } 291 * 292 * // Create an array containing the ndarrays: 293 * struct ndarray *arrays[] = { x, y }; 294 * 295 * // Define a callback: 296 * uint8_t scale( const uint8_t x ) { 297 * return x + 10; 298 * } 299 * 300 * // Apply the callback: 301 * int8_t status = stdlib_ndarray_b_k_2d( arrays, (void *)scale ); 302 * if ( status != 0 ) { 303 * fprintf( stderr, "Error during computation.\n" ); 304 * exit( EXIT_FAILURE ); 305 * } 306 * 307 * // ... 308 * 309 * // Free allocated memory: 310 * stdlib_ndarray_free( x ); 311 * stdlib_ndarray_free( y ); 312 */ 313 int8_t stdlib_ndarray_b_k_2d( struct ndarray *arrays[], void *fcn ) { 314 typedef uint8_t func_type( const uint8_t x ); 315 func_type *f = (func_type *)fcn; 316 STDLIB_NDARRAY_UNARY_2D_LOOP_CLBK( uint8_t, int16_t ) 317 return 0; 318 } 319 320 /** 321 * Applies a unary callback accepting and returning unsigned 8-bit integers to a two-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a two-dimensional signed 16-bit integer output ndarray. 322 * 323 * ## Notes 324 * 325 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 326 * 327 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 328 * @param fcn callback 329 * @return status code 330 * 331 * @example 332 * #include "stdlib/ndarray/base/unary/b_k.h" 333 * #include "stdlib/ndarray/dtypes.h" 334 * #include "stdlib/ndarray/index_modes.h" 335 * #include "stdlib/ndarray/orders.h" 336 * #include "stdlib/ndarray/ctor.h" 337 * #include <stdint.h> 338 * #include <stdlib.h> 339 * #include <stdio.h> 340 * 341 * // Define the ndarray data types: 342 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 343 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 344 * 345 * // Create underlying byte arrays: 346 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 347 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 348 * 349 * // Define the number of dimensions: 350 * int64_t ndims = 2; 351 * 352 * // Define the array shapes: 353 * int64_t shape[] = { 2, 2 }; 354 * 355 * // Define the strides: 356 * int64_t sx[] = { 2, 1 }; 357 * int64_t sy[] = { 4, 2 }; 358 * 359 * // Define the offsets: 360 * int64_t ox = 0; 361 * int64_t oy = 0; 362 * 363 * // Define the array order: 364 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 365 * 366 * // Specify the index mode: 367 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 368 * 369 * // Specify the subscript index modes: 370 * int8_t submodes[] = { imode }; 371 * int64_t nsubmodes = 1; 372 * 373 * // Create an input ndarray: 374 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 375 * if ( x == NULL ) { 376 * fprintf( stderr, "Error allocating memory.\n" ); 377 * exit( EXIT_FAILURE ); 378 * } 379 * 380 * // Create an output ndarray: 381 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 382 * if ( y == NULL ) { 383 * fprintf( stderr, "Error allocating memory.\n" ); 384 * exit( EXIT_FAILURE ); 385 * } 386 * 387 * // Create an array containing the ndarrays: 388 * struct ndarray *arrays[] = { x, y }; 389 * 390 * // Define a callback: 391 * uint8_t scale( const uint8_t x ) { 392 * return x + 10; 393 * } 394 * 395 * // Apply the callback: 396 * int8_t status = stdlib_ndarray_b_k_2d_blocked( arrays, (void *)scale ); 397 * if ( status != 0 ) { 398 * fprintf( stderr, "Error during computation.\n" ); 399 * exit( EXIT_FAILURE ); 400 * } 401 * 402 * // ... 403 * 404 * // Free allocated memory: 405 * stdlib_ndarray_free( x ); 406 * stdlib_ndarray_free( y ); 407 */ 408 int8_t stdlib_ndarray_b_k_2d_blocked( struct ndarray *arrays[], void *fcn ) { 409 typedef uint8_t func_type( const uint8_t x ); 410 func_type *f = (func_type *)fcn; 411 STDLIB_NDARRAY_UNARY_2D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 412 return 0; 413 } 414 415 /** 416 * Applies a unary callback accepting and returning unsigned 8-bit integers to a three-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a three-dimensional signed 16-bit integer output ndarray. 417 * 418 * ## Notes 419 * 420 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 421 * 422 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 423 * @param fcn callback 424 * @return status code 425 * 426 * @example 427 * #include "stdlib/ndarray/base/unary/b_k.h" 428 * #include "stdlib/ndarray/dtypes.h" 429 * #include "stdlib/ndarray/index_modes.h" 430 * #include "stdlib/ndarray/orders.h" 431 * #include "stdlib/ndarray/ctor.h" 432 * #include <stdint.h> 433 * #include <stdlib.h> 434 * #include <stdio.h> 435 * 436 * // Define the ndarray data types: 437 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 438 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 439 * 440 * // Create underlying byte arrays: 441 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 442 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 443 * 444 * // Define the number of dimensions: 445 * int64_t ndims = 3; 446 * 447 * // Define the array shapes: 448 * int64_t shape[] = { 2, 2, 2 }; 449 * 450 * // Define the strides: 451 * int64_t sx[] = { 4, 2, 1 }; 452 * int64_t sy[] = { 8, 4, 2 }; 453 * 454 * // Define the offsets: 455 * int64_t ox = 0; 456 * int64_t oy = 0; 457 * 458 * // Define the array order: 459 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 460 * 461 * // Specify the index mode: 462 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 463 * 464 * // Specify the subscript index modes: 465 * int8_t submodes[] = { imode }; 466 * int64_t nsubmodes = 1; 467 * 468 * // Create an input ndarray: 469 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 470 * if ( x == NULL ) { 471 * fprintf( stderr, "Error allocating memory.\n" ); 472 * exit( EXIT_FAILURE ); 473 * } 474 * 475 * // Create an output ndarray: 476 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 477 * if ( y == NULL ) { 478 * fprintf( stderr, "Error allocating memory.\n" ); 479 * exit( EXIT_FAILURE ); 480 * } 481 * 482 * // Create an array containing the ndarrays: 483 * struct ndarray *arrays[] = { x, y }; 484 * 485 * // Define a callback: 486 * uint8_t scale( const uint8_t x ) { 487 * return x + 10; 488 * } 489 * 490 * // Apply the callback: 491 * int8_t status = stdlib_ndarray_b_k_3d( arrays, (void *)scale ); 492 * if ( status != 0 ) { 493 * fprintf( stderr, "Error during computation.\n" ); 494 * exit( EXIT_FAILURE ); 495 * } 496 * 497 * // ... 498 * 499 * // Free allocated memory: 500 * stdlib_ndarray_free( x ); 501 * stdlib_ndarray_free( y ); 502 */ 503 int8_t stdlib_ndarray_b_k_3d( struct ndarray *arrays[], void *fcn ) { 504 typedef uint8_t func_type( const uint8_t x ); 505 func_type *f = (func_type *)fcn; 506 STDLIB_NDARRAY_UNARY_3D_LOOP_CLBK( uint8_t, int16_t ) 507 return 0; 508 } 509 510 /** 511 * Applies a unary callback accepting and returning unsigned 8-bit integers to a three-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a three-dimensional signed 16-bit integer output ndarray. 512 * 513 * ## Notes 514 * 515 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 516 * 517 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 518 * @param fcn callback 519 * @return status code 520 * 521 * @example 522 * #include "stdlib/ndarray/base/unary/b_k.h" 523 * #include "stdlib/ndarray/dtypes.h" 524 * #include "stdlib/ndarray/index_modes.h" 525 * #include "stdlib/ndarray/orders.h" 526 * #include "stdlib/ndarray/ctor.h" 527 * #include <stdint.h> 528 * #include <stdlib.h> 529 * #include <stdio.h> 530 * 531 * // Define the ndarray data types: 532 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 533 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 534 * 535 * // Create underlying byte arrays: 536 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 537 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 538 * 539 * // Define the number of dimensions: 540 * int64_t ndims = 3; 541 * 542 * // Define the array shapes: 543 * int64_t shape[] = { 2, 2, 2 }; 544 * 545 * // Define the strides: 546 * int64_t sx[] = { 4, 2, 1 }; 547 * int64_t sy[] = { 8, 4, 2 }; 548 * 549 * // Define the offsets: 550 * int64_t ox = 0; 551 * int64_t oy = 0; 552 * 553 * // Define the array order: 554 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 555 * 556 * // Specify the index mode: 557 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 558 * 559 * // Specify the subscript index modes: 560 * int8_t submodes[] = { imode }; 561 * int64_t nsubmodes = 1; 562 * 563 * // Create an input ndarray: 564 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 565 * if ( x == NULL ) { 566 * fprintf( stderr, "Error allocating memory.\n" ); 567 * exit( EXIT_FAILURE ); 568 * } 569 * 570 * // Create an output ndarray: 571 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 572 * if ( y == NULL ) { 573 * fprintf( stderr, "Error allocating memory.\n" ); 574 * exit( EXIT_FAILURE ); 575 * } 576 * 577 * // Create an array containing the ndarrays: 578 * struct ndarray *arrays[] = { x, y }; 579 * 580 * // Define a callback: 581 * uint8_t scale( const uint8_t x ) { 582 * return x + 10; 583 * } 584 * 585 * // Apply the callback: 586 * int8_t status = stdlib_ndarray_b_k_3d_blocked( arrays, (void *)scale ); 587 * if ( status != 0 ) { 588 * fprintf( stderr, "Error during computation.\n" ); 589 * exit( EXIT_FAILURE ); 590 * } 591 * 592 * // ... 593 * 594 * // Free allocated memory: 595 * stdlib_ndarray_free( x ); 596 * stdlib_ndarray_free( y ); 597 */ 598 int8_t stdlib_ndarray_b_k_3d_blocked( struct ndarray *arrays[], void *fcn ) { 599 typedef uint8_t func_type( const uint8_t x ); 600 func_type *f = (func_type *)fcn; 601 STDLIB_NDARRAY_UNARY_3D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 602 return 0; 603 } 604 605 /** 606 * Applies a unary callback accepting and returning unsigned 8-bit integers to a four-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a four-dimensional signed 16-bit integer output ndarray. 607 * 608 * ## Notes 609 * 610 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 611 * 612 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 613 * @param fcn callback 614 * @return status code 615 * 616 * @example 617 * #include "stdlib/ndarray/base/unary/b_k.h" 618 * #include "stdlib/ndarray/dtypes.h" 619 * #include "stdlib/ndarray/index_modes.h" 620 * #include "stdlib/ndarray/orders.h" 621 * #include "stdlib/ndarray/ctor.h" 622 * #include <stdint.h> 623 * #include <stdlib.h> 624 * #include <stdio.h> 625 * 626 * // Define the ndarray data types: 627 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 628 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 629 * 630 * // Create underlying byte arrays: 631 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 632 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 633 * 634 * // Define the number of dimensions: 635 * int64_t ndims = 4; 636 * 637 * // Define the array shapes: 638 * int64_t shape[] = { 1, 2, 2, 2 }; 639 * 640 * // Define the strides: 641 * int64_t sx[] = { 4, 4, 2, 1 }; 642 * int64_t sy[] = { 8, 8, 4, 2 }; 643 * 644 * // Define the offsets: 645 * int64_t ox = 0; 646 * int64_t oy = 0; 647 * 648 * // Define the array order: 649 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 650 * 651 * // Specify the index mode: 652 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 653 * 654 * // Specify the subscript index modes: 655 * int8_t submodes[] = { imode }; 656 * int64_t nsubmodes = 1; 657 * 658 * // Create an input ndarray: 659 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 660 * if ( x == NULL ) { 661 * fprintf( stderr, "Error allocating memory.\n" ); 662 * exit( EXIT_FAILURE ); 663 * } 664 * 665 * // Create an output ndarray: 666 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 667 * if ( y == NULL ) { 668 * fprintf( stderr, "Error allocating memory.\n" ); 669 * exit( EXIT_FAILURE ); 670 * } 671 * 672 * // Create an array containing the ndarrays: 673 * struct ndarray *arrays[] = { x, y }; 674 * 675 * // Define a callback: 676 * uint8_t scale( const uint8_t x ) { 677 * return x + 10; 678 * } 679 * 680 * // Apply the callback: 681 * int8_t status = stdlib_ndarray_b_k_4d( arrays, (void *)scale ); 682 * if ( status != 0 ) { 683 * fprintf( stderr, "Error during computation.\n" ); 684 * exit( EXIT_FAILURE ); 685 * } 686 * 687 * // ... 688 * 689 * // Free allocated memory: 690 * stdlib_ndarray_free( x ); 691 * stdlib_ndarray_free( y ); 692 */ 693 int8_t stdlib_ndarray_b_k_4d( struct ndarray *arrays[], void *fcn ) { 694 typedef uint8_t func_type( const uint8_t x ); 695 func_type *f = (func_type *)fcn; 696 STDLIB_NDARRAY_UNARY_4D_LOOP_CLBK( uint8_t, int16_t ) 697 return 0; 698 } 699 700 /** 701 * Applies a unary callback accepting and returning unsigned 8-bit integers to a four-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a four-dimensional signed 16-bit integer output ndarray. 702 * 703 * ## Notes 704 * 705 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 706 * 707 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 708 * @param fcn callback 709 * @return status code 710 * 711 * @example 712 * #include "stdlib/ndarray/base/unary/b_k.h" 713 * #include "stdlib/ndarray/dtypes.h" 714 * #include "stdlib/ndarray/index_modes.h" 715 * #include "stdlib/ndarray/orders.h" 716 * #include "stdlib/ndarray/ctor.h" 717 * #include <stdint.h> 718 * #include <stdlib.h> 719 * #include <stdio.h> 720 * 721 * // Define the ndarray data types: 722 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 723 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 724 * 725 * // Create underlying byte arrays: 726 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 727 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 728 * 729 * // Define the number of dimensions: 730 * int64_t ndims = 4; 731 * 732 * // Define the array shapes: 733 * int64_t shape[] = { 1, 2, 2, 2 }; 734 * 735 * // Define the strides: 736 * int64_t sx[] = { 4, 4, 2, 1 }; 737 * int64_t sy[] = { 8, 8, 4, 2 }; 738 * 739 * // Define the offsets: 740 * int64_t ox = 0; 741 * int64_t oy = 0; 742 * 743 * // Define the array order: 744 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 745 * 746 * // Specify the index mode: 747 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 748 * 749 * // Specify the subscript index modes: 750 * int8_t submodes[] = { imode }; 751 * int64_t nsubmodes = 1; 752 * 753 * // Create an input ndarray: 754 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 755 * if ( x == NULL ) { 756 * fprintf( stderr, "Error allocating memory.\n" ); 757 * exit( EXIT_FAILURE ); 758 * } 759 * 760 * // Create an output ndarray: 761 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 762 * if ( y == NULL ) { 763 * fprintf( stderr, "Error allocating memory.\n" ); 764 * exit( EXIT_FAILURE ); 765 * } 766 * 767 * // Create an array containing the ndarrays: 768 * struct ndarray *arrays[] = { x, y }; 769 * 770 * // Define a callback: 771 * uint8_t scale( const uint8_t x ) { 772 * return x + 10; 773 * } 774 * 775 * // Apply the callback: 776 * int8_t status = stdlib_ndarray_b_k_4d_blocked( arrays, (void *)scale ); 777 * if ( status != 0 ) { 778 * fprintf( stderr, "Error during computation.\n" ); 779 * exit( EXIT_FAILURE ); 780 * } 781 * 782 * // ... 783 * 784 * // Free allocated memory: 785 * stdlib_ndarray_free( x ); 786 * stdlib_ndarray_free( y ); 787 */ 788 int8_t stdlib_ndarray_b_k_4d_blocked( struct ndarray *arrays[], void *fcn ) { 789 typedef uint8_t func_type( const uint8_t x ); 790 func_type *f = (func_type *)fcn; 791 STDLIB_NDARRAY_UNARY_4D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 792 return 0; 793 } 794 795 /** 796 * Applies a unary callback accepting and returning unsigned 8-bit integers to a five-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a five-dimensional signed 16-bit integer output ndarray. 797 * 798 * ## Notes 799 * 800 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 801 * 802 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 803 * @param fcn callback 804 * @return status code 805 * 806 * @example 807 * #include "stdlib/ndarray/base/unary/b_k.h" 808 * #include "stdlib/ndarray/dtypes.h" 809 * #include "stdlib/ndarray/index_modes.h" 810 * #include "stdlib/ndarray/orders.h" 811 * #include "stdlib/ndarray/ctor.h" 812 * #include <stdint.h> 813 * #include <stdlib.h> 814 * #include <stdio.h> 815 * 816 * // Define the ndarray data types: 817 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 818 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 819 * 820 * // Create underlying byte arrays: 821 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 822 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 823 * 824 * // Define the number of dimensions: 825 * int64_t ndims = 5; 826 * 827 * // Define the array shapes: 828 * int64_t shape[] = { 1, 1, 2, 2, 2 }; 829 * 830 * // Define the strides: 831 * int64_t sx[] = { 4, 4, 4, 2, 1 }; 832 * int64_t sy[] = { 8, 8, 8, 4, 2 }; 833 * 834 * // Define the offsets: 835 * int64_t ox = 0; 836 * int64_t oy = 0; 837 * 838 * // Define the array order: 839 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 840 * 841 * // Specify the index mode: 842 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 843 * 844 * // Specify the subscript index modes: 845 * int8_t submodes[] = { imode }; 846 * int64_t nsubmodes = 1; 847 * 848 * // Create an input ndarray: 849 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 850 * if ( x == NULL ) { 851 * fprintf( stderr, "Error allocating memory.\n" ); 852 * exit( EXIT_FAILURE ); 853 * } 854 * 855 * // Create an output ndarray: 856 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 857 * if ( y == NULL ) { 858 * fprintf( stderr, "Error allocating memory.\n" ); 859 * exit( EXIT_FAILURE ); 860 * } 861 * 862 * // Create an array containing the ndarrays: 863 * struct ndarray *arrays[] = { x, y }; 864 * 865 * // Define a callback: 866 * uint8_t scale( const uint8_t x ) { 867 * return x + 10; 868 * } 869 * 870 * // Apply the callback: 871 * int8_t status = stdlib_ndarray_b_k_5d( arrays, (void *)scale ); 872 * if ( status != 0 ) { 873 * fprintf( stderr, "Error during computation.\n" ); 874 * exit( EXIT_FAILURE ); 875 * } 876 * 877 * // ... 878 * 879 * // Free allocated memory: 880 * stdlib_ndarray_free( x ); 881 * stdlib_ndarray_free( y ); 882 */ 883 int8_t stdlib_ndarray_b_k_5d( struct ndarray *arrays[], void *fcn ) { 884 typedef uint8_t func_type( const uint8_t x ); 885 func_type *f = (func_type *)fcn; 886 STDLIB_NDARRAY_UNARY_5D_LOOP_CLBK( uint8_t, int16_t ) 887 return 0; 888 } 889 890 /** 891 * Applies a unary callback accepting and returning unsigned 8-bit integers to a five-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a five-dimensional signed 16-bit integer output ndarray. 892 * 893 * ## Notes 894 * 895 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 896 * 897 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 898 * @param fcn callback 899 * @return status code 900 * 901 * @example 902 * #include "stdlib/ndarray/base/unary/b_k.h" 903 * #include "stdlib/ndarray/dtypes.h" 904 * #include "stdlib/ndarray/index_modes.h" 905 * #include "stdlib/ndarray/orders.h" 906 * #include "stdlib/ndarray/ctor.h" 907 * #include <stdint.h> 908 * #include <stdlib.h> 909 * #include <stdio.h> 910 * 911 * // Define the ndarray data types: 912 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 913 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 914 * 915 * // Create underlying byte arrays: 916 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 917 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 918 * 919 * // Define the number of dimensions: 920 * int64_t ndims = 5; 921 * 922 * // Define the array shapes: 923 * int64_t shape[] = { 1, 1, 2, 2, 2 }; 924 * 925 * // Define the strides: 926 * int64_t sx[] = { 4, 4, 4, 2, 1 }; 927 * int64_t sy[] = { 8, 8, 8, 4, 2 }; 928 * 929 * // Define the offsets: 930 * int64_t ox = 0; 931 * int64_t oy = 0; 932 * 933 * // Define the array order: 934 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 935 * 936 * // Specify the index mode: 937 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 938 * 939 * // Specify the subscript index modes: 940 * int8_t submodes[] = { imode }; 941 * int64_t nsubmodes = 1; 942 * 943 * // Create an input ndarray: 944 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 945 * if ( x == NULL ) { 946 * fprintf( stderr, "Error allocating memory.\n" ); 947 * exit( EXIT_FAILURE ); 948 * } 949 * 950 * // Create an output ndarray: 951 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 952 * if ( y == NULL ) { 953 * fprintf( stderr, "Error allocating memory.\n" ); 954 * exit( EXIT_FAILURE ); 955 * } 956 * 957 * // Create an array containing the ndarrays: 958 * struct ndarray *arrays[] = { x, y }; 959 * 960 * // Define a callback: 961 * uint8_t scale( const uint8_t x ) { 962 * return x + 10; 963 * } 964 * 965 * // Apply the callback: 966 * int8_t status = stdlib_ndarray_b_k_5d_blocked( arrays, (void *)scale ); 967 * if ( status != 0 ) { 968 * fprintf( stderr, "Error during computation.\n" ); 969 * exit( EXIT_FAILURE ); 970 * } 971 * 972 * // ... 973 * 974 * // Free allocated memory: 975 * stdlib_ndarray_free( x ); 976 * stdlib_ndarray_free( y ); 977 */ 978 int8_t stdlib_ndarray_b_k_5d_blocked( struct ndarray *arrays[], void *fcn ) { 979 typedef uint8_t func_type( const uint8_t x ); 980 func_type *f = (func_type *)fcn; 981 STDLIB_NDARRAY_UNARY_5D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 982 return 0; 983 } 984 985 /** 986 * Applies a unary callback accepting and returning unsigned 8-bit integers to a six-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a six-dimensional signed 16-bit integer output ndarray. 987 * 988 * ## Notes 989 * 990 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 991 * 992 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 993 * @param fcn callback 994 * @return status code 995 * 996 * @example 997 * #include "stdlib/ndarray/base/unary/b_k.h" 998 * #include "stdlib/ndarray/dtypes.h" 999 * #include "stdlib/ndarray/index_modes.h" 1000 * #include "stdlib/ndarray/orders.h" 1001 * #include "stdlib/ndarray/ctor.h" 1002 * #include <stdint.h> 1003 * #include <stdlib.h> 1004 * #include <stdio.h> 1005 * 1006 * // Define the ndarray data types: 1007 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1008 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1009 * 1010 * // Create underlying byte arrays: 1011 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1012 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1013 * 1014 * // Define the number of dimensions: 1015 * int64_t ndims = 6; 1016 * 1017 * // Define the array shapes: 1018 * int64_t shape[] = { 1, 1, 1, 2, 2, 2 }; 1019 * 1020 * // Define the strides: 1021 * int64_t sx[] = { 4, 4, 4, 4, 2, 1 }; 1022 * int64_t sy[] = { 8, 8, 8, 8, 4, 2 }; 1023 * 1024 * // Define the offsets: 1025 * int64_t ox = 0; 1026 * int64_t oy = 0; 1027 * 1028 * // Define the array order: 1029 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1030 * 1031 * // Specify the index mode: 1032 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1033 * 1034 * // Specify the subscript index modes: 1035 * int8_t submodes[] = { imode }; 1036 * int64_t nsubmodes = 1; 1037 * 1038 * // Create an input ndarray: 1039 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1040 * if ( x == NULL ) { 1041 * fprintf( stderr, "Error allocating memory.\n" ); 1042 * exit( EXIT_FAILURE ); 1043 * } 1044 * 1045 * // Create an output ndarray: 1046 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1047 * if ( y == NULL ) { 1048 * fprintf( stderr, "Error allocating memory.\n" ); 1049 * exit( EXIT_FAILURE ); 1050 * } 1051 * 1052 * // Create an array containing the ndarrays: 1053 * struct ndarray *arrays[] = { x, y }; 1054 * 1055 * // Define a callback: 1056 * uint8_t scale( const uint8_t x ) { 1057 * return x + 10; 1058 * } 1059 * 1060 * // Apply the callback: 1061 * int8_t status = stdlib_ndarray_b_k_6d( arrays, (void *)scale ); 1062 * if ( status != 0 ) { 1063 * fprintf( stderr, "Error during computation.\n" ); 1064 * exit( EXIT_FAILURE ); 1065 * } 1066 * 1067 * // ... 1068 * 1069 * // Free allocated memory: 1070 * stdlib_ndarray_free( x ); 1071 * stdlib_ndarray_free( y ); 1072 */ 1073 int8_t stdlib_ndarray_b_k_6d( struct ndarray *arrays[], void *fcn ) { 1074 typedef uint8_t func_type( const uint8_t x ); 1075 func_type *f = (func_type *)fcn; 1076 STDLIB_NDARRAY_UNARY_6D_LOOP_CLBK( uint8_t, int16_t ) 1077 return 0; 1078 } 1079 1080 /** 1081 * Applies a unary callback accepting and returning unsigned 8-bit integers to a six-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a six-dimensional signed 16-bit integer output ndarray. 1082 * 1083 * ## Notes 1084 * 1085 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1086 * 1087 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1088 * @param fcn callback 1089 * @return status code 1090 * 1091 * @example 1092 * #include "stdlib/ndarray/base/unary/b_k.h" 1093 * #include "stdlib/ndarray/dtypes.h" 1094 * #include "stdlib/ndarray/index_modes.h" 1095 * #include "stdlib/ndarray/orders.h" 1096 * #include "stdlib/ndarray/ctor.h" 1097 * #include <stdint.h> 1098 * #include <stdlib.h> 1099 * #include <stdio.h> 1100 * 1101 * // Define the ndarray data types: 1102 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1103 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1104 * 1105 * // Create underlying byte arrays: 1106 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1107 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1108 * 1109 * // Define the number of dimensions: 1110 * int64_t ndims = 6; 1111 * 1112 * // Define the array shapes: 1113 * int64_t shape[] = { 1, 1, 1, 2, 2, 2 }; 1114 * 1115 * // Define the strides: 1116 * int64_t sx[] = { 4, 4, 4, 4, 2, 1 }; 1117 * int64_t sy[] = { 8, 8, 8, 8, 4, 2 }; 1118 * 1119 * // Define the offsets: 1120 * int64_t ox = 0; 1121 * int64_t oy = 0; 1122 * 1123 * // Define the array order: 1124 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1125 * 1126 * // Specify the index mode: 1127 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1128 * 1129 * // Specify the subscript index modes: 1130 * int8_t submodes[] = { imode }; 1131 * int64_t nsubmodes = 1; 1132 * 1133 * // Create an input ndarray: 1134 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1135 * if ( x == NULL ) { 1136 * fprintf( stderr, "Error allocating memory.\n" ); 1137 * exit( EXIT_FAILURE ); 1138 * } 1139 * 1140 * // Create an output ndarray: 1141 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1142 * if ( y == NULL ) { 1143 * fprintf( stderr, "Error allocating memory.\n" ); 1144 * exit( EXIT_FAILURE ); 1145 * } 1146 * 1147 * // Create an array containing the ndarrays: 1148 * struct ndarray *arrays[] = { x, y }; 1149 * 1150 * // Define a callback: 1151 * uint8_t scale( const uint8_t x ) { 1152 * return x + 10; 1153 * } 1154 * 1155 * // Apply the callback: 1156 * int8_t status = stdlib_ndarray_b_k_6d_blocked( arrays, (void *)scale ); 1157 * if ( status != 0 ) { 1158 * fprintf( stderr, "Error during computation.\n" ); 1159 * exit( EXIT_FAILURE ); 1160 * } 1161 * 1162 * // ... 1163 * 1164 * // Free allocated memory: 1165 * stdlib_ndarray_free( x ); 1166 * stdlib_ndarray_free( y ); 1167 */ 1168 int8_t stdlib_ndarray_b_k_6d_blocked( struct ndarray *arrays[], void *fcn ) { 1169 typedef uint8_t func_type( const uint8_t x ); 1170 func_type *f = (func_type *)fcn; 1171 STDLIB_NDARRAY_UNARY_6D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 1172 return 0; 1173 } 1174 1175 /** 1176 * Applies a unary callback accepting and returning unsigned 8-bit integers to a seven-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a seven-dimensional signed 16-bit integer output ndarray. 1177 * 1178 * ## Notes 1179 * 1180 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1181 * 1182 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1183 * @param fcn callback 1184 * @return status code 1185 * 1186 * @example 1187 * #include "stdlib/ndarray/base/unary/b_k.h" 1188 * #include "stdlib/ndarray/dtypes.h" 1189 * #include "stdlib/ndarray/index_modes.h" 1190 * #include "stdlib/ndarray/orders.h" 1191 * #include "stdlib/ndarray/ctor.h" 1192 * #include <stdint.h> 1193 * #include <stdlib.h> 1194 * #include <stdio.h> 1195 * 1196 * // Define the ndarray data types: 1197 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1198 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1199 * 1200 * // Create underlying byte arrays: 1201 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1202 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1203 * 1204 * // Define the number of dimensions: 1205 * int64_t ndims = 7; 1206 * 1207 * // Define the array shapes: 1208 * int64_t shape[] = { 1, 1, 1, 1, 2, 2, 2 }; 1209 * 1210 * // Define the strides: 1211 * int64_t sx[] = { 4, 4, 4, 4, 4, 2, 1 }; 1212 * int64_t sy[] = { 8, 8, 8, 8, 8, 4, 2 }; 1213 * 1214 * // Define the offsets: 1215 * int64_t ox = 0; 1216 * int64_t oy = 0; 1217 * 1218 * // Define the array order: 1219 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1220 * 1221 * // Specify the index mode: 1222 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1223 * 1224 * // Specify the subscript index modes: 1225 * int8_t submodes[] = { imode }; 1226 * int64_t nsubmodes = 1; 1227 * 1228 * // Create an input ndarray: 1229 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1230 * if ( x == NULL ) { 1231 * fprintf( stderr, "Error allocating memory.\n" ); 1232 * exit( EXIT_FAILURE ); 1233 * } 1234 * 1235 * // Create an output ndarray: 1236 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1237 * if ( y == NULL ) { 1238 * fprintf( stderr, "Error allocating memory.\n" ); 1239 * exit( EXIT_FAILURE ); 1240 * } 1241 * 1242 * // Create an array containing the ndarrays: 1243 * struct ndarray *arrays[] = { x, y }; 1244 * 1245 * // Define a callback: 1246 * uint8_t scale( const uint8_t x ) { 1247 * return x + 10; 1248 * } 1249 * 1250 * // Apply the callback: 1251 * int8_t status = stdlib_ndarray_b_k_7d( arrays, (void *)scale ); 1252 * if ( status != 0 ) { 1253 * fprintf( stderr, "Error during computation.\n" ); 1254 * exit( EXIT_FAILURE ); 1255 * } 1256 * 1257 * // ... 1258 * 1259 * // Free allocated memory: 1260 * stdlib_ndarray_free( x ); 1261 * stdlib_ndarray_free( y ); 1262 */ 1263 int8_t stdlib_ndarray_b_k_7d( struct ndarray *arrays[], void *fcn ) { 1264 typedef uint8_t func_type( const uint8_t x ); 1265 func_type *f = (func_type *)fcn; 1266 STDLIB_NDARRAY_UNARY_7D_LOOP_CLBK( uint8_t, int16_t ) 1267 return 0; 1268 } 1269 1270 /** 1271 * Applies a unary callback accepting and returning unsigned 8-bit integers to a seven-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a seven-dimensional signed 16-bit integer output ndarray. 1272 * 1273 * ## Notes 1274 * 1275 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1276 * 1277 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1278 * @param fcn callback 1279 * @return status code 1280 * 1281 * @example 1282 * #include "stdlib/ndarray/base/unary/b_k.h" 1283 * #include "stdlib/ndarray/dtypes.h" 1284 * #include "stdlib/ndarray/index_modes.h" 1285 * #include "stdlib/ndarray/orders.h" 1286 * #include "stdlib/ndarray/ctor.h" 1287 * #include <stdint.h> 1288 * #include <stdlib.h> 1289 * #include <stdio.h> 1290 * 1291 * // Define the ndarray data types: 1292 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1293 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1294 * 1295 * // Create underlying byte arrays: 1296 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1297 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1298 * 1299 * // Define the number of dimensions: 1300 * int64_t ndims = 7; 1301 * 1302 * // Define the array shapes: 1303 * int64_t shape[] = { 1, 1, 1, 1, 2, 2, 2 }; 1304 * 1305 * // Define the strides: 1306 * int64_t sx[] = { 4, 4, 4, 4, 4, 2, 1 }; 1307 * int64_t sy[] = { 8, 8, 8, 8, 8, 4, 2 }; 1308 * 1309 * // Define the offsets: 1310 * int64_t ox = 0; 1311 * int64_t oy = 0; 1312 * 1313 * // Define the array order: 1314 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1315 * 1316 * // Specify the index mode: 1317 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1318 * 1319 * // Specify the subscript index modes: 1320 * int8_t submodes[] = { imode }; 1321 * int64_t nsubmodes = 1; 1322 * 1323 * // Create an input ndarray: 1324 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1325 * if ( x == NULL ) { 1326 * fprintf( stderr, "Error allocating memory.\n" ); 1327 * exit( EXIT_FAILURE ); 1328 * } 1329 * 1330 * // Create an output ndarray: 1331 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1332 * if ( y == NULL ) { 1333 * fprintf( stderr, "Error allocating memory.\n" ); 1334 * exit( EXIT_FAILURE ); 1335 * } 1336 * 1337 * // Create an array containing the ndarrays: 1338 * struct ndarray *arrays[] = { x, y }; 1339 * 1340 * // Define a callback: 1341 * uint8_t scale( const uint8_t x ) { 1342 * return x + 10; 1343 * } 1344 * 1345 * // Apply the callback: 1346 * int8_t status = stdlib_ndarray_b_k_7d_blocked( arrays, (void *)scale ); 1347 * if ( status != 0 ) { 1348 * fprintf( stderr, "Error during computation.\n" ); 1349 * exit( EXIT_FAILURE ); 1350 * } 1351 * 1352 * // ... 1353 * 1354 * // Free allocated memory: 1355 * stdlib_ndarray_free( x ); 1356 * stdlib_ndarray_free( y ); 1357 */ 1358 int8_t stdlib_ndarray_b_k_7d_blocked( struct ndarray *arrays[], void *fcn ) { 1359 typedef uint8_t func_type( const uint8_t x ); 1360 func_type *f = (func_type *)fcn; 1361 STDLIB_NDARRAY_UNARY_7D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 1362 return 0; 1363 } 1364 1365 /** 1366 * Applies a unary callback accepting and returning unsigned 8-bit integers to an eight-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in an eight-dimensional signed 16-bit integer output ndarray. 1367 * 1368 * ## Notes 1369 * 1370 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1371 * 1372 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1373 * @param fcn callback 1374 * @return status code 1375 * 1376 * @example 1377 * #include "stdlib/ndarray/base/unary/b_k.h" 1378 * #include "stdlib/ndarray/dtypes.h" 1379 * #include "stdlib/ndarray/index_modes.h" 1380 * #include "stdlib/ndarray/orders.h" 1381 * #include "stdlib/ndarray/ctor.h" 1382 * #include <stdint.h> 1383 * #include <stdlib.h> 1384 * #include <stdio.h> 1385 * 1386 * // Define the ndarray data types: 1387 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1388 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1389 * 1390 * // Create underlying byte arrays: 1391 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1392 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1393 * 1394 * // Define the number of dimensions: 1395 * int64_t ndims = 8; 1396 * 1397 * // Define the array shapes: 1398 * int64_t shape[] = { 1, 1, 1, 1, 1, 2, 2, 2 }; 1399 * 1400 * // Define the strides: 1401 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 2, 1 }; 1402 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 4, 2 }; 1403 * 1404 * // Define the offsets: 1405 * int64_t ox = 0; 1406 * int64_t oy = 0; 1407 * 1408 * // Define the array order: 1409 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1410 * 1411 * // Specify the index mode: 1412 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1413 * 1414 * // Specify the subscript index modes: 1415 * int8_t submodes[] = { imode }; 1416 * int64_t nsubmodes = 1; 1417 * 1418 * // Create an input ndarray: 1419 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1420 * if ( x == NULL ) { 1421 * fprintf( stderr, "Error allocating memory.\n" ); 1422 * exit( EXIT_FAILURE ); 1423 * } 1424 * 1425 * // Create an output ndarray: 1426 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1427 * if ( y == NULL ) { 1428 * fprintf( stderr, "Error allocating memory.\n" ); 1429 * exit( EXIT_FAILURE ); 1430 * } 1431 * 1432 * // Create an array containing the ndarrays: 1433 * struct ndarray *arrays[] = { x, y }; 1434 * 1435 * // Define a callback: 1436 * uint8_t scale( const uint8_t x ) { 1437 * return x + 10; 1438 * } 1439 * 1440 * // Apply the callback: 1441 * int8_t status = stdlib_ndarray_b_k_8d( arrays, (void *)scale ); 1442 * if ( status != 0 ) { 1443 * fprintf( stderr, "Error during computation.\n" ); 1444 * exit( EXIT_FAILURE ); 1445 * } 1446 * 1447 * // ... 1448 * 1449 * // Free allocated memory: 1450 * stdlib_ndarray_free( x ); 1451 * stdlib_ndarray_free( y ); 1452 */ 1453 int8_t stdlib_ndarray_b_k_8d( struct ndarray *arrays[], void *fcn ) { 1454 typedef uint8_t func_type( const uint8_t x ); 1455 func_type *f = (func_type *)fcn; 1456 STDLIB_NDARRAY_UNARY_8D_LOOP_CLBK( uint8_t, int16_t ) 1457 return 0; 1458 } 1459 1460 /** 1461 * Applies a unary callback accepting and returning unsigned 8-bit integers to an eight-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in an eight-dimensional signed 16-bit integer output ndarray. 1462 * 1463 * ## Notes 1464 * 1465 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1466 * 1467 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1468 * @param fcn callback 1469 * @return status code 1470 * 1471 * @example 1472 * #include "stdlib/ndarray/base/unary/b_k.h" 1473 * #include "stdlib/ndarray/dtypes.h" 1474 * #include "stdlib/ndarray/index_modes.h" 1475 * #include "stdlib/ndarray/orders.h" 1476 * #include "stdlib/ndarray/ctor.h" 1477 * #include <stdint.h> 1478 * #include <stdlib.h> 1479 * #include <stdio.h> 1480 * 1481 * // Define the ndarray data types: 1482 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1483 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1484 * 1485 * // Create underlying byte arrays: 1486 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1487 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1488 * 1489 * // Define the number of dimensions: 1490 * int64_t ndims = 8; 1491 * 1492 * // Define the array shapes: 1493 * int64_t shape[] = { 1, 1, 1, 1, 1, 2, 2, 2 }; 1494 * 1495 * // Define the strides: 1496 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 2, 1 }; 1497 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 4, 2 }; 1498 * 1499 * // Define the offsets: 1500 * int64_t ox = 0; 1501 * int64_t oy = 0; 1502 * 1503 * // Define the array order: 1504 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1505 * 1506 * // Specify the index mode: 1507 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1508 * 1509 * // Specify the subscript index modes: 1510 * int8_t submodes[] = { imode }; 1511 * int64_t nsubmodes = 1; 1512 * 1513 * // Create an input ndarray: 1514 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1515 * if ( x == NULL ) { 1516 * fprintf( stderr, "Error allocating memory.\n" ); 1517 * exit( EXIT_FAILURE ); 1518 * } 1519 * 1520 * // Create an output ndarray: 1521 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1522 * if ( y == NULL ) { 1523 * fprintf( stderr, "Error allocating memory.\n" ); 1524 * exit( EXIT_FAILURE ); 1525 * } 1526 * 1527 * // Create an array containing the ndarrays: 1528 * struct ndarray *arrays[] = { x, y }; 1529 * 1530 * // Define a callback: 1531 * uint8_t scale( const uint8_t x ) { 1532 * return x + 10; 1533 * } 1534 * 1535 * // Apply the callback: 1536 * int8_t status = stdlib_ndarray_b_k_8d_blocked( arrays, (void *)scale ); 1537 * if ( status != 0 ) { 1538 * fprintf( stderr, "Error during computation.\n" ); 1539 * exit( EXIT_FAILURE ); 1540 * } 1541 * 1542 * // ... 1543 * 1544 * // Free allocated memory: 1545 * stdlib_ndarray_free( x ); 1546 * stdlib_ndarray_free( y ); 1547 */ 1548 int8_t stdlib_ndarray_b_k_8d_blocked( struct ndarray *arrays[], void *fcn ) { 1549 typedef uint8_t func_type( const uint8_t x ); 1550 func_type *f = (func_type *)fcn; 1551 STDLIB_NDARRAY_UNARY_8D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 1552 return 0; 1553 } 1554 1555 /** 1556 * Applies a unary callback accepting and returning unsigned 8-bit integers to a nine-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a nine-dimensional signed 16-bit integer output ndarray. 1557 * 1558 * ## Notes 1559 * 1560 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1561 * 1562 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1563 * @param fcn callback 1564 * @return status code 1565 * 1566 * @example 1567 * #include "stdlib/ndarray/base/unary/b_k.h" 1568 * #include "stdlib/ndarray/dtypes.h" 1569 * #include "stdlib/ndarray/index_modes.h" 1570 * #include "stdlib/ndarray/orders.h" 1571 * #include "stdlib/ndarray/ctor.h" 1572 * #include <stdint.h> 1573 * #include <stdlib.h> 1574 * #include <stdio.h> 1575 * 1576 * // Define the ndarray data types: 1577 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1578 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1579 * 1580 * // Create underlying byte arrays: 1581 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1582 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1583 * 1584 * // Define the number of dimensions: 1585 * int64_t ndims = 9; 1586 * 1587 * // Define the array shapes: 1588 * int64_t shape[] = { 1, 1, 1, 1, 1, 1, 2, 2, 2 }; 1589 * 1590 * // Define the strides: 1591 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 4, 2, 1 }; 1592 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 8, 4, 2 }; 1593 * 1594 * // Define the offsets: 1595 * int64_t ox = 0; 1596 * int64_t oy = 0; 1597 * 1598 * // Define the array order: 1599 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1600 * 1601 * // Specify the index mode: 1602 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1603 * 1604 * // Specify the subscript index modes: 1605 * int8_t submodes[] = { imode }; 1606 * int64_t nsubmodes = 1; 1607 * 1608 * // Create an input ndarray: 1609 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1610 * if ( x == NULL ) { 1611 * fprintf( stderr, "Error allocating memory.\n" ); 1612 * exit( EXIT_FAILURE ); 1613 * } 1614 * 1615 * // Create an output ndarray: 1616 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1617 * if ( y == NULL ) { 1618 * fprintf( stderr, "Error allocating memory.\n" ); 1619 * exit( EXIT_FAILURE ); 1620 * } 1621 * 1622 * // Create an array containing the ndarrays: 1623 * struct ndarray *arrays[] = { x, y }; 1624 * 1625 * // Define a callback: 1626 * uint8_t scale( const uint8_t x ) { 1627 * return x + 10; 1628 * } 1629 * 1630 * // Apply the callback: 1631 * int8_t status = stdlib_ndarray_b_k_9d( arrays, (void *)scale ); 1632 * if ( status != 0 ) { 1633 * fprintf( stderr, "Error during computation.\n" ); 1634 * exit( EXIT_FAILURE ); 1635 * } 1636 * 1637 * // ... 1638 * 1639 * // Free allocated memory: 1640 * stdlib_ndarray_free( x ); 1641 * stdlib_ndarray_free( y ); 1642 */ 1643 int8_t stdlib_ndarray_b_k_9d( struct ndarray *arrays[], void *fcn ) { 1644 typedef uint8_t func_type( const uint8_t x ); 1645 func_type *f = (func_type *)fcn; 1646 STDLIB_NDARRAY_UNARY_9D_LOOP_CLBK( uint8_t, int16_t ) 1647 return 0; 1648 } 1649 1650 /** 1651 * Applies a unary callback accepting and returning unsigned 8-bit integers to a nine-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a nine-dimensional signed 16-bit integer output ndarray. 1652 * 1653 * ## Notes 1654 * 1655 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1656 * 1657 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1658 * @param fcn callback 1659 * @return status code 1660 * 1661 * @example 1662 * #include "stdlib/ndarray/base/unary/b_k.h" 1663 * #include "stdlib/ndarray/dtypes.h" 1664 * #include "stdlib/ndarray/index_modes.h" 1665 * #include "stdlib/ndarray/orders.h" 1666 * #include "stdlib/ndarray/ctor.h" 1667 * #include <stdint.h> 1668 * #include <stdlib.h> 1669 * #include <stdio.h> 1670 * 1671 * // Define the ndarray data types: 1672 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1673 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1674 * 1675 * // Create underlying byte arrays: 1676 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1677 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1678 * 1679 * // Define the number of dimensions: 1680 * int64_t ndims = 9; 1681 * 1682 * // Define the array shapes: 1683 * int64_t shape[] = { 1, 1, 1, 1, 1, 1, 2, 2, 2 }; 1684 * 1685 * // Define the strides: 1686 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 4, 2, 1 }; 1687 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 8, 4, 2 }; 1688 * 1689 * // Define the offsets: 1690 * int64_t ox = 0; 1691 * int64_t oy = 0; 1692 * 1693 * // Define the array order: 1694 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1695 * 1696 * // Specify the index mode: 1697 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1698 * 1699 * // Specify the subscript index modes: 1700 * int8_t submodes[] = { imode }; 1701 * int64_t nsubmodes = 1; 1702 * 1703 * // Create an input ndarray: 1704 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1705 * if ( x == NULL ) { 1706 * fprintf( stderr, "Error allocating memory.\n" ); 1707 * exit( EXIT_FAILURE ); 1708 * } 1709 * 1710 * // Create an output ndarray: 1711 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1712 * if ( y == NULL ) { 1713 * fprintf( stderr, "Error allocating memory.\n" ); 1714 * exit( EXIT_FAILURE ); 1715 * } 1716 * 1717 * // Create an array containing the ndarrays: 1718 * struct ndarray *arrays[] = { x, y }; 1719 * 1720 * // Define a callback: 1721 * uint8_t scale( const uint8_t x ) { 1722 * return x + 10; 1723 * } 1724 * 1725 * // Apply the callback: 1726 * int8_t status = stdlib_ndarray_b_k_9d_blocked( arrays, (void *)scale ); 1727 * if ( status != 0 ) { 1728 * fprintf( stderr, "Error during computation.\n" ); 1729 * exit( EXIT_FAILURE ); 1730 * } 1731 * 1732 * // ... 1733 * 1734 * // Free allocated memory: 1735 * stdlib_ndarray_free( x ); 1736 * stdlib_ndarray_free( y ); 1737 */ 1738 int8_t stdlib_ndarray_b_k_9d_blocked( struct ndarray *arrays[], void *fcn ) { 1739 typedef uint8_t func_type( const uint8_t x ); 1740 func_type *f = (func_type *)fcn; 1741 STDLIB_NDARRAY_UNARY_9D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 1742 return 0; 1743 } 1744 1745 /** 1746 * Applies a unary callback accepting and returning unsigned 8-bit integers to a ten-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a ten-dimensional signed 16-bit integer output ndarray. 1747 * 1748 * ## Notes 1749 * 1750 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1751 * 1752 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1753 * @param fcn callback 1754 * @return status code 1755 * 1756 * @example 1757 * #include "stdlib/ndarray/base/unary/b_k.h" 1758 * #include "stdlib/ndarray/dtypes.h" 1759 * #include "stdlib/ndarray/index_modes.h" 1760 * #include "stdlib/ndarray/orders.h" 1761 * #include "stdlib/ndarray/ctor.h" 1762 * #include <stdint.h> 1763 * #include <stdlib.h> 1764 * #include <stdio.h> 1765 * 1766 * // Define the ndarray data types: 1767 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1768 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1769 * 1770 * // Create underlying byte arrays: 1771 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1772 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1773 * 1774 * // Define the number of dimensions: 1775 * int64_t ndims = 10; 1776 * 1777 * // Define the array shapes: 1778 * int64_t shape[] = { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 }; 1779 * 1780 * // Define the strides: 1781 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 }; 1782 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 8, 8, 4, 2 }; 1783 * 1784 * // Define the offsets: 1785 * int64_t ox = 0; 1786 * int64_t oy = 0; 1787 * 1788 * // Define the array order: 1789 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1790 * 1791 * // Specify the index mode: 1792 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1793 * 1794 * // Specify the subscript index modes: 1795 * int8_t submodes[] = { imode }; 1796 * int64_t nsubmodes = 1; 1797 * 1798 * // Create an input ndarray: 1799 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1800 * if ( x == NULL ) { 1801 * fprintf( stderr, "Error allocating memory.\n" ); 1802 * exit( EXIT_FAILURE ); 1803 * } 1804 * 1805 * // Create an output ndarray: 1806 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1807 * if ( y == NULL ) { 1808 * fprintf( stderr, "Error allocating memory.\n" ); 1809 * exit( EXIT_FAILURE ); 1810 * } 1811 * 1812 * // Create an array containing the ndarrays: 1813 * struct ndarray *arrays[] = { x, y }; 1814 * 1815 * // Define a callback: 1816 * uint8_t scale( const uint8_t x ) { 1817 * return x + 10; 1818 * } 1819 * 1820 * // Apply the callback: 1821 * int8_t status = stdlib_ndarray_b_k_10d( arrays, (void *)scale ); 1822 * if ( status != 0 ) { 1823 * fprintf( stderr, "Error during computation.\n" ); 1824 * exit( EXIT_FAILURE ); 1825 * } 1826 * 1827 * // ... 1828 * 1829 * // Free allocated memory: 1830 * stdlib_ndarray_free( x ); 1831 * stdlib_ndarray_free( y ); 1832 */ 1833 int8_t stdlib_ndarray_b_k_10d( struct ndarray *arrays[], void *fcn ) { 1834 typedef uint8_t func_type( const uint8_t x ); 1835 func_type *f = (func_type *)fcn; 1836 STDLIB_NDARRAY_UNARY_10D_LOOP_CLBK( uint8_t, int16_t ) 1837 return 0; 1838 } 1839 1840 /** 1841 * Applies a unary callback accepting and returning unsigned 8-bit integers to a ten-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a ten-dimensional signed 16-bit integer output ndarray. 1842 * 1843 * ## Notes 1844 * 1845 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1846 * 1847 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1848 * @param fcn callback 1849 * @return status code 1850 * 1851 * @example 1852 * #include "stdlib/ndarray/base/unary/b_k.h" 1853 * #include "stdlib/ndarray/dtypes.h" 1854 * #include "stdlib/ndarray/index_modes.h" 1855 * #include "stdlib/ndarray/orders.h" 1856 * #include "stdlib/ndarray/ctor.h" 1857 * #include <stdint.h> 1858 * #include <stdlib.h> 1859 * #include <stdio.h> 1860 * 1861 * // Define the ndarray data types: 1862 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1863 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1864 * 1865 * // Create underlying byte arrays: 1866 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1867 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1868 * 1869 * // Define the number of dimensions: 1870 * int64_t ndims = 10; 1871 * 1872 * // Define the array shapes: 1873 * int64_t shape[] = { 1, 1, 1, 1, 1, 1, 1, 2, 2, 2 }; 1874 * 1875 * // Define the strides: 1876 * int64_t sx[] = { 4, 4, 4, 4, 4, 4, 4, 4, 2, 1 }; 1877 * int64_t sy[] = { 8, 8, 8, 8, 8, 8, 8, 8, 4, 2 }; 1878 * 1879 * // Define the offsets: 1880 * int64_t ox = 0; 1881 * int64_t oy = 0; 1882 * 1883 * // Define the array order: 1884 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1885 * 1886 * // Specify the index mode: 1887 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1888 * 1889 * // Specify the subscript index modes: 1890 * int8_t submodes[] = { imode }; 1891 * int64_t nsubmodes = 1; 1892 * 1893 * // Create an input ndarray: 1894 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1895 * if ( x == NULL ) { 1896 * fprintf( stderr, "Error allocating memory.\n" ); 1897 * exit( EXIT_FAILURE ); 1898 * } 1899 * 1900 * // Create an output ndarray: 1901 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1902 * if ( y == NULL ) { 1903 * fprintf( stderr, "Error allocating memory.\n" ); 1904 * exit( EXIT_FAILURE ); 1905 * } 1906 * 1907 * // Create an array containing the ndarrays: 1908 * struct ndarray *arrays[] = { x, y }; 1909 * 1910 * // Define a callback: 1911 * uint8_t scale( const uint8_t x ) { 1912 * return x + 10; 1913 * } 1914 * 1915 * // Apply the callback: 1916 * int8_t status = stdlib_ndarray_b_k_10d_blocked( arrays, (void *)scale ); 1917 * if ( status != 0 ) { 1918 * fprintf( stderr, "Error during computation.\n" ); 1919 * exit( EXIT_FAILURE ); 1920 * } 1921 * 1922 * // ... 1923 * 1924 * // Free allocated memory: 1925 * stdlib_ndarray_free( x ); 1926 * stdlib_ndarray_free( y ); 1927 */ 1928 int8_t stdlib_ndarray_b_k_10d_blocked( struct ndarray *arrays[], void *fcn ) { 1929 typedef uint8_t func_type( const uint8_t x ); 1930 func_type *f = (func_type *)fcn; 1931 STDLIB_NDARRAY_UNARY_10D_BLOCKED_LOOP_CLBK( uint8_t, int16_t ) 1932 return 0; 1933 } 1934 1935 /** 1936 * Applies a unary callback accepting and returning unsigned 8-bit integers to an n-dimensional unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in an n-dimensional signed 16-bit integer output ndarray. 1937 * 1938 * ## Notes 1939 * 1940 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 1941 * 1942 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 1943 * @param fcn callback 1944 * @return status code 1945 * 1946 * @example 1947 * #include "stdlib/ndarray/base/unary/b_k.h" 1948 * #include "stdlib/ndarray/dtypes.h" 1949 * #include "stdlib/ndarray/index_modes.h" 1950 * #include "stdlib/ndarray/orders.h" 1951 * #include "stdlib/ndarray/ctor.h" 1952 * #include <stdint.h> 1953 * #include <stdlib.h> 1954 * #include <stdio.h> 1955 * 1956 * // Define the ndarray data types: 1957 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 1958 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 1959 * 1960 * // Create underlying byte arrays: 1961 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 1962 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1963 * 1964 * // Define the number of dimensions: 1965 * int64_t ndims = 3; 1966 * 1967 * // Define the array shapes: 1968 * int64_t shape[] = { 2, 2, 2 }; 1969 * 1970 * // Define the strides: 1971 * int64_t sx[] = { 4, 2, 1 }; 1972 * int64_t sy[] = { 8, 4, 2 }; 1973 * 1974 * // Define the offsets: 1975 * int64_t ox = 0; 1976 * int64_t oy = 0; 1977 * 1978 * // Define the array order: 1979 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 1980 * 1981 * // Specify the index mode: 1982 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 1983 * 1984 * // Specify the subscript index modes: 1985 * int8_t submodes[] = { imode }; 1986 * int64_t nsubmodes = 1; 1987 * 1988 * // Create an input ndarray: 1989 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 1990 * if ( x == NULL ) { 1991 * fprintf( stderr, "Error allocating memory.\n" ); 1992 * exit( EXIT_FAILURE ); 1993 * } 1994 * 1995 * // Create an output ndarray: 1996 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 1997 * if ( y == NULL ) { 1998 * fprintf( stderr, "Error allocating memory.\n" ); 1999 * exit( EXIT_FAILURE ); 2000 * } 2001 * 2002 * // Create an array containing the ndarrays: 2003 * struct ndarray *arrays[] = { x, y }; 2004 * 2005 * // Define a callback: 2006 * uint8_t scale( const uint8_t x ) { 2007 * return x + 10; 2008 * } 2009 * 2010 * // Apply the callback: 2011 * int8_t status = stdlib_ndarray_b_k_nd( arrays, (void *)scale ); 2012 * if ( status != 0 ) { 2013 * fprintf( stderr, "Error during computation.\n" ); 2014 * exit( EXIT_FAILURE ); 2015 * } 2016 * 2017 * // ... 2018 * 2019 * // Free allocated memory: 2020 * stdlib_ndarray_free( x ); 2021 * stdlib_ndarray_free( y ); 2022 */ 2023 int8_t stdlib_ndarray_b_k_nd( struct ndarray *arrays[], void *fcn ) { 2024 typedef uint8_t func_type( const uint8_t x ); 2025 func_type *f = (func_type *)fcn; 2026 STDLIB_NDARRAY_UNARY_ND_LOOP_CLBK( uint8_t, int16_t ) 2027 return 0; 2028 } 2029 2030 // Define a list of unary ndarray functions: 2031 static ndarrayUnaryFcn functions[] = { 2032 stdlib_ndarray_b_k_0d, 2033 stdlib_ndarray_b_k_1d, 2034 stdlib_ndarray_b_k_2d, 2035 stdlib_ndarray_b_k_3d, 2036 stdlib_ndarray_b_k_4d, 2037 stdlib_ndarray_b_k_5d, 2038 stdlib_ndarray_b_k_6d, 2039 stdlib_ndarray_b_k_7d, 2040 stdlib_ndarray_b_k_8d, 2041 stdlib_ndarray_b_k_9d, 2042 stdlib_ndarray_b_k_10d, 2043 stdlib_ndarray_b_k_nd 2044 }; 2045 2046 // Define a list of unary ndarray functions implementing loop blocking... 2047 static ndarrayUnaryFcn blocked_functions[] = { 2048 stdlib_ndarray_b_k_2d_blocked, 2049 stdlib_ndarray_b_k_3d_blocked, 2050 stdlib_ndarray_b_k_4d_blocked, 2051 stdlib_ndarray_b_k_5d_blocked, 2052 stdlib_ndarray_b_k_6d_blocked, 2053 stdlib_ndarray_b_k_7d_blocked, 2054 stdlib_ndarray_b_k_8d_blocked, 2055 stdlib_ndarray_b_k_9d_blocked, 2056 stdlib_ndarray_b_k_10d_blocked 2057 }; 2058 2059 // Create a unary function dispatch object: 2060 static const struct ndarrayUnaryDispatchObject obj = { 2061 // Array containing unary ndarray functions: 2062 functions, 2063 2064 // Number of unary ndarray functions: 2065 12, 2066 2067 // Array containing unary ndarray functions using loop blocking: 2068 blocked_functions, 2069 2070 // Number of unary ndarray functions using loop blocking: 2071 9 2072 }; 2073 2074 /** 2075 * Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer input ndarray, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a signed 16-bit integer output ndarray. 2076 * 2077 * ## Notes 2078 * 2079 * - If successful, the functions returns `0`; otherwise, the function returns an error code. 2080 * 2081 * @param arrays array whose first element is a pointer to an input ndarray and whose last element is a pointer to an output ndarray 2082 * @param fcn callback 2083 * @return status code 2084 * 2085 * @example 2086 * #include "stdlib/ndarray/base/unary/b_k.h" 2087 * #include "stdlib/ndarray/dtypes.h" 2088 * #include "stdlib/ndarray/index_modes.h" 2089 * #include "stdlib/ndarray/orders.h" 2090 * #include "stdlib/ndarray/ctor.h" 2091 * #include <stdint.h> 2092 * #include <stdlib.h> 2093 * #include <stdio.h> 2094 * 2095 * // Define the ndarray data types: 2096 * enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_UINT8; 2097 * enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_INT16; 2098 * 2099 * // Create underlying byte arrays: 2100 * uint8_t xbuf[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 2101 * uint8_t ybuf[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2102 * 2103 * // Define the number of dimensions: 2104 * int64_t ndims = 2; 2105 * 2106 * // Define the array shapes: 2107 * int64_t shape[] = { 2, 2 }; 2108 * 2109 * // Define the strides: 2110 * int64_t sx[] = { 2, 1 }; 2111 * int64_t sy[] = { 4, 2 }; 2112 * 2113 * // Define the offsets: 2114 * int64_t ox = 0; 2115 * int64_t oy = 0; 2116 * 2117 * // Define the array order: 2118 * enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 2119 * 2120 * // Specify the index mode: 2121 * enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 2122 * 2123 * // Specify the subscript index modes: 2124 * int8_t submodes[] = { imode }; 2125 * int64_t nsubmodes = 1; 2126 * 2127 * // Create an input ndarray: 2128 * struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shape, sx, ox, order, imode, nsubmodes, submodes ); 2129 * if ( x == NULL ) { 2130 * fprintf( stderr, "Error allocating memory.\n" ); 2131 * exit( EXIT_FAILURE ); 2132 * } 2133 * 2134 * // Create an output ndarray: 2135 * struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, ndims, shape, sy, oy, order, imode, nsubmodes, submodes ); 2136 * if ( y == NULL ) { 2137 * fprintf( stderr, "Error allocating memory.\n" ); 2138 * exit( EXIT_FAILURE ); 2139 * } 2140 * 2141 * // Create an array containing the ndarrays: 2142 * struct ndarray *arrays[] = { x, y }; 2143 * 2144 * // Define a callback: 2145 * uint8_t scale( const uint8_t x ) { 2146 * return x + 10; 2147 * } 2148 * 2149 * // Apply the callback: 2150 * int8_t status = stdlib_ndarray_b_k( arrays, (void *)scale ); 2151 * if ( status != 0 ) { 2152 * fprintf( stderr, "Error during computation.\n" ); 2153 * exit( EXIT_FAILURE ); 2154 * } 2155 * 2156 * // ... 2157 * 2158 * // Free allocated memory: 2159 * stdlib_ndarray_free( x ); 2160 * stdlib_ndarray_free( y ); 2161 */ 2162 int8_t stdlib_ndarray_b_k( struct ndarray *arrays[], void *fcn ) { 2163 return stdlib_ndarray_unary_dispatch( &obj, arrays, fcn ); 2164 }