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