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