README.md (124515B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Unary 22 23 > Apply a unary callback to elements in a strided input array and assign results to elements in a strided output array. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var unary = require( '@stdlib/strided/base/unary' ); 37 ``` 38 39 #### unary( arrays, shape, strides, fcn ) 40 41 Applies a unary callback to elements in a strided input array and assigns results to elements in a strided output array. 42 43 ```javascript 44 var Float64Array = require( '@stdlib/array/float64' ); 45 var abs = require( '@stdlib/math/base/special/abs' ); 46 47 var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); 48 49 // Compute the absolute values in-place: 50 unary( [ x, x ], [ x.length ], [ 1, 1 ], abs ); 51 // x => <Float64Array>[ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ] 52 ``` 53 54 The function accepts the following arguments: 55 56 - **arrays**: array-like object containing one strided input array and one strided output array. 57 - **shape**: array-like object containing a single element, the number of indexed elements. 58 - **strides**: array-like object containing the stride lengths for the strided input and output arrays. 59 - **fcn**: unary function to apply. 60 61 The `shape` and `strides` parameters determine which elements in the strided input and output arrays are accessed at runtime. For example, to index every other value in the strided input array and to index the first `N` elements of the strided output array in reverse order, 62 63 ```javascript 64 var Float64Array = require( '@stdlib/array/float64' ); 65 var abs = require( '@stdlib/math/base/special/abs' ); 66 67 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] ); 68 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 69 70 var N = 3; 71 72 unary( [ x, y ], [ N ], [ 2, -1 ], abs ); 73 // y => <Float64Array>[ 5.0, 3.0, 1.0, 0.0, 0.0, 0.0 ] 74 ``` 75 76 Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. 77 78 ```javascript 79 var Float64Array = require( '@stdlib/array/float64' ); 80 var abs = require( '@stdlib/math/base/special/abs' ); 81 82 // Initial arrays... 83 var x0 = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] ); 84 var y0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 85 86 // Create offset views... 87 var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element 88 var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element 89 90 var N = 3; 91 92 unary( [ x1, y1 ], [ N ], [ -2, 1 ], abs ); 93 // y0 => <Float64Array>[ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ] 94 ``` 95 96 #### unary.ndarray( arrays, shape, strides, offsets, fcn ) 97 98 Applies a unary callback to elements in a strided input array and assigns results to elements in a strided output array using alternative indexing semantics. 99 100 ```javascript 101 var Float64Array = require( '@stdlib/array/float64' ); 102 var abs = require( '@stdlib/math/base/special/abs' ); 103 104 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); 105 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 106 107 unary.ndarray( [ x, y ], [ x.length ], [ 1, 1 ], [ 0, 0 ], abs ); 108 // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ] 109 ``` 110 111 The function accepts the following additional arguments: 112 113 - **offsets**: array-like object containing the starting indices (i.e., index offsets) for the strided input and output arrays. 114 115 While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsets` parameter supports indexing semantics based on starting indices. For example, to index every other value in the strided input array starting from the second value and to index the last `N` elements in the strided output array, 116 117 ```javascript 118 var Float64Array = require( '@stdlib/array/float64' ); 119 var abs = require( '@stdlib/math/base/special/abs' ); 120 121 var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] ); 122 var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 123 124 var N = 3; 125 126 unary.ndarray( [ x, y ], [ N ], [ 2, -1 ], [ 1, y.length-1 ], abs ); 127 // y => <Float64Array>[ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ] 128 ``` 129 130 </section> 131 132 <!-- /.usage --> 133 134 <section class="notes"> 135 136 </section> 137 138 <!-- /.notes --> 139 140 <section class="examples"> 141 142 ## Examples 143 144 <!-- eslint no-undef: "error" --> 145 146 ```javascript 147 var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; 148 var filledarray = require( '@stdlib/array/filled' ); 149 var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); 150 var unary = require( '@stdlib/strided/base/unary' ); 151 152 function add10( x ) { 153 return x + 10; 154 } 155 156 var N = 10; 157 158 var x = filledarray( 0.0, N, 'generic' ); 159 gfillBy( x.length, x, 1, discreteUniform( -100, 100 ) ); 160 console.log( x ); 161 162 var y = filledarray( 0.0, N, 'generic' ); 163 console.log( y ); 164 165 var shape = [ N ]; 166 var strides = [ 1, -1 ]; 167 var offsets = [ 0, N-1 ]; 168 169 unary.ndarray( [ x, y ], shape, strides, offsets, add10 ); 170 console.log( y ); 171 ``` 172 173 </section> 174 175 <!-- /.examples --> 176 177 <!-- C interface documentation. --> 178 179 * * * 180 181 <section class="c"> 182 183 ## C APIs 184 185 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 186 187 <section class="intro"> 188 189 Character codes for data types: 190 191 - **d**: `float64` (double-precision floating-point number). 192 - **f**: `float32` (single-precision floating-point number). 193 - **s**: `int8` (signed 8-bit integer). 194 - **b**: `uint8` (unsigned 8-bit integer). 195 - **k**: `int16` (signed 16-bit integer). 196 - **t**: `uint16` (unsigned 16-bit integer). 197 - **i**: `int32` (signed 32-bit integer). 198 - **u**: `uint32` (unsigned 32-bit integer). 199 - **l**: `int64` (signed 64-bit integer). 200 - **v**: `uint64` (unsigned 64-bit integer). 201 202 Function name suffix naming convention: 203 204 ```text 205 stdlib_strided_<input_data_type>_<output_data_type>[_as_<callback_arg_data_type>_<callback_return_data_type>] 206 ``` 207 208 For example, 209 210 ```c 211 void stdlib_strided_d_d(...) {...} 212 ``` 213 214 is a function which accepts one double-precision floating-point strided input array and one double-precision floating-point strided output array. In other words, the suffix encodes the function type signature. 215 216 To support callbacks whose input arguments and/or return values are of a different data type than the strided input and/or output array data types, the naming convention supports appending an `as` suffix. For example, 217 218 ```c 219 void stdlib_strided_f_f_as_d_d(...) {...} 220 ``` 221 222 is a function which accepts one single-precision floating-point strided input array and one single-precision floating-point strided output array. However, the callback accepts and returns double-precision floating-point numbers. Accordingly, the input and output values need to be cast using the following conversion sequence 223 224 ```c 225 // Convert each input array element to double-precision: 226 double dxi = (double)fx[ i ]; 227 228 // Evaluate the callback: 229 double dyi = f( dxi ); 230 231 // Convert the callback return value to single-precision: 232 fy[ i ] = (float)dyi; 233 ``` 234 235 </section> 236 237 <!-- /.intro --> 238 239 <!-- C usage documentation. --> 240 241 <section class="usage"> 242 243 ### Usage 244 245 ```c 246 #include "stdlib/strided/base/unary.h" 247 ``` 248 249 #### UnaryFcnFloat32 250 251 Function type for a function accepting and returning single-precision floating-point numbers. 252 253 ```c 254 typedef float UnaryFcnFloat32( const float x ); 255 ``` 256 257 A `UnaryFcnFloat32` function should accept the following arguments: 258 259 - **x**: `[in] float` single-precision floating-point number. 260 261 The function should return a single-precision floating-point number. 262 263 #### UnaryFcnFloat32Int64 264 265 Function type for a function which accepts a single-precision floating-point number and returns a signed 64-bit integer. 266 267 ```c 268 typedef int64_t UnaryFcnFloat32Int64( const float x ); 269 ``` 270 271 A `UnaryFcnFloat32Int64` function should accept the following arguments: 272 273 - **x**: `[in] float` single-precision floating-point number. 274 275 The function should return a signed 64-bit integer. 276 277 #### UnaryFcnFloat32Int32 278 279 Function type for a function which accepts a single-precision floating-point number and returns a signed 32-bit integer. 280 281 ```c 282 typedef int32_t UnaryFcnFloat32Int32( const float x ); 283 ``` 284 285 A `UnaryFcnFloat32Int32` function should accept the following arguments: 286 287 - **x**: `[in] float` single-precision floating-point number. 288 289 The function should return a signed 32-bit integer. 290 291 #### UnaryFcnFloat64 292 293 Function type for a function which accepts and returns double-precision floating-point numbers. 294 295 ```c 296 typedef double UnaryFcnFloat64( const double x ); 297 ``` 298 299 A `UnaryFcnFloat64` function should accept the following arguments: 300 301 - **x**: `[in] double` double-precision floating-point number. 302 303 The function should return a double-precision floating-point number. 304 305 #### UnaryFcnFloat64Int64 306 307 Function type for a function which accepts a double-precision floating-point number and returns a signed 64-bit integer. 308 309 ```c 310 typedef int64_t UnaryFcnFloat64Int64( const double x ); 311 ``` 312 313 A `UnaryFcnFloat64Int64` function should accept the following arguments: 314 315 - **x**: `[in] double` double-precision floating-point number. 316 317 The function should return a signed 64-bit integer. 318 319 #### UnaryFcnFloat64Int32 320 321 Function type for a function which accepts a double-precision floating-point number and returns a signed 32-bit integer. 322 323 ```c 324 typedef int32_t UnaryFcnFloat64Int32( const double x ); 325 ``` 326 327 A `UnaryFcnFloat64Int32` function should accept the following arguments: 328 329 - **x**: `[in] double` double-precision floating-point number. 330 331 The function should return a signed 32-bit integer. 332 333 #### UnaryFcnInt64 334 335 Function type for a function which accepts and returns signed 64-bit integers. 336 337 ```c 338 typedef int64_t UnaryFcnInt64( const int64_t x ); 339 ``` 340 341 A `UnaryFcnInt64` function should accept the following arguments: 342 343 - **x**: `[in] int64_t` signed 64-bit integer. 344 345 The function should return a signed 64-bit integer. 346 347 #### UnaryFcnUint64 348 349 Function type for a function which accepts and returns unsigned 64-bit integers. 350 351 ```c 352 typedef uint64_t UnaryFcnUint64( const uint64_t x ); 353 ``` 354 355 A `UnaryFcnUint64` function should accept the following arguments: 356 357 - **x**: `[in] uint64_t` unsigned 64-bit integer. 358 359 The function should return an unsigned 64-bit integer. 360 361 #### UnaryFcnInt32 362 363 Function type for a function which accepts and returns signed 32-bit integers. 364 365 ```c 366 typedef int32_t UnaryFcnInt32( const int32_t x ); 367 ``` 368 369 A `UnaryFcnInt32` function should accept the following arguments: 370 371 - **x**: `[in] int32_t` signed 32-bit integer. 372 373 The function should return a signed 32-bit integer. 374 375 #### UnaryFcnUint32 376 377 Function type for a function which accepts and returns unsigned 32-bit integers. 378 379 ```c 380 typedef uint32_t UnaryFcnUint32( const uint32_t x ); 381 ``` 382 383 A `UnaryFcnUint32` function should accept the following arguments: 384 385 - **x**: `[in] uint32_t` unsigned 32-bit integer. 386 387 The function should return an unsigned 32-bit integer. 388 389 #### UnaryFcnInt16 390 391 Function type for a function which accepts and returns signed 16-bit integers. 392 393 ```c 394 typedef int16_t UnaryFcnInt16( const int16_t x ); 395 ``` 396 397 A `UnaryFcnInt16` function should accept the following arguments: 398 399 - **x**: `[in] int16_t` signed 16-bit integer. 400 401 The function should return a signed 16-bit integer. 402 403 #### UnaryFcnUint16 404 405 Function type for a function which accepts and returns unsigned 16-bit integers. 406 407 ```c 408 typedef uint16_t UnaryFcnUint16( const uint16_t x ); 409 ``` 410 411 A `UnaryFcnUint16` function should accept the following arguments: 412 413 - **x**: `[in] uint16_t` unsigned 16-bit integer. 414 415 The function should return an unsigned 16-bit integer. 416 417 #### UnaryFcnInt8 418 419 Function type for a function which accepts and returns signed 8-bit integers. 420 421 ```c 422 typedef int8_t UnaryFcnInt8( const int8_t x ); 423 ``` 424 425 A `UnaryFcnInt8` function should accept the following arguments: 426 427 - **x**: `[in] int8_t` signed 8-bit integer. 428 429 The function should return a signed 8-bit integer. 430 431 #### UnaryFcnUint8 432 433 Function type for a function which accepts and returns unsigned 8-bit integers. 434 435 ```c 436 typedef uint8_t UnaryFcnUint8( const uint8_t x ); 437 ``` 438 439 A `UnaryFcnUint8` function should accept the following arguments: 440 441 - **x**: `[in] uint8_t` unsigned 8-bit integer. 442 443 The function should return an unsigned 8-bit integer. 444 445 <!-- NOTE: keep the following in alphabetical order --> 446 447 * * * 448 449 #### stdlib_strided_b_b( \*arrays[], \*shape, \*strides, \*fcn ) 450 451 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array and assigns results to elements in an unsigned 8-bit integer strided output array. 452 453 ```c 454 #include <stdint.h> 455 456 // Create underlying byte arrays: 457 uint8_t x[] = { 0, 0, 0 }; 458 uint8_t out[] = { 0, 0, 0 }; 459 460 // Define a pointer to an array containing pointers to strided arrays: 461 uint8_t *arrays[] = { x, out }; 462 463 // Define the strides: 464 int64_t strides[] = { 1, 1 }; // 1 byte per uint8 465 466 // Define the number of elements over which to iterate: 467 int64_t shape[] = { 3 }; 468 469 // Define a callback: 470 uint8_t scale( const uint8_t x ) { 471 return x + 10; 472 } 473 474 // Apply the callback: 475 stdlib_strided_b_b( arrays, shape, strides, (void *)scale ); 476 ``` 477 478 The function accepts the following arguments: 479 480 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 481 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 482 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 483 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 484 485 ```c 486 void stdlib_strided_b_b( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 487 ``` 488 489 #### stdlib_strided_b_d( \*arrays[], \*shape, \*strides, \*fcn ) 490 491 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 492 493 ```c 494 #include <stdint.h> 495 496 // Create underlying byte arrays: 497 uint8_t x[] = { 0, 0, 0 }; 498 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 499 500 // Define a pointer to an array containing pointers to strided arrays: 501 uint8_t *arrays[] = { x, out }; 502 503 // Define the strides: 504 int64_t strides[] = { 1, 8 }; // 1 byte per uint8, 8 bytes per double 505 506 // Define the number of elements over which to iterate: 507 int64_t shape[] = { 3 }; 508 509 // Define a callback: 510 uint8_t scale( const uint8_t x ) { 511 return x + 10; 512 } 513 514 // Apply the callback: 515 stdlib_strided_b_d( arrays, shape, strides, (void *)scale ); 516 ``` 517 518 The function accepts the following arguments: 519 520 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 521 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 522 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 523 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 524 525 ```c 526 void stdlib_strided_b_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 527 ``` 528 529 #### stdlib_strided_b_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 530 531 Applies a unary callback accepting and returning double-precision floating-point numbers to an unsigned 8-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 532 533 ```c 534 #include <stdint.h> 535 536 // Create underlying byte arrays: 537 uint8_t x[] = { 0, 0, 0 }; 538 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 539 540 // Define a pointer to an array containing pointers to strided arrays: 541 uint8_t *arrays[] = { x, out }; 542 543 // Define the strides: 544 int64_t strides[] = { 1, 8 }; // 1 byte per uint8, 8 bytes per double 545 546 // Define the number of elements over which to iterate: 547 int64_t shape[] = { 3 }; 548 549 // Define a callback: 550 double scale( const double x ) { 551 return x + 10.0; 552 } 553 554 // Apply the callback: 555 stdlib_strided_b_d_as_d_d( arrays, shape, strides, (void *)scale ); 556 ``` 557 558 The function accepts the following arguments: 559 560 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 561 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 562 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 563 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 564 565 ```c 566 void stdlib_strided_b_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 567 ``` 568 569 #### stdlib_strided_b_f( \*arrays[], \*shape, \*strides, \*fcn ) 570 571 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 572 573 ```c 574 #include <stdint.h> 575 576 // Create underlying byte arrays: 577 uint8_t x[] = { 0, 0, 0 }; 578 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 579 580 // Define a pointer to an array containing pointers to strided arrays: 581 uint8_t *arrays[] = { x, out }; 582 583 // Define the strides: 584 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per float 585 586 // Define the number of elements over which to iterate: 587 int64_t shape[] = { 3 }; 588 589 // Define a callback: 590 uint8_t scale( const uint8_t x ) { 591 return x + 10; 592 } 593 594 // Apply the callback: 595 stdlib_strided_b_f( arrays, shape, strides, (void *)scale ); 596 ``` 597 598 The function accepts the following arguments: 599 600 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 601 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 602 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 603 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 604 605 ```c 606 void stdlib_strided_b_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 607 ``` 608 609 #### stdlib_strided_b_f_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 610 611 Applies a unary callback accepting and returning double-precision floating-point numbers to an unsigned 8-bit integer strided input array, casts the callback's double-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 612 613 ```c 614 #include <stdint.h> 615 616 // Create underlying byte arrays: 617 uint8_t x[] = { 0, 0, 0 }; 618 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 619 620 // Define a pointer to an array containing pointers to strided arrays: 621 uint8_t *arrays[] = { x, out }; 622 623 // Define the strides: 624 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per float 625 626 // Define the number of elements over which to iterate: 627 int64_t shape[] = { 3 }; 628 629 // Define a callback: 630 double scale( const double x ) { 631 return x + 10.0; 632 } 633 634 // Apply the callback: 635 stdlib_strided_b_f_as_d_d( arrays, shape, strides, (void *)scale ); 636 ``` 637 638 The function accepts the following arguments: 639 640 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 641 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 642 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 643 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 644 645 ```c 646 void stdlib_strided_b_f_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 647 ``` 648 649 #### stdlib_strided_b_f_as_f_f( \*arrays[], \*shape, \*strides, \*fcn ) 650 651 Applies a unary callback accepting and returning single-precision floating-point numbers to an unsigned 8-bit integer strided input array, casts the callback's single-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 652 653 ```c 654 #include <stdint.h> 655 656 // Create underlying byte arrays: 657 uint8_t x[] = { 0, 0, 0 }; 658 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 659 660 // Define a pointer to an array containing pointers to strided arrays: 661 uint8_t *arrays[] = { x, out }; 662 663 // Define the strides: 664 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per float 665 666 // Define the number of elements over which to iterate: 667 int64_t shape[] = { 3 }; 668 669 // Define a callback: 670 float scale( const float x ) { 671 return x + 10.0f; 672 } 673 674 // Apply the callback: 675 stdlib_strided_b_f_as_f_f( arrays, shape, strides, (void *)scale ); 676 ``` 677 678 The function accepts the following arguments: 679 680 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 681 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 682 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 683 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 684 685 ```c 686 void stdlib_strided_b_f_as_f_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 687 ``` 688 689 #### stdlib_strided_b_i( \*arrays[], \*shape, \*strides, \*fcn ) 690 691 Applies a unary callback accepting and returning signed 32-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to a signed 32-bit integer, and assigns results to elements in a signed 32-bit integer strided output array. 692 693 ```c 694 #include <stdint.h> 695 696 // Create underlying byte arrays: 697 uint8_t x[] = { 0, 0, 0 }; 698 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 699 700 // Define a pointer to an array containing pointers to strided arrays: 701 uint8_t *arrays[] = { x, out }; 702 703 // Define the strides: 704 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per int32 705 706 // Define the number of elements over which to iterate: 707 int64_t shape[] = { 3 }; 708 709 // Define a callback: 710 uint8_t scale( const uint8_t x ) { 711 return x + 10; 712 } 713 714 // Apply the callback: 715 stdlib_strided_b_i( arrays, shape, strides, (void *)scale ); 716 ``` 717 718 The function accepts the following arguments: 719 720 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 721 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 722 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 723 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 724 725 ```c 726 void stdlib_strided_b_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 727 ``` 728 729 #### stdlib_strided_b_i_as_i_i( \*arrays[], \*shape, \*strides, \*fcn ) 730 731 Applies a unary callback accepting and returning signed 32-bit integers to an unsigned 8-bit integer strided input array and assigns results to elements in a signed 32-bit integer strided output array. 732 733 ```c 734 #include <stdint.h> 735 736 // Create underlying byte arrays: 737 uint8_t x[] = { 0, 0, 0 }; 738 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 739 740 // Define a pointer to an array containing pointers to strided arrays: 741 uint8_t *arrays[] = { x, out }; 742 743 // Define the strides: 744 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per int32 745 746 // Define the number of elements over which to iterate: 747 int64_t shape[] = { 3 }; 748 749 // Define a callback: 750 int32_t scale( const int32_t x ) { 751 return x + 10; 752 } 753 754 // Apply the callback: 755 stdlib_strided_b_i_as_i_i( arrays, shape, strides, (void *)scale ); 756 ``` 757 758 The function accepts the following arguments: 759 760 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 761 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 762 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 763 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 764 765 ```c 766 void stdlib_strided_b_i_as_i_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 767 ``` 768 769 #### stdlib_strided_b_k( \*arrays[], \*shape, \*strides, \*fcn ) 770 771 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a signed 16-bit integer strided output array. 772 773 ```c 774 #include <stdint.h> 775 776 // Create underlying byte arrays: 777 uint8_t x[] = { 0, 0, 0 }; 778 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 779 780 // Define a pointer to an array containing pointers to strided arrays: 781 uint8_t *arrays[] = { x, out }; 782 783 // Define the strides: 784 int64_t strides[] = { 1, 2 }; // 1 byte per uint8, 2 bytes per int16 785 786 // Define the number of elements over which to iterate: 787 int64_t shape[] = { 3 }; 788 789 // Define a callback: 790 uint8_t scale( const uint8_t x ) { 791 return x + 10; 792 } 793 794 // Apply the callback: 795 stdlib_strided_b_k( arrays, shape, strides, (void *)scale ); 796 ``` 797 798 The function accepts the following arguments: 799 800 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 801 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 802 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 803 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 804 805 ```c 806 void stdlib_strided_b_k( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 807 ``` 808 809 #### stdlib_strided_b_k_as_k_k( \*arrays[], \*shape, \*strides, \*fcn ) 810 811 Applies a unary callback accepting and returning signed 16-bit integers to an unsigned 8-bit integer strided input array and assigns results to elements in a signed 16-bit integer strided output array. 812 813 ```c 814 #include <stdint.h> 815 816 // Create underlying byte arrays: 817 uint8_t x[] = { 0, 0, 0 }; 818 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 819 820 // Define a pointer to an array containing pointers to strided arrays: 821 uint8_t *arrays[] = { x, out }; 822 823 // Define the strides: 824 int64_t strides[] = { 1, 2 }; // 1 byte per uint8, 2 bytes per int16 825 826 // Define the number of elements over which to iterate: 827 int64_t shape[] = { 3 }; 828 829 // Define a callback: 830 int16_t scale( const int16_t x ) { 831 return x + 10; 832 } 833 834 // Apply the callback: 835 stdlib_strided_b_k_as_k_k( arrays, shape, strides, (void *)scale ); 836 ``` 837 838 The function accepts the following arguments: 839 840 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 841 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 842 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 843 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 844 845 ```c 846 void stdlib_strided_b_k_as_k_k( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 847 ``` 848 849 #### stdlib_strided_b_t( \*arrays[], \*shape, \*strides, \*fcn ) 850 851 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to an unsigned 16-bit integer, and assigns results to elements in an unsigned 16-bit integer strided output array. 852 853 ```c 854 #include <stdint.h> 855 856 // Create underlying byte arrays: 857 uint8_t x[] = { 0, 0, 0 }; 858 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 859 860 // Define a pointer to an array containing pointers to strided arrays: 861 uint8_t *arrays[] = { x, out }; 862 863 // Define the strides: 864 int64_t strides[] = { 1, 2 }; // 1 byte per uint8, 2 bytes per uint16 865 866 // Define the number of elements over which to iterate: 867 int64_t shape[] = { 3 }; 868 869 // Define a callback: 870 uint8_t scale( const uint8_t x ) { 871 return x + 10; 872 } 873 874 // Apply the callback: 875 stdlib_strided_b_t( arrays, shape, strides, (void *)scale ); 876 ``` 877 878 The function accepts the following arguments: 879 880 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 881 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 882 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 883 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 884 885 ```c 886 void stdlib_strided_b_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 887 ``` 888 889 #### stdlib_strided_b_t_as_t_t( \*arrays[], \*shape, \*strides, \*fcn ) 890 891 Applies a unary callback accepting and returning unsigned 16-bit integers to an unsigned 8-bit integer strided input array and assigns results to elements in an unsigned 16-bit integer strided output array. 892 893 ```c 894 #include <stdint.h> 895 896 // Create underlying byte arrays: 897 uint8_t x[] = { 0, 0, 0 }; 898 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 899 900 // Define a pointer to an array containing pointers to strided arrays: 901 uint8_t *arrays[] = { x, out }; 902 903 // Define the strides: 904 int64_t strides[] = { 1, 2 }; // 1 byte per uint8, 2 bytes per uint16 905 906 // Define the number of elements over which to iterate: 907 int64_t shape[] = { 3 }; 908 909 // Define a callback: 910 uint16_t scale( const uint16_t x ) { 911 return x + 10; 912 } 913 914 // Apply the callback: 915 stdlib_strided_b_t_as_t_t( arrays, shape, strides, (void *)scale ); 916 ``` 917 918 The function accepts the following arguments: 919 920 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 921 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 922 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 923 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 924 925 ```c 926 void stdlib_strided_b_t_as_t_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 927 ``` 928 929 #### stdlib_strided_b_u( \*arrays[], \*shape, \*strides, \*fcn ) 930 931 Applies a unary callback accepting and returning unsigned 8-bit integers to an unsigned 8-bit integer strided input array, casts the callback's unsigned 8-bit integer return value to an unsigned 32-bit integer, and assigns results to elements in an unsigned 32-bit integer strided output array. 932 933 ```c 934 #include <stdint.h> 935 936 // Create underlying byte arrays: 937 uint8_t x[] = { 0, 0, 0 }; 938 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 939 940 // Define a pointer to an array containing pointers to strided arrays: 941 uint8_t *arrays[] = { x, out }; 942 943 // Define the strides: 944 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per uint32 945 946 // Define the number of elements over which to iterate: 947 int64_t shape[] = { 3 }; 948 949 // Define a callback: 950 uint8_t scale( const uint8_t x ) { 951 return x + 10; 952 } 953 954 // Apply the callback: 955 stdlib_strided_b_u( arrays, shape, strides, (void *)scale ); 956 ``` 957 958 The function accepts the following arguments: 959 960 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 961 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 962 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 963 - **fcn**: `[in] void*` a `UnaryFcnUint8` function to apply provided as a `void` pointer. 964 965 ```c 966 void stdlib_strided_b_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 967 ``` 968 969 #### stdlib_strided_b_u_as_u_u( \*arrays[], \*shape, \*strides, \*fcn ) 970 971 Applies a unary callback accepting and returning unsigned 32-bit integers to an unsigned 8-bit integer strided input array and assigns results to elements in an unsigned 32-bit integer strided output array. 972 973 ```c 974 #include <stdint.h> 975 976 // Create underlying byte arrays: 977 uint8_t x[] = { 0, 0, 0 }; 978 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 979 980 // Define a pointer to an array containing pointers to strided arrays: 981 uint8_t *arrays[] = { x, out }; 982 983 // Define the strides: 984 int64_t strides[] = { 1, 4 }; // 1 byte per uint8, 4 bytes per uint32 985 986 // Define the number of elements over which to iterate: 987 int64_t shape[] = { 3 }; 988 989 // Define a callback: 990 uint32_t scale( const uint32_t x ) { 991 return x + 10; 992 } 993 994 // Apply the callback: 995 stdlib_strided_b_u_as_u_u( arrays, shape, strides, (void *)scale ); 996 ``` 997 998 The function accepts the following arguments: 999 1000 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1001 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1002 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1003 - **fcn**: `[in] void*` a `UnaryFcnUint32` function to apply provided as a `void` pointer. 1004 1005 ```c 1006 void stdlib_strided_b_u_as_u_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1007 ``` 1008 1009 #### stdlib_strided_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1010 1011 Applies a unary callback accepting and returning double-precision floating-point numbers to a double-precision floating-point strided input array and assigns results to elements in a double-precision floating-point strided output array. 1012 1013 ```c 1014 #include <stdint.h> 1015 1016 // Create underlying byte arrays: 1017 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1018 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1019 1020 // Define a pointer to an array containing pointers to strided arrays: 1021 uint8_t *arrays[] = { x, out }; 1022 1023 // Define the strides: 1024 int64_t strides[] = { 8, 8 }; // 8 bytes per double 1025 1026 // Define the number of elements over which to iterate: 1027 int64_t shape[] = { 3 }; 1028 1029 // Define a callback: 1030 double scale( const double x ) { 1031 return x + 10.0; 1032 } 1033 1034 // Apply the callback: 1035 stdlib_strided_d_d( arrays, shape, strides, (void *)scale ); 1036 ``` 1037 1038 The function accepts the following arguments: 1039 1040 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1041 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1042 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1043 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1044 1045 ```c 1046 void stdlib_strided_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1047 ``` 1048 1049 #### stdlib_strided_d_i( \*arrays[], \*shape, \*strides, \*fcn ) 1050 1051 Applies a unary callback accepting a double-precision floating-point number and returning a signed 32-bit integer to a double-precision floating-point strided input array and assigns results to elements in a signed 32-bit integer strided output array. 1052 1053 ```c 1054 #include <stdint.h> 1055 #include <math.h> 1056 1057 // Create underlying byte arrays: 1058 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1059 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1060 1061 // Define a pointer to an array containing pointers to strided arrays: 1062 uint8_t *arrays[] = { x, out }; 1063 1064 // Define the strides: 1065 int64_t strides[] = { 8, 4 }; // 8 bytes per double, 4 bytes per int32 1066 1067 // Define the number of elements over which to iterate: 1068 int64_t shape[] = { 3 }; 1069 1070 // Apply the callback: 1071 stdlib_strided_d_i( arrays, shape, strides, (void *)lrint ); 1072 ``` 1073 1074 The function accepts the following arguments: 1075 1076 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1077 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1078 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1079 - **fcn**: `[in] void*` a `UnaryFcnFloat64Int32` function to apply provided as a `void` pointer. 1080 1081 ```c 1082 void stdlib_strided_d_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1083 ``` 1084 1085 #### stdlib_strided_d_l( \*arrays[], \*shape, \*strides, \*fcn ) 1086 1087 Applies a unary callback accepting a double-precision floating-point number and returning a signed 64-bit integer to a double-precision floating-point strided input array and assigns results to elements in a signed 64-bit integer strided output array. 1088 1089 ```c 1090 #include <stdint.h> 1091 #include <math.h> 1092 1093 // Create underlying byte arrays: 1094 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1095 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1096 1097 // Define a pointer to an array containing pointers to strided arrays: 1098 uint8_t *arrays[] = { x, out }; 1099 1100 // Define the strides: 1101 int64_t strides[] = { 8, 8 }; // 8 bytes per double, 8 bytes per int64 1102 1103 // Define the number of elements over which to iterate: 1104 int64_t shape[] = { 3 }; 1105 1106 // Apply the callback: 1107 stdlib_strided_d_l( arrays, shape, strides, (void *)llrint ); 1108 ``` 1109 1110 The function accepts the following arguments: 1111 1112 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1113 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1114 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1115 - **fcn**: `[in] void*` a `UnaryFcnFloat64Int64` function to apply provided as a `void` pointer. 1116 1117 ```c 1118 void stdlib_strided_d_l( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1119 ``` 1120 1121 #### stdlib_strided_f_d( \*arrays[], \*shape, \*strides, \*fcn ) 1122 1123 Applies a unary callback accepting and returning single-precision floating-point numbers to a single-precision floating-point strided input array, casts the callback's single-precision floating-point return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 1124 1125 ```c 1126 #include <stdint.h> 1127 1128 // Create underlying byte arrays: 1129 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1130 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1131 1132 // Define a pointer to an array containing pointers to strided arrays: 1133 uint8_t *arrays[] = { x, out }; 1134 1135 // Define the strides: 1136 int64_t strides[] = { 4, 8 }; // 4 bytes per float, 8 bytes per double 1137 1138 // Define the number of elements over which to iterate: 1139 int64_t shape[] = { 3 }; 1140 1141 // Define a callback: 1142 float scale( const float x ) { 1143 return x + 10.0f; 1144 } 1145 1146 // Apply the callback: 1147 stdlib_strided_f_d( arrays, shape, strides, (void *)scale ); 1148 ``` 1149 1150 The function accepts the following arguments: 1151 1152 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1153 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1154 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1155 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 1156 1157 ```c 1158 void stdlib_strided_f_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1159 ``` 1160 1161 #### stdlib_strided_f_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1162 1163 Applies a unary callback accepting and returning double-precision floating-point numbers to a single-precision floating-point strided input array and assigns results to elements in a double-precision floating-point strided output array. 1164 1165 ```c 1166 #include <stdint.h> 1167 1168 // Create underlying byte arrays: 1169 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1170 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1171 1172 // Define a pointer to an array containing pointers to strided arrays: 1173 uint8_t *arrays[] = { x, out }; 1174 1175 // Define the strides: 1176 int64_t strides[] = { 4, 8 }; // 4 bytes per float, 8 bytes per double 1177 1178 // Define the number of elements over which to iterate: 1179 int64_t shape[] = { 3 }; 1180 1181 // Define a callback: 1182 double scale( const double x ) { 1183 return x + 10.0; 1184 } 1185 1186 // Apply the callback: 1187 stdlib_strided_f_d_as_d_d( arrays, shape, strides, (void *)scale ); 1188 ``` 1189 1190 The function accepts the following arguments: 1191 1192 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1193 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1194 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1195 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1196 1197 ```c 1198 void stdlib_strided_f_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1199 ``` 1200 1201 #### stdlib_strided_f_f( \*arrays[], \*shape, \*strides, \*fcn ) 1202 1203 Applies a unary callback accepting and returning single-precision floating-point numbers to a single-precision floating-point strided input array and assigns results to elements in a single-precision floating-point strided output array. 1204 1205 ```c 1206 #include <stdint.h> 1207 1208 // Create underlying byte arrays: 1209 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1210 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1211 1212 // Define a pointer to an array containing pointers to strided arrays: 1213 uint8_t *arrays[] = { x, out }; 1214 1215 // Define the strides: 1216 int64_t strides[] = { 4, 4 }; // 4 bytes per float 1217 1218 // Define the number of elements over which to iterate: 1219 int64_t shape[] = { 3 }; 1220 1221 // Define a callback: 1222 float scale( const float x ) { 1223 return x + 10.0f; 1224 } 1225 1226 // Apply the callback: 1227 stdlib_strided_f_f( arrays, shape, strides, (void *)scale ); 1228 ``` 1229 1230 The function accepts the following arguments: 1231 1232 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1233 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1234 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1235 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 1236 1237 ```c 1238 void stdlib_strided_f_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1239 ``` 1240 1241 #### stdlib_strided_f_f_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1242 1243 Applies a unary callback accepting and returning double-precision floating-point numbers, casts the callback's double-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 1244 1245 ```c 1246 #include <stdint.h> 1247 1248 // Create underlying byte arrays: 1249 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1250 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1251 1252 // Define a pointer to an array containing pointers to strided arrays: 1253 uint8_t *arrays[] = { x, out }; 1254 1255 // Define the strides: 1256 int64_t strides[] = { 4, 4 }; // 4 bytes per float 1257 1258 // Define the number of elements over which to iterate: 1259 int64_t shape[] = { 3 }; 1260 1261 // Define a callback: 1262 double scale( const double x ) { 1263 return x + 10.0; 1264 } 1265 1266 // Apply the callback: 1267 stdlib_strided_f_f_as_d_d( arrays, shape, strides, (void *)scale ); 1268 ``` 1269 1270 The function accepts the following arguments: 1271 1272 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1273 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1274 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1275 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1276 1277 ```c 1278 void stdlib_strided_f_f_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1279 ``` 1280 1281 #### stdlib_strided_f_i( \*arrays[], \*shape, \*strides, \*fcn ) 1282 1283 Applies a unary callback accepting a single-precision floating-point number and returning a signed 32-bit integer to a single-precision floating-point strided input array and assigns results to elements in a signed 32-bit integer strided output array. 1284 1285 ```c 1286 #include <stdint.h> 1287 #include <math.h> 1288 1289 // Create underlying byte arrays: 1290 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1291 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1292 1293 // Define a pointer to an array containing pointers to strided arrays: 1294 uint8_t *arrays[] = { x, out }; 1295 1296 // Define the strides: 1297 int64_t strides[] = { 4, 4 }; // 4 bytes per float, 4 bytes per int32 1298 1299 // Define the number of elements over which to iterate: 1300 int64_t shape[] = { 3 }; 1301 1302 // Apply the callback: 1303 stdlib_strided_f_i( arrays, shape, strides, (void *)lrintf ); 1304 ``` 1305 1306 The function accepts the following arguments: 1307 1308 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1309 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1310 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1311 - **fcn**: `[in] void*` a `UnaryFcnFloat32Int32` function to apply provided as a `void` pointer. 1312 1313 ```c 1314 void stdlib_strided_f_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1315 ``` 1316 1317 #### stdlib_strided_f_l( \*arrays[], \*shape, \*strides, \*fcn ) 1318 1319 Applies a unary callback accepting a single-precision floating-point number and returning a signed 64-bit integer to a single-precision floating-point strided input array and assigns results to elements in a signed 64-bit integer strided output array. 1320 1321 ```c 1322 #include <stdint.h> 1323 #include <math.h> 1324 1325 // Create underlying byte arrays: 1326 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1327 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1328 1329 // Define a pointer to an array containing pointers to strided arrays: 1330 uint8_t *arrays[] = { x, out }; 1331 1332 // Define the strides: 1333 int64_t strides[] = { 4, 8 }; // 4 bytes per float, 8 bytes per int64 1334 1335 // Define the number of elements over which to iterate: 1336 int64_t shape[] = { 3 }; 1337 1338 // Apply the callback: 1339 stdlib_strided_f_l( arrays, shape, strides, (void *)lrintf ); 1340 ``` 1341 1342 The function accepts the following arguments: 1343 1344 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1345 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1346 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1347 - **fcn**: `[in] void*` a `UnaryFcnFloat32Int64` function to apply provided as a `void` pointer. 1348 1349 ```c 1350 void stdlib_strided_f_l( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1351 ``` 1352 1353 #### stdlib_strided_i_d( \*arrays[], \*shape, \*strides, \*fcn ) 1354 1355 Applies a unary callback accepting and returning signed 32-bit integers to a signed 32-bit integer strided input array, casts the callback's signed 32-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 1356 1357 ```c 1358 #include <stdint.h> 1359 1360 // Create underlying byte arrays: 1361 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1362 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1363 1364 // Define a pointer to an array containing pointers to strided arrays: 1365 uint8_t *arrays[] = { x, out }; 1366 1367 // Define the strides: 1368 int64_t strides[] = { 4, 8 }; // 4 bytes per int32, 8 bytes per double 1369 1370 // Define the number of elements over which to iterate: 1371 int64_t shape[] = { 3 }; 1372 1373 // Define a callback: 1374 int32_t scale( const int32_t x ) { 1375 return x + 10; 1376 } 1377 1378 // Apply the callback: 1379 stdlib_strided_i_d( arrays, shape, strides, (void *)scale ); 1380 ``` 1381 1382 The function accepts the following arguments: 1383 1384 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1385 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1386 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1387 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 1388 1389 ```c 1390 void stdlib_strided_i_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1391 ``` 1392 1393 #### stdlib_strided_i_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1394 1395 Applies a unary callback accepting and returning double-precision floating-point numbers to a signed 32-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 1396 1397 ```c 1398 #include <stdint.h> 1399 1400 // Create underlying byte arrays: 1401 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1402 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1403 1404 // Define a pointer to an array containing pointers to strided arrays: 1405 uint8_t *arrays[] = { x, out }; 1406 1407 // Define the strides: 1408 int64_t strides[] = { 4, 8 }; // 4 bytes per int32, 8 bytes per double 1409 1410 // Define the number of elements over which to iterate: 1411 int64_t shape[] = { 3 }; 1412 1413 // Define a callback: 1414 double scale( const double x ) { 1415 return x + 10.0; 1416 } 1417 1418 // Apply the callback: 1419 stdlib_strided_i_d_as_d_d( arrays, shape, strides, (void *)scale ); 1420 ``` 1421 1422 The function accepts the following arguments: 1423 1424 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1425 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1426 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1427 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1428 1429 ```c 1430 void stdlib_strided_i_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1431 ``` 1432 1433 #### stdlib_strided_i_i( \*arrays[], \*shape, \*strides, \*fcn ) 1434 1435 Applies a unary callback accepting and returning signed 32-bit integers to a signed 32-bit integer strided input array and assigns results to elements in a signed 32-bit integer strided output array. 1436 1437 ```c 1438 #include <stdint.h> 1439 1440 // Create underlying byte arrays: 1441 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1442 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1443 1444 // Define a pointer to an array containing pointers to strided arrays: 1445 uint8_t *arrays[] = { x, out }; 1446 1447 // Define the strides: 1448 int64_t strides[] = { 4, 4 }; // 4 bytes per int32 1449 1450 // Define the number of elements over which to iterate: 1451 int64_t shape[] = { 3 }; 1452 1453 // Define a callback: 1454 int32_t scale( const int32_t x ) { 1455 return x + 10; 1456 } 1457 1458 // Apply the callback: 1459 stdlib_strided_i_i( arrays, shape, strides, (void *)scale ); 1460 ``` 1461 1462 The function accepts the following arguments: 1463 1464 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1465 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1466 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1467 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 1468 1469 ```c 1470 void stdlib_strided_i_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1471 ``` 1472 1473 #### stdlib_strided_i_u( \*arrays[], \*shape, \*strides, \*fcn ) 1474 1475 Applies a unary callback accepting and returning signed 32-bit integers to a signed 32-bit integer strided input array, casts the callback's signed 32-bit integer return value to an unsigned 32-bit integer, and assigns results to elements in an unsigned 32-bit integer strided output array. 1476 1477 ```c 1478 #include <stdint.h> 1479 1480 // Create underlying byte arrays: 1481 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1482 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1483 1484 // Define a pointer to an array containing pointers to strided arrays: 1485 uint8_t *arrays[] = { x, out }; 1486 1487 // Define the strides: 1488 int64_t strides[] = { 4, 4 }; // 4 bytes per int32, 4 bytes per uint32 1489 1490 // Define the number of elements over which to iterate: 1491 int64_t shape[] = { 3 }; 1492 1493 // Define a callback: 1494 int32_t abs( const int32_t x ) { 1495 if ( x < 0 ) { 1496 return -x; 1497 } 1498 return x; 1499 } 1500 1501 // Apply the callback: 1502 stdlib_strided_i_u( arrays, shape, strides, (void *)abs ); 1503 ``` 1504 1505 The function accepts the following arguments: 1506 1507 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1508 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1509 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1510 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 1511 1512 ```c 1513 void stdlib_strided_i_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1514 ``` 1515 1516 #### stdlib_strided_k_d( \*arrays[], \*shape, \*strides, \*fcn ) 1517 1518 Applies a unary callback accepting and returning signed 16-bit integers to a signed 16-bit integer strided input array, casts the callback's signed 16-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 1519 1520 ```c 1521 #include <stdint.h> 1522 1523 // Create underlying byte arrays: 1524 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1525 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1526 1527 // Define a pointer to an array containing pointers to strided arrays: 1528 uint8_t *arrays[] = { x, out }; 1529 1530 // Define the strides: 1531 int64_t strides[] = { 2, 8 }; // 2 bytes per int16, 8 bytes per double 1532 1533 // Define the number of elements over which to iterate: 1534 int64_t shape[] = { 3 }; 1535 1536 // Define a callback: 1537 int16_t scale( const int16_t x ) { 1538 return x + 10; 1539 } 1540 1541 // Apply the callback: 1542 stdlib_strided_k_d( arrays, shape, strides, (void *)scale ); 1543 ``` 1544 1545 The function accepts the following arguments: 1546 1547 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1548 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1549 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1550 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1551 1552 ```c 1553 void stdlib_strided_k_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1554 ``` 1555 1556 #### stdlib_strided_k_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1557 1558 Applies a unary callback accepting and returning double-precision floating-point numbers to a signed 16-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 1559 1560 ```c 1561 #include <stdint.h> 1562 1563 // Create underlying byte arrays: 1564 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1565 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1566 1567 // Define a pointer to an array containing pointers to strided arrays: 1568 uint8_t *arrays[] = { x, out }; 1569 1570 // Define the strides: 1571 int64_t strides[] = { 2, 8 }; // 2 bytes per int16, 8 bytes per double 1572 1573 // Define the number of elements over which to iterate: 1574 int64_t shape[] = { 3 }; 1575 1576 // Define a callback: 1577 double scale( const double x ) { 1578 return x + 10.0; 1579 } 1580 1581 // Apply the callback: 1582 stdlib_strided_k_d_as_d_d( arrays, shape, strides, (void *)scale ); 1583 ``` 1584 1585 The function accepts the following arguments: 1586 1587 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1588 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1589 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1590 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1591 1592 ```c 1593 void stdlib_strided_k_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1594 ``` 1595 1596 #### stdlib_strided_k_f( \*arrays[], \*shape, \*strides, \*fcn ) 1597 1598 Applies a unary callback accepting and returning signed 16-bit integers to a signed 16-bit integer strided input array, casts the callback's signed 16-bit integer return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 1599 1600 ```c 1601 #include <stdint.h> 1602 1603 // Create underlying byte arrays: 1604 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1605 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1606 1607 // Define a pointer to an array containing pointers to strided arrays: 1608 uint8_t *arrays[] = { x, out }; 1609 1610 // Define the strides: 1611 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per float 1612 1613 // Define the number of elements over which to iterate: 1614 int64_t shape[] = { 3 }; 1615 1616 // Define a callback: 1617 int16_t scale( const int16_t x ) { 1618 return x + 10; 1619 } 1620 1621 // Apply the callback: 1622 stdlib_strided_k_f( arrays, shape, strides, (void *)scale ); 1623 ``` 1624 1625 The function accepts the following arguments: 1626 1627 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1628 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1629 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1630 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1631 1632 ```c 1633 void stdlib_strided_k_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1634 ``` 1635 1636 #### stdlib_strided_k_f_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 1637 1638 Applies a unary callback accepting and returning double-precision floating-point numbers to a signed 16-bit integer strided input array, casts the callback's double-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 1639 1640 ```c 1641 #include <stdint.h> 1642 1643 // Create underlying byte arrays: 1644 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1645 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1646 1647 // Define a pointer to an array containing pointers to strided arrays: 1648 uint8_t *arrays[] = { x, out }; 1649 1650 // Define the strides: 1651 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per float 1652 1653 // Define the number of elements over which to iterate: 1654 int64_t shape[] = { 3 }; 1655 1656 // Define a callback: 1657 double scale( const double x ) { 1658 return x + 10.0; 1659 } 1660 1661 // Apply the callback: 1662 stdlib_strided_k_f_as_d_d( arrays, shape, strides, (void *)scale ); 1663 ``` 1664 1665 The function accepts the following arguments: 1666 1667 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1668 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1669 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1670 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 1671 1672 ```c 1673 void stdlib_strided_k_f_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1674 ``` 1675 1676 #### stdlib_strided_k_f_as_f_f( \*arrays[], \*shape, \*strides, \*fcn ) 1677 1678 Applies a unary callback accepting and returning single-precision floating-point numbers to a signed 16-bit integer strided input array and assigns results to elements in a single-precision floating-point strided output array. 1679 1680 ```c 1681 #include <stdint.h> 1682 1683 // Create underlying byte arrays: 1684 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1685 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1686 1687 // Define a pointer to an array containing pointers to strided arrays: 1688 uint8_t *arrays[] = { x, out }; 1689 1690 // Define the strides: 1691 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per float 1692 1693 // Define the number of elements over which to iterate: 1694 int64_t shape[] = { 3 }; 1695 1696 // Define a callback: 1697 float scale( const float x ) { 1698 return x + 10.0f; 1699 } 1700 1701 // Apply the callback: 1702 stdlib_strided_k_f_as_f_f( arrays, shape, strides, (void *)scale ); 1703 ``` 1704 1705 The function accepts the following arguments: 1706 1707 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1708 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1709 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1710 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 1711 1712 ```c 1713 void stdlib_strided_k_f_as_f_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1714 ``` 1715 1716 #### stdlib_strided_k_i( \*arrays[], \*shape, \*strides, \*fcn ) 1717 1718 Applies a unary callback accepting and returning signed 16-bit integers to a signed 16-bit integer strided input array, casts the callback's signed 16-bit integer return value to a signed 32-bit integer, and assigns results to elements in a signed 32-bit integer strided output array. 1719 1720 ```c 1721 #include <stdint.h> 1722 1723 // Create underlying byte arrays: 1724 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1725 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1726 1727 // Define a pointer to an array containing pointers to strided arrays: 1728 uint8_t *arrays[] = { x, out }; 1729 1730 // Define the strides: 1731 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per int32 1732 1733 // Define the number of elements over which to iterate: 1734 int64_t shape[] = { 3 }; 1735 1736 // Define a callback: 1737 int16_t scale( const int16_t x ) { 1738 return x + 10; 1739 } 1740 1741 // Apply the callback: 1742 stdlib_strided_k_i( arrays, shape, strides, (void *)scale ); 1743 ``` 1744 1745 The function accepts the following arguments: 1746 1747 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1748 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1749 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1750 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1751 1752 ```c 1753 void stdlib_strided_k_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1754 ``` 1755 1756 #### stdlib_strided_k_i_as_i_i( \*arrays[], \*shape, \*strides, \*fcn ) 1757 1758 Applies a unary callback accepting and returning signed 32-bit integers to a signed 16-bit integer strided input array and assigns results to elements in a signed 32-bit integer strided output array. 1759 1760 ```c 1761 #include <stdint.h> 1762 1763 // Create underlying byte arrays: 1764 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1765 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1766 1767 // Define a pointer to an array containing pointers to strided arrays: 1768 uint8_t *arrays[] = { x, out }; 1769 1770 // Define the strides: 1771 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per int32 1772 1773 // Define the number of elements over which to iterate: 1774 int64_t shape[] = { 3 }; 1775 1776 // Define a callback: 1777 int32_t scale( const int32_t x ) { 1778 return x + 10; 1779 } 1780 1781 // Apply the callback: 1782 stdlib_strided_k_i_as_i_i( arrays, shape, strides, (void *)scale ); 1783 ``` 1784 1785 The function accepts the following arguments: 1786 1787 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1788 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1789 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1790 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 1791 1792 ```c 1793 void stdlib_strided_k_i_as_i_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1794 ``` 1795 1796 #### stdlib_strided_k_k( \*arrays[], \*shape, \*strides, \*fcn ) 1797 1798 Applies a unary callback accepting and returning signed 16-bit integers to a signed 16-bit integer strided input array and assigns results to elements in a signed 16-bit integer strided output array. 1799 1800 ```c 1801 #include <stdint.h> 1802 1803 // Create underlying byte arrays: 1804 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1805 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 1806 1807 // Define a pointer to an array containing pointers to strided arrays: 1808 uint8_t *arrays[] = { x, out }; 1809 1810 // Define the strides: 1811 int64_t strides[] = { 2, 2 }; // 2 bytes per int16 1812 1813 // Define the number of elements over which to iterate: 1814 int64_t shape[] = { 3 }; 1815 1816 // Define a callback: 1817 int16_t scale( const int16_t x ) { 1818 return x + 10; 1819 } 1820 1821 // Apply the callback: 1822 stdlib_strided_k_k( arrays, shape, strides, (void *)scale ); 1823 ``` 1824 1825 The function accepts the following arguments: 1826 1827 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1828 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1829 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1830 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1831 1832 ```c 1833 void stdlib_strided_k_k( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1834 ``` 1835 1836 #### stdlib_strided_k_t( \*arrays[], \*shape, \*strides, \*fcn ) 1837 1838 Applies a unary callback accepting and returned signed 16-bit integers to a signed 16-bit integer strided input array, casts the callback's signed 16-bit integer return value to an unsigned 16-bit integer, and assigns results to elements in an unsigned 16-bit integer strided output array. 1839 1840 ```c 1841 #include <stdint.h> 1842 1843 // Create underlying byte arrays: 1844 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1845 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 1846 1847 // Define a pointer to an array containing pointers to strided arrays: 1848 uint8_t *arrays[] = { x, out }; 1849 1850 // Define the strides: 1851 int64_t strides[] = { 2, 2 }; // 2 bytes per int16, 2 bytes per uint16 1852 1853 // Define the number of elements over which to iterate: 1854 int64_t shape[] = { 3 }; 1855 1856 // Define a callback: 1857 int16_t abs( const int16_t x ) { 1858 if ( x < 0 ) { 1859 return -x; 1860 } 1861 return x; 1862 } 1863 1864 // Apply the callback: 1865 stdlib_strided_k_t( arrays, shape, strides, (void *)abs ); 1866 ``` 1867 1868 The function accepts the following arguments: 1869 1870 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1871 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1872 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1873 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1874 1875 ```c 1876 void stdlib_strided_k_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1877 ``` 1878 1879 #### stdlib_strided_k_u( \*arrays[], \*shape, \*strides, \*fcn ) 1880 1881 Applies a unary callback accepting and returning signed 16-bit integers to a signed 16-bit integer strided input array, casts the callback's signed 16-bit integer return value to an unsigned 32-bit integer, and assigns results to elements in an unsigned 32-bit integer strided output array. 1882 1883 ```c 1884 #include <stdint.h> 1885 1886 // Create underlying byte arrays: 1887 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 1888 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1889 1890 // Define a pointer to an array containing pointers to strided arrays: 1891 uint8_t *arrays[] = { x, out }; 1892 1893 // Define the strides: 1894 int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per uint32 1895 1896 // Define the number of elements over which to iterate: 1897 int64_t shape[] = { 3 }; 1898 1899 // Define a callback: 1900 int16_t abs( const int16_t x ) { 1901 if ( x < 0 ) { 1902 return -x; 1903 } 1904 return x; 1905 } 1906 1907 // Apply the callback: 1908 stdlib_strided_k_u( arrays, shape, strides, (void *)abs ); 1909 ``` 1910 1911 The function accepts the following arguments: 1912 1913 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1914 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1915 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1916 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 1917 1918 ```c 1919 void stdlib_strided_k_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1920 ``` 1921 1922 #### stdlib_strided_l_l( \*arrays[], \*shape, \*strides, \*fcn ) 1923 1924 Applies a unary callback accepting and returning signed 64-bit integers to a signed 64-bit integer strided input array and assigns results to elements in a signed 64-bit integer strided output array. 1925 1926 ```c 1927 #include <stdint.h> 1928 1929 // Create underlying byte arrays: 1930 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1931 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1932 1933 // Define a pointer to an array containing pointers to strided arrays: 1934 uint8_t *arrays[] = { x, out }; 1935 1936 // Define the strides: 1937 int64_t strides[] = { 8, 8 }; // 8 bytes per int64 1938 1939 // Define the number of elements over which to iterate: 1940 int64_t shape[] = { 3 }; 1941 1942 // Define a callback: 1943 int64_t scale( const int64_t x ) { 1944 return x + 10; 1945 } 1946 1947 // Apply the callback: 1948 stdlib_strided_l_l( arrays, shape, strides, (void *)scale ); 1949 ``` 1950 1951 The function accepts the following arguments: 1952 1953 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1954 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1955 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1956 - **fcn**: `[in] void*` a `UnaryFcnInt64` function to apply provided as a `void` pointer. 1957 1958 ```c 1959 void stdlib_strided_l_l( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 1960 ``` 1961 1962 #### stdlib_strided_l_v( \*arrays[], \*shape, \*strides, \*fcn ) 1963 1964 Applies a unary callback accepting and returning signed 64-bit integers to a signed 64-bit integer strided input array, casts the callback's signed 64-bit integer return value to an unsigned 64-bit integer, and assigns results to elements in an unsigned 64-bit integer strided output array. 1965 1966 ```c 1967 #include <stdint.h> 1968 1969 // Create underlying byte arrays: 1970 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1971 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 1972 1973 // Define a pointer to an array containing pointers to strided arrays: 1974 uint8_t *arrays[] = { x, out }; 1975 1976 // Define the strides: 1977 int64_t strides[] = { 8, 8 }; // 8 bytes per int64, 8 bytes per uint64 1978 1979 // Define the number of elements over which to iterate: 1980 int64_t shape[] = { 3 }; 1981 1982 // Define a callback: 1983 int64_t abs( const int64_t x ) { 1984 if ( x < 0 ) { 1985 return -x; 1986 } 1987 return x; 1988 } 1989 1990 // Apply the callback: 1991 stdlib_strided_l_v( arrays, shape, strides, (void *)abs ); 1992 ``` 1993 1994 The function accepts the following arguments: 1995 1996 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 1997 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 1998 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 1999 - **fcn**: `[in] void*` a `UnaryFcnInt64` function to apply provided as a `void` pointer. 2000 2001 ```c 2002 void stdlib_strided_l_v( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2003 ``` 2004 2005 #### stdlib_strided_s_b( \*arrays[], \*shape, \*strides, \*fcn ) 2006 2007 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, 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 strided output array. 2008 2009 ```c 2010 #include <stdint.h> 2011 2012 // Create underlying byte arrays: 2013 uint8_t x[] = { 0, 0, 0 }; 2014 uint8_t out[] = { 0, 0, 0 }; 2015 2016 // Define a pointer to an array containing pointers to strided arrays: 2017 uint8_t *arrays[] = { x, out }; 2018 2019 // Define the strides: 2020 int64_t strides[] = { 1, 1 }; // 1 byte per int8, 1 byte per uint8 2021 2022 // Define the number of elements over which to iterate: 2023 int64_t shape[] = { 3 }; 2024 2025 // Define a callback: 2026 int8_t abs( const int8_t x ) { 2027 if ( x < 0 ) { 2028 return -x; 2029 } 2030 return x; 2031 } 2032 2033 // Apply the callback: 2034 stdlib_strided_s_b( arrays, shape, strides, (void *)abs ); 2035 ``` 2036 2037 The function accepts the following arguments: 2038 2039 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2040 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2041 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2042 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2043 2044 ```c 2045 void stdlib_strided_s_b( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2046 ``` 2047 2048 #### stdlib_strided_s_d( \*arrays[], \*shape, \*strides, \*fcn ) 2049 2050 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 2051 2052 ```c 2053 #include <stdint.h> 2054 2055 // Create underlying byte arrays: 2056 uint8_t x[] = { 0, 0, 0 }; 2057 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2058 2059 // Define a pointer to an array containing pointers to strided arrays: 2060 uint8_t *arrays[] = { x, out }; 2061 2062 // Define the strides: 2063 int64_t strides[] = { 1, 8 }; // 1 byte per int8, 8 bytes per double 2064 2065 // Define the number of elements over which to iterate: 2066 int64_t shape[] = { 3 }; 2067 2068 // Define a callback: 2069 int8_t scale( const int8_t x ) { 2070 return x + 10; 2071 } 2072 2073 // Apply the callback: 2074 stdlib_strided_s_d( arrays, shape, strides, (void *)scale ); 2075 ``` 2076 2077 The function accepts the following arguments: 2078 2079 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2080 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2081 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2082 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2083 2084 ```c 2085 void stdlib_strided_s_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2086 ``` 2087 2088 #### stdlib_strided_s_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 2089 2090 Applies a unary callback accepting and returning double-precision floating-point numbers to a signed 8-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 2091 2092 ```c 2093 #include <stdint.h> 2094 2095 // Create underlying byte arrays: 2096 uint8_t x[] = { 0, 0, 0 }; 2097 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2098 2099 // Define a pointer to an array containing pointers to strided arrays: 2100 uint8_t *arrays[] = { x, out }; 2101 2102 // Define the strides: 2103 int64_t strides[] = { 1, 8 }; // 1 byte per int8, 8 bytes per double 2104 2105 // Define the number of elements over which to iterate: 2106 int64_t shape[] = { 3 }; 2107 2108 // Define a callback: 2109 double scale( const double x ) { 2110 return x + 10.0; 2111 } 2112 2113 // Apply the callback: 2114 stdlib_strided_s_d_as_d_d( arrays, shape, strides, (void *)scale ); 2115 ``` 2116 2117 The function accepts the following arguments: 2118 2119 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2120 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2121 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2122 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 2123 2124 ```c 2125 void stdlib_strided_s_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2126 ``` 2127 2128 #### stdlib_strided_s_f( \*arrays[], \*shape, \*strides, \*fcn ) 2129 2130 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 2131 2132 ```c 2133 #include <stdint.h> 2134 2135 // Create underlying byte arrays: 2136 uint8_t x[] = { 0, 0, 0 }; 2137 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2138 2139 // Define a pointer to an array containing pointers to strided arrays: 2140 uint8_t *arrays[] = { x, out }; 2141 2142 // Define the strides: 2143 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per float 2144 2145 // Define the number of elements over which to iterate: 2146 int64_t shape[] = { 3 }; 2147 2148 // Define a callback: 2149 int8_t scale( const int8_t x ) { 2150 return x + 10; 2151 } 2152 2153 // Apply the callback: 2154 stdlib_strided_s_f( arrays, shape, strides, (void *)scale ); 2155 ``` 2156 2157 The function accepts the following arguments: 2158 2159 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2160 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2161 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2162 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2163 2164 ```c 2165 void stdlib_strided_s_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2166 ``` 2167 2168 #### stdlib_strided_s_f_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 2169 2170 Applies a unary callback accepting and returning double-precision floating-point numbers to a signed 8-bit integer strided input array, casts the callback's double-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 2171 2172 ```c 2173 #include <stdint.h> 2174 2175 // Create underlying byte arrays: 2176 uint8_t x[] = { 0, 0, 0 }; 2177 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2178 2179 // Define a pointer to an array containing pointers to strided arrays: 2180 uint8_t *arrays[] = { x, out }; 2181 2182 // Define the strides: 2183 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per float 2184 2185 // Define the number of elements over which to iterate: 2186 int64_t shape[] = { 3 }; 2187 2188 // Define a callback: 2189 double scale( const double x ) { 2190 return x + 10.0; 2191 } 2192 2193 // Apply the callback: 2194 stdlib_strided_s_f_as_d_d( arrays, shape, strides, (void *)scale ); 2195 ``` 2196 2197 The function accepts the following arguments: 2198 2199 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2200 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2201 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2202 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 2203 2204 ```c 2205 void stdlib_strided_s_f_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2206 ``` 2207 2208 #### stdlib_strided_s_f_as_f_f( \*arrays[], \*shape, \*strides, \*fcn ) 2209 2210 Applies a unary callback accepting and returning single-precision floating-point numbers to a signed 8-bit integer strided input array and assigns results to elements in a single-precision floating-point strided output array. 2211 2212 ```c 2213 #include <stdint.h> 2214 2215 // Create underlying byte arrays: 2216 uint8_t x[] = { 0, 0, 0 }; 2217 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2218 2219 // Define a pointer to an array containing pointers to strided arrays: 2220 uint8_t *arrays[] = { x, out }; 2221 2222 // Define the strides: 2223 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per float 2224 2225 // Define the number of elements over which to iterate: 2226 int64_t shape[] = { 3 }; 2227 2228 // Define a callback: 2229 float scale( const float x ) { 2230 return x + 10.0f; 2231 } 2232 2233 // Apply the callback: 2234 stdlib_strided_s_f_as_f_f( arrays, shape, strides, (void *)scale ); 2235 ``` 2236 2237 The function accepts the following arguments: 2238 2239 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2240 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2241 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2242 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 2243 2244 ```c 2245 void stdlib_strided_s_f_as_f_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2246 ``` 2247 2248 #### stdlib_strided_s_i( \*arrays[], \*shape, \*strides, \*fcn ) 2249 2250 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to a signed 32-bit integer, and assigns results to elements in a signed 32-bit integer strided output array. 2251 2252 ```c 2253 #include <stdint.h> 2254 2255 // Create underlying byte arrays: 2256 uint8_t x[] = { 0, 0, 0 }; 2257 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2258 2259 // Define a pointer to an array containing pointers to strided arrays: 2260 uint8_t *arrays[] = { x, out }; 2261 2262 // Define the strides: 2263 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per int32 2264 2265 // Define the number of elements over which to iterate: 2266 int64_t shape[] = { 3 }; 2267 2268 // Define a callback: 2269 int8_t scale( const int8_t x ) { 2270 return x + 10; 2271 } 2272 2273 // Apply the callback: 2274 stdlib_strided_s_i( arrays, shape, strides, (void *)scale ); 2275 ``` 2276 2277 The function accepts the following arguments: 2278 2279 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2280 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2281 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2282 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2283 2284 ```c 2285 void stdlib_strided_s_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2286 ``` 2287 2288 #### stdlib_strided_s_i_as_i_i( \*arrays[], \*shape, \*strides, \*fcn ) 2289 2290 Applies a unary callback accepting and returning signed 32-bit integers to a signed 8-bit integer strided input array and assigns results to elements in a signed 32-bit integer strided output array. 2291 2292 ```c 2293 #include <stdint.h> 2294 2295 // Create underlying byte arrays: 2296 uint8_t x[] = { 0, 0, 0 }; 2297 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2298 2299 // Define a pointer to an array containing pointers to strided arrays: 2300 uint8_t *arrays[] = { x, out }; 2301 2302 // Define the strides: 2303 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per int32 2304 2305 // Define the number of elements over which to iterate: 2306 int64_t shape[] = { 3 }; 2307 2308 // Define a callback: 2309 int32_t scale( const int32_t x ) { 2310 return x + 10; 2311 } 2312 2313 // Apply the callback: 2314 stdlib_strided_s_i_as_i_i( arrays, shape, strides, (void *)scale ); 2315 ``` 2316 2317 The function accepts the following arguments: 2318 2319 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2320 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2321 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2322 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 2323 2324 ```c 2325 void stdlib_strided_s_i_as_i_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2326 ``` 2327 2328 #### stdlib_strided_s_k( \*arrays[], \*shape, \*strides, \*fcn ) 2329 2330 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to a signed 16-bit integer, and assigns results to elements in a signed 16-bit integer strided output array. 2331 2332 ```c 2333 #include <stdint.h> 2334 2335 // Create underlying byte arrays: 2336 uint8_t x[] = { 0, 0, 0 }; 2337 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 2338 2339 // Define a pointer to an array containing pointers to strided arrays: 2340 uint8_t *arrays[] = { x, out }; 2341 2342 // Define the strides: 2343 int64_t strides[] = { 1, 2 }; // 1 byte per int8, 2 bytes per int16 2344 2345 // Define the number of elements over which to iterate: 2346 int64_t shape[] = { 3 }; 2347 2348 // Define a callback: 2349 int8_t scale( const int8_t x ) { 2350 return x + 10; 2351 } 2352 2353 // Apply the callback: 2354 stdlib_strided_s_k( arrays, shape, strides, (void *)scale ); 2355 ``` 2356 2357 The function accepts the following arguments: 2358 2359 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2360 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2361 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2362 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2363 2364 ```c 2365 void stdlib_strided_s_k( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2366 ``` 2367 2368 #### stdlib_strided_s_k_as_k_k( \*arrays[], \*shape, \*strides, \*fcn ) 2369 2370 Applies a unary callback accepting and returning signed 16-bit integers to a signed 8-bit integer strided input array and assigns results to elements in a signed 16-bit integer strided output array. 2371 2372 ```c 2373 #include <stdint.h> 2374 2375 // Create underlying byte arrays: 2376 uint8_t x[] = { 0, 0, 0 }; 2377 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 2378 2379 // Define a pointer to an array containing pointers to strided arrays: 2380 uint8_t *arrays[] = { x, out }; 2381 2382 // Define the strides: 2383 int64_t strides[] = { 1, 2 }; // 1 byte per int8, 2 bytes per int16 2384 2385 // Define the number of elements over which to iterate: 2386 int64_t shape[] = { 3 }; 2387 2388 // Define a callback: 2389 int16_t scale( const int16_t x ) { 2390 return x + 10; 2391 } 2392 2393 // Apply the callback: 2394 stdlib_strided_s_k_as_k_k( arrays, shape, strides, (void *)scale ); 2395 ``` 2396 2397 The function accepts the following arguments: 2398 2399 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2400 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2401 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2402 - **fcn**: `[in] void*` a `UnaryFcnInt16` function to apply provided as a `void` pointer. 2403 2404 ```c 2405 void stdlib_strided_s_k_as_k_k( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2406 ``` 2407 2408 #### stdlib_strided_s_s( \*arrays[], \*shape, \*strides, \*fcn ) 2409 2410 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array and assigns results to elements in a signed 8-bit integer strided output array. 2411 2412 ```c 2413 #include <stdint.h> 2414 2415 // Create underlying byte arrays: 2416 uint8_t x[] = { 0, 0, 0 }; 2417 uint8_t out[] = { 0, 0, 0 }; 2418 2419 // Define a pointer to an array containing pointers to strided arrays: 2420 uint8_t *arrays[] = { x, out }; 2421 2422 // Define the strides: 2423 int64_t strides[] = { 1, 1 }; // 1 byte per int8 2424 2425 // Define the number of elements over which to iterate: 2426 int64_t shape[] = { 3 }; 2427 2428 // Define a callback: 2429 int8_t scale( const int8_t x ) { 2430 return x + 10; 2431 } 2432 2433 // Apply the callback: 2434 stdlib_strided_s_s( arrays, shape, strides, (void *)scale ); 2435 ``` 2436 2437 The function accepts the following arguments: 2438 2439 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2440 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2441 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2442 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2443 2444 ```c 2445 void stdlib_strided_s_s( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2446 ``` 2447 2448 #### stdlib_strided_s_t( \*arrays[], \*shape, \*strides, \*fcn ) 2449 2450 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to an unsigned 16-bit integer, and assigns results to elements in an unsigned 16-bit integer strided output array. 2451 2452 ```c 2453 #include <stdint.h> 2454 2455 // Create underlying byte arrays: 2456 uint8_t x[] = { 0, 0, 0 }; 2457 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 2458 2459 // Define a pointer to an array containing pointers to strided arrays: 2460 uint8_t *arrays[] = { x, out }; 2461 2462 // Define the strides: 2463 int64_t strides[] = { 1, 2 }; // 1 byte per int8, 2 bytes per uint16 2464 2465 // Define the number of elements over which to iterate: 2466 int64_t shape[] = { 3 }; 2467 2468 // Define a callback: 2469 int8_t abs( const int8_t x ) { 2470 if ( x < 0 ) { 2471 return -x; 2472 } 2473 return x; 2474 } 2475 2476 // Apply the callback: 2477 stdlib_strided_s_t( arrays, shape, strides, (void *)abs ); 2478 ``` 2479 2480 The function accepts the following arguments: 2481 2482 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2483 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2484 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2485 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2486 2487 ```c 2488 void stdlib_strided_s_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2489 ``` 2490 2491 #### stdlib_strided_s_u( \*arrays[], \*shape, \*strides, \*fcn ) 2492 2493 Applies a unary callback accepting and returning signed 8-bit integers to a signed 8-bit integer strided input array, casts the callback's signed 8-bit integer return value to an unsigned 32-bit integer, and assigns results to elements in an unsigned 32-bit integer strided output array. 2494 2495 ```c 2496 #include <stdint.h> 2497 2498 // Create underlying byte arrays: 2499 uint8_t x[] = { 0, 0, 0 }; 2500 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2501 2502 // Define a pointer to an array containing pointers to strided arrays: 2503 uint8_t *arrays[] = { x, out }; 2504 2505 // Define the strides: 2506 int64_t strides[] = { 1, 4 }; // 1 byte per int8, 4 bytes per uint32 2507 2508 // Define the number of elements over which to iterate: 2509 int64_t shape[] = { 3 }; 2510 2511 // Define a callback: 2512 int8_t abs( const int8_t x ) { 2513 if ( x < 0 ) { 2514 return -x; 2515 } 2516 return x; 2517 } 2518 2519 // Apply the callback: 2520 stdlib_strided_s_u( arrays, shape, strides, (void *)abs ); 2521 ``` 2522 2523 The function accepts the following arguments: 2524 2525 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2526 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2527 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2528 - **fcn**: `[in] void*` a `UnaryFcnInt8` function to apply provided as a `void` pointer. 2529 2530 ```c 2531 void stdlib_strided_s_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2532 ``` 2533 2534 #### stdlib_strided_t_d( \*arrays[], \*shape, \*strides, \*fcn ) 2535 2536 Applies a unary callback accepting and returning unsigned 16-bit integers to an unsigned 16-bit integer strided input array, casts the callback's unsigned 16-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 2537 2538 ```c 2539 #include <stdint.h> 2540 2541 // Create underlying byte arrays: 2542 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2543 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2544 2545 // Define a pointer to an array containing pointers to strided arrays: 2546 uint8_t *arrays[] = { x, out }; 2547 2548 // Define the strides: 2549 int64_t strides[] = { 2, 8 }; // 2 bytes per uint16, 8 bytes per double 2550 2551 // Define the number of elements over which to iterate: 2552 int64_t shape[] = { 3 }; 2553 2554 // Define a callback: 2555 uint16_t scale( const uint16_t x ) { 2556 return x + 10; 2557 } 2558 2559 // Apply the callback: 2560 stdlib_strided_t_d( arrays, shape, strides, (void *)scale ); 2561 ``` 2562 2563 The function accepts the following arguments: 2564 2565 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2566 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2567 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2568 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 2569 2570 ```c 2571 void stdlib_strided_t_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2572 ``` 2573 2574 #### stdlib_strided_t_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 2575 2576 Applies a unary callback accepting and returning double-precision floating-point numbers to an unsigned 16-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 2577 2578 ```c 2579 #include <stdint.h> 2580 2581 // Create underlying byte arrays: 2582 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2583 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2584 2585 // Define a pointer to an array containing pointers to strided arrays: 2586 uint8_t *arrays[] = { x, out }; 2587 2588 // Define the strides: 2589 int64_t strides[] = { 2, 8 }; // 2 bytes per uint16, 8 bytes per double 2590 2591 // Define the number of elements over which to iterate: 2592 int64_t shape[] = { 3 }; 2593 2594 // Define a callback: 2595 double scale( const double x ) { 2596 return x + 10.0; 2597 } 2598 2599 // Apply the callback: 2600 stdlib_strided_t_d_as_d_d( arrays, shape, strides, (void *)scale ); 2601 ``` 2602 2603 The function accepts the following arguments: 2604 2605 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2606 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2607 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2608 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 2609 2610 ```c 2611 void stdlib_strided_t_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2612 ``` 2613 2614 #### stdlib_strided_t_f( \*arrays[], \*shape, \*strides, \*fcn ) 2615 2616 Applies a unary callback accepting and returning unsigned 16-bit integers to an unsigned 16-bit integer strided input array, casts the callback's unsigned 16-bit integer return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 2617 2618 ```c 2619 #include <stdint.h> 2620 2621 // Create underlying byte arrays: 2622 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2623 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2624 2625 // Define a pointer to an array containing pointers to strided arrays: 2626 uint8_t *arrays[] = { x, out }; 2627 2628 // Define the strides: 2629 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per float 2630 2631 // Define the number of elements over which to iterate: 2632 int64_t shape[] = { 3 }; 2633 2634 // Define a callback: 2635 uint16_t scale( const uint16_t x ) { 2636 return x + 10; 2637 } 2638 2639 // Apply the callback: 2640 stdlib_strided_t_f( arrays, shape, strides, (void *)scale ); 2641 ``` 2642 2643 The function accepts the following arguments: 2644 2645 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2646 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2647 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2648 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 2649 2650 ```c 2651 void stdlib_strided_t_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2652 ``` 2653 2654 #### stdlib_strided_t_f_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 2655 2656 Applies a unary callback accepting and returning double-precision floating-point numbers to an unsigned 16-bit integer strided input array, casts the callback's double-precision floating-point return value to a single-precision floating-point number, and assigns results to elements in a single-precision floating-point strided output array. 2657 2658 ```c 2659 #include <stdint.h> 2660 2661 // Create underlying byte arrays: 2662 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2663 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2664 2665 // Define a pointer to an array containing pointers to strided arrays: 2666 uint8_t *arrays[] = { x, out }; 2667 2668 // Define the strides: 2669 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per float 2670 2671 // Define the number of elements over which to iterate: 2672 int64_t shape[] = { 3 }; 2673 2674 // Define a callback: 2675 double scale( const double x ) { 2676 return x + 10.0; 2677 } 2678 2679 // Apply the callback: 2680 stdlib_strided_t_f_as_d_d( arrays, shape, strides, (void *)scale ); 2681 ``` 2682 2683 The function accepts the following arguments: 2684 2685 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2686 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2687 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2688 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 2689 2690 ```c 2691 void stdlib_strided_t_f_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2692 ``` 2693 2694 #### stdlib_strided_t_f_as_f_f( \*arrays[], \*shape, \*strides, \*fcn ) 2695 2696 Applies a unary callback accepting and returning single-precision floating-point numbers to an unsigned 16-bit integer strided input array and assigns results to elements in a single-precision floating-point strided output array. 2697 2698 ```c 2699 #include <stdint.h> 2700 2701 // Create underlying byte arrays: 2702 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2703 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2704 2705 // Define a pointer to an array containing pointers to strided arrays: 2706 uint8_t *arrays[] = { x, out }; 2707 2708 // Define the strides: 2709 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per float 2710 2711 // Define the number of elements over which to iterate: 2712 int64_t shape[] = { 3 }; 2713 2714 // Define a callback: 2715 float scale( const float x ) { 2716 return x + 10.0f; 2717 } 2718 2719 // Apply the callback: 2720 stdlib_strided_t_f_as_f_f( arrays, shape, strides, (void *)scale ); 2721 ``` 2722 2723 The function accepts the following arguments: 2724 2725 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2726 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2727 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2728 - **fcn**: `[in] void*` a `UnaryFcnFloat32` function to apply provided as a `void` pointer. 2729 2730 ```c 2731 void stdlib_strided_t_f_as_f_f( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2732 ``` 2733 2734 #### stdlib_strided_t_i( \*arrays[], \*shape, \*strides, \*fcn ) 2735 2736 Applies a unary callback accepting and returning unsigned 16-bit integers to an unsigned 16-bit integer strided input array, casts the callback's unsigned 16-bit integer return value to a signed 32-bit integer, and assigns results to elements in a signed 32-bit integer strided output array. 2737 2738 ```c 2739 #include <stdint.h> 2740 2741 // Create underlying byte arrays: 2742 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2743 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2744 2745 // Define a pointer to an array containing pointers to strided arrays: 2746 uint8_t *arrays[] = { x, out }; 2747 2748 // Define the strides: 2749 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per int32 2750 2751 // Define the number of elements over which to iterate: 2752 int64_t shape[] = { 3 }; 2753 2754 // Define a callback: 2755 uint16_t scale( const uint16_t x ) { 2756 return x + 10; 2757 } 2758 2759 // Apply the callback: 2760 stdlib_strided_t_i( arrays, shape, strides, (void *)scale ); 2761 ``` 2762 2763 The function accepts the following arguments: 2764 2765 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2766 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2767 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2768 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 2769 2770 ```c 2771 void stdlib_strided_t_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2772 ``` 2773 2774 #### stdlib_strided_t_i_as_i_i( \*arrays[], \*shape, \*strides, \*fcn ) 2775 2776 Applies a unary callback accepting and returning signed 32-bit integers to an unsigned 16-bit integer strided input array and assigns results to elements in a signed 32-bit integer strided output array. 2777 2778 ```c 2779 #include <stdint.h> 2780 2781 // Create underlying byte arrays: 2782 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2783 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2784 2785 // Define a pointer to an array containing pointers to strided arrays: 2786 uint8_t *arrays[] = { x, out }; 2787 2788 // Define the strides: 2789 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per int32 2790 2791 // Define the number of elements over which to iterate: 2792 int64_t shape[] = { 3 }; 2793 2794 // Define a callback: 2795 int32_t scale( const int32_t x ) { 2796 return x + 10; 2797 } 2798 2799 // Apply the callback: 2800 stdlib_strided_t_i_as_i_i( arrays, shape, strides, (void *)scale ); 2801 ``` 2802 2803 The function accepts the following arguments: 2804 2805 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2806 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2807 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2808 - **fcn**: `[in] void*` a `UnaryFcnInt32` function to apply provided as a `void` pointer. 2809 2810 ```c 2811 void stdlib_strided_t_i_as_i_i( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2812 ``` 2813 2814 #### stdlib_strided_t_t( \*arrays[], \*shape, \*strides, \*fcn ) 2815 2816 Applies a unary callback accepting and returning unsigned 16-bit integers to an unsigned 16-bit integer strided input array and assigns results to elements in an unsigned 16-bit integer strided output array. 2817 2818 ```c 2819 #include <stdint.h> 2820 2821 // Create underlying byte arrays: 2822 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2823 uint8_t out[] = { 0, 0, 0, 0, 0, 0 }; 2824 2825 // Define a pointer to an array containing pointers to strided arrays: 2826 uint8_t *arrays[] = { x, out }; 2827 2828 // Define the strides: 2829 int64_t strides[] = { 2, 2 }; // 2 bytes per uint16 2830 2831 // Define the number of elements over which to iterate: 2832 int64_t shape[] = { 3 }; 2833 2834 // Define a callback: 2835 uint16_t scale( const uint16_t x ) { 2836 return x + 10; 2837 } 2838 2839 // Apply the callback: 2840 stdlib_strided_t_t( arrays, shape, strides, (void *)scale ); 2841 ``` 2842 2843 The function accepts the following arguments: 2844 2845 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2846 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2847 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2848 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 2849 2850 ```c 2851 void stdlib_strided_t_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2852 ``` 2853 2854 #### stdlib_strided_t_u( \*arrays[], \*shape, \*strides, \*fcn ) 2855 2856 Applies a unary callback accepting and returning unsigned 16-bit integers to each element in an unsigned 16-bit integer strided input array, casts the callback's unsigned 16-bit integer return value to an unsigned 32-bit integer, and assigns results to elements in an unsigned 32-bit integer strided output array. 2857 2858 ```c 2859 #include <stdint.h> 2860 2861 // Create underlying byte arrays: 2862 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2863 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2864 2865 // Define a pointer to an array containing pointers to strided arrays: 2866 uint8_t *arrays[] = { x, out }; 2867 2868 // Define the strides: 2869 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per uint32 2870 2871 // Define the number of elements over which to iterate: 2872 int64_t shape[] = { 3 }; 2873 2874 // Define a callback: 2875 uint16_t scale( const uint16_t x ) { 2876 return x + 10; 2877 } 2878 2879 // Apply the callback: 2880 stdlib_strided_t_u( arrays, shape, strides, (void *)scale ); 2881 ``` 2882 2883 The function accepts the following arguments: 2884 2885 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2886 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2887 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2888 - **fcn**: `[in] void*` a `UnaryFcnUint16` function to apply provided as a `void` pointer. 2889 2890 ```c 2891 void stdlib_strided_t_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2892 ``` 2893 2894 #### stdlib_strided_t_u_as_u_u( \*arrays[], \*shape, \*strides, \*fcn ) 2895 2896 Applies a unary callback accepting and returning unsigned 32-bit integers to an unsigned 16-bit integer strided input array and assigns results to elements in an unsigned 32-bit integer strided output array. 2897 2898 ```c 2899 #include <stdint.h> 2900 2901 // Create underlying byte arrays: 2902 uint8_t x[] = { 0, 0, 0, 0, 0, 0 }; 2903 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2904 2905 // Define a pointer to an array containing pointers to strided arrays: 2906 uint8_t *arrays[] = { x, out }; 2907 2908 // Define the strides: 2909 int64_t strides[] = { 2, 4 }; // 2 bytes per uint16, 4 bytes per uint32 2910 2911 // Define the number of elements over which to iterate: 2912 int64_t shape[] = { 3 }; 2913 2914 // Define a callback: 2915 uint32_t scale( const uint32_t x ) { 2916 return x + 10; 2917 } 2918 2919 // Apply the callback: 2920 stdlib_strided_t_u_as_u_u( arrays, shape, strides, (void *)scale ); 2921 ``` 2922 2923 The function accepts the following arguments: 2924 2925 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2926 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2927 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2928 - **fcn**: `[in] void*` a `UnaryFcnUint32` function to apply provided as a `void` pointer. 2929 2930 ```c 2931 void stdlib_strided_t_u_as_u_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2932 ``` 2933 2934 #### stdlib_strided_u_d( \*arrays[], \*shape, \*strides, \*fcn ) 2935 2936 Applies a unary callback accepting and returning unsigned 32-bit integers to an unsigned 32-bit integer strided input array, casts the callback's unsigned 32-bit integer return value to a double-precision floating-point number, and assigns results to elements in a double-precision floating-point strided output array. 2937 2938 ```c 2939 #include <stdint.h> 2940 2941 // Create underlying byte arrays: 2942 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2943 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2944 2945 // Define a pointer to an array containing pointers to strided arrays: 2946 uint8_t *arrays[] = { x, out }; 2947 2948 // Define the strides: 2949 int64_t strides[] = { 4, 8 }; // 4 bytes per uint32, 8 bytes per double 2950 2951 // Define the number of elements over which to iterate: 2952 int64_t shape[] = { 3 }; 2953 2954 // Define a callback: 2955 uint32_t scale( const uint32_t x ) { 2956 return x + 10; 2957 } 2958 2959 // Apply the callback: 2960 stdlib_strided_u_d( arrays, shape, strides, (void *)scale ); 2961 ``` 2962 2963 The function accepts the following arguments: 2964 2965 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 2966 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 2967 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 2968 - **fcn**: `[in] void*` a `UnaryFcnUint32` function to apply provided as a `void` pointer. 2969 2970 ```c 2971 void stdlib_strided_u_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 2972 ``` 2973 2974 #### stdlib_strided_u_d_as_d_d( \*arrays[], \*shape, \*strides, \*fcn ) 2975 2976 Applies a unary callback accepting and returning double-precision floating-point numbers to an unsigned 32-bit integer strided input array and assigns results to elements in a double-precision floating-point strided output array. 2977 2978 ```c 2979 #include <stdint.h> 2980 2981 // Create underlying byte arrays: 2982 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2983 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 2984 2985 // Define a pointer to an array containing pointers to strided arrays: 2986 uint8_t *arrays[] = { x, out }; 2987 2988 // Define the strides: 2989 int64_t strides[] = { 4, 8 }; // 4 bytes per uint32, 8 bytes per double 2990 2991 // Define the number of elements over which to iterate: 2992 int64_t shape[] = { 3 }; 2993 2994 // Define a callback: 2995 double scale( const double x ) { 2996 return x + 10.0; 2997 } 2998 2999 // Apply the callback: 3000 stdlib_strided_u_d_as_d_d( arrays, shape, strides, (void *)scale ); 3001 ``` 3002 3003 The function accepts the following arguments: 3004 3005 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 3006 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 3007 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 3008 - **fcn**: `[in] void*` a `UnaryFcnFloat64` function to apply provided as a `void` pointer. 3009 3010 ```c 3011 void stdlib_strided_u_d_as_d_d( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 3012 ``` 3013 3014 #### stdlib_strided_u_u( \*arrays[], \*shape, \*strides, \*fcn ) 3015 3016 Applies a unary callback accepting and returning unsigned 32-bit integers to an unsigned 32-bit integer strided input array and assigns results to elements in an unsigned 32-bit integer strided output array. 3017 3018 ```c 3019 #include <stdint.h> 3020 3021 // Create underlying byte arrays: 3022 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 3023 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 3024 3025 // Define a pointer to an array containing pointers to strided arrays: 3026 uint8_t *arrays[] = { x, out }; 3027 3028 // Define the strides: 3029 int64_t strides[] = { 4, 4 }; // 4 bytes per uint32 3030 3031 // Define the number of elements over which to iterate: 3032 int64_t shape[] = { 3 }; 3033 3034 // Define a callback: 3035 uint32_t scale( const uint32_t x ) { 3036 return x + 10; 3037 } 3038 3039 // Apply the callback: 3040 stdlib_strided_u_u( arrays, shape, strides, (void *)scale ); 3041 ``` 3042 3043 The function accepts the following arguments: 3044 3045 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 3046 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 3047 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 3048 - **fcn**: `[in] void*` a `UnaryFcnUint32` function to apply provided as a `void` pointer. 3049 3050 ```c 3051 void stdlib_strided_u_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 3052 ``` 3053 3054 #### stdlib_strided_v_v( \*arrays[], \*shape, \*strides, \*fcn ) 3055 3056 Applies a unary callback accepting and returning unsigned 64-bit integers to an unsigned 64-bit integer strided input array and assigns results to elements in an unsigned 64-bit integer strided output array. 3057 3058 ```c 3059 #include <stdint.h> 3060 3061 // Create underlying byte arrays: 3062 uint8_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 3063 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 3064 3065 // Define a pointer to an array containing pointers to strided arrays: 3066 uint8_t *arrays[] = { x, out }; 3067 3068 // Define the strides: 3069 int64_t strides[] = { 8, 8 }; // 8 bytes per uint64 3070 3071 // Define the number of elements over which to iterate: 3072 int64_t shape[] = { 3 }; 3073 3074 // Define a callback: 3075 uint64_t scale( const uint64_t x ) { 3076 return x + 10; 3077 } 3078 3079 // Apply the callback: 3080 stdlib_strided_v_v( arrays, shape, strides, (void *)scale ); 3081 ``` 3082 3083 The function accepts the following arguments: 3084 3085 - **arrays**: `[inout] uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 3086 - **shape**: `[in] int64_t*` array whose only element is the number of elements over which to iterate. 3087 - **strides**: `[in] int64_t*` array containing strides (in bytes) for each strided array. 3088 - **fcn**: `[in] void*` a `UnaryFcnUint64` function to apply provided as a `void` pointer. 3089 3090 ```c 3091 void stdlib_strided_v_v( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ); 3092 ``` 3093 3094 <!-- macros --> 3095 3096 * * * 3097 3098 #### STDLIB_STRIDED_UNARY_LOOP_PREAMBLE 3099 3100 Macro containing the preamble for a loop which operates on strided array elements. 3101 3102 ```c 3103 STDLIB_STRIDED_UNARY_LOOP_PREMABLE { 3104 // Loop body... 3105 } 3106 ``` 3107 3108 The macro expects the following variables to be defined: 3109 3110 - **arrays**: `uint8_t**` array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array. 3111 - **shape**: `int64_t*` array whose only element is the number of elements over which to iterate. 3112 - **strides**: `int64_t*` array containing strides (in bytes) for each strided array. 3113 3114 The macro defines the following variables: 3115 3116 - **ip1**: `uint8_t*` pointer to the first indexed element of the input strided array. 3117 - **op1**: `uint8_t*` pointer to the first indexed element of the output strided array. 3118 - **is1**: `int64_t` index increment for the input strided array. 3119 - **os1**: `int64_t` index increment for the output strided array. 3120 - **n**: `int64_t` number of indexed elements. 3121 - **i**: `int64_t` loop counter. 3122 3123 ```c 3124 #define STDLIB_STRIDED_UNARY_LOOP_PREAMBLE \ 3125 uint8_t *ip1 = arrays[ 0 ]; \ 3126 uint8_t *op1 = arrays[ 1 ]; \ 3127 int64_t is1 = strides[ 0 ]; \ 3128 int64_t os1 = strides[ 1 ]; \ 3129 int64_t n = shape[ 0 ]; \ 3130 int64_t i; \ 3131 if ( n <= 0 ) { \ 3132 return; \ 3133 } \ 3134 if ( is1 < 0 ) { \ 3135 ip1 += (1-n) * is1; \ 3136 } \ 3137 if ( os1 < 0 ) { \ 3138 op1 += (1-n) * os1; \ 3139 } \ 3140 for ( i = 0; i < n; i++, ip1 += is1, op1 += os1 ) 3141 ``` 3142 3143 #### STDLIB_STRIDED_UNARY_LOOP_TWO_OUT_PREAMBLE 3144 3145 Macro containing the preamble for a loop which operates on strided array elements and updates two strided output arrays. 3146 3147 ```c 3148 STDLIB_STRIDED_UNARY_LOOP_TWO_OUT_PREAMBLE { 3149 // Loop body... 3150 } 3151 ``` 3152 3153 The macro expects the following variables to be defined: 3154 3155 - **arrays**: `uint8_t**` array whose first element is a pointer to a strided input array and whose last two elements are pointers to strided output arrays. 3156 - **shape**: `int64_t*` array whose only element is the number of elements over which to iterate. 3157 - **strides**: `int64_t*` array containing strides (in bytes) for each strided array. 3158 3159 The macro defines the following variables: 3160 3161 - **ip1**: `uint8_t*` pointer to the first indexed element of the input strided array. 3162 - **op1**: `uint8_t*` pointer to the first indexed element of the first output strided array. 3163 - **op2**: `uint8_t*` pointer to the first indexed element of the second output strided array. 3164 - **is1**: `int64_t` index increment for the input strided array. 3165 - **os1**: `int64_t` index increment for the first output strided array. 3166 - **os2**: `int64_t` index increment for the second output strided array. 3167 - **n**: `int64_t` number of indexed elements. 3168 - **i**: `int64_t` loop counter. 3169 3170 ```c 3171 #define STDLIB_STRIDED_UNARY_LOOP_TWO_OUT_PREAMBLE \ 3172 uint8_t *ip1 = arrays[ 0 ]; \ 3173 uint8_t *op1 = arrays[ 1 ]; \ 3174 uint8_t *op2 = arrays[ 2 ]; \ 3175 int64_t is1 = strides[ 0 ]; \ 3176 int64_t os1 = strides[ 1 ]; \ 3177 int64_t os2 = strides[ 2 ]; \ 3178 int64_t n = shape[ 0 ]; \ 3179 int64_t i; \ 3180 if ( n <= 0 ) { \ 3181 return; \ 3182 } \ 3183 if ( is1 < 0 ) { \ 3184 ip1 += (1-n) * is1; \ 3185 } \ 3186 if ( os1 < 0 ) { \ 3187 op1 += (1-n) * os1; \ 3188 } \ 3189 if ( os2 < 0 ) { \ 3190 op2 += (1-n) * os2; \ 3191 } \ 3192 for ( i = 0; i < n; i++, ip1 += os1, op1 += os1, op2 += os2 ) 3193 ``` 3194 3195 #### STDLIB_STRIDED_UNARY_LOOP_INLINE( tin, tout, expr ) 3196 3197 Macro for a unary loop which inlines an expression. 3198 3199 ```c 3200 STDLIB_STRIDED_UNARY_LOOP_INLINE( double, double, *out = in1 * in1 ) 3201 ``` 3202 3203 The macro expects the following arguments: 3204 3205 - **tin**: input strided array element type. 3206 - **tout**: output strided array element type. 3207 - **expr**: expression to inline. 3208 3209 In addition to the variables defined by the `STDLIB_STRIDED_UNARY_LOOP_PREAMBLE` macro, the macro defines the following variables: 3210 3211 - **in1**: `<tin>` input strided array element. 3212 - **out**: `<tout>*` pointer to an output strided array element. 3213 3214 The macro expects a provided expression to operate on `in1` and to store the result via `*out`. 3215 3216 ```c 3217 #define STDLIB_STRIDED_UNARY_LOOP_INLINE( tin, tout, expr ) \ 3218 STDLIB_STRIDED_UNARY_LOOP_PREAMBLE { \ 3219 const tin in1 = *(tin *)ip1; \ 3220 tout *out = (tout *)op1; \ 3221 expr; \ 3222 } 3223 ``` 3224 3225 #### STDLIB_STRIDED_UNARY_LOOP_CLBK( tin, tout ) 3226 3227 Macro for a unary loop which invokes a callback. 3228 3229 ```c 3230 STDLIB_STRIDED_UNARY_LOOP_CLBK( double, double ) 3231 ``` 3232 3233 The macro expects the following arguments: 3234 3235 - **tin**: input strided array element data type. 3236 - **tout**: output strided array element data type. 3237 3238 In addition to the variables expected by `STDLIB_STRIDED_UNARY_LOOP_PREAMBLE`, the macro expects the following variables to be defined: 3239 3240 - **f**: unary callback. 3241 3242 In addition to the variables defined by the `STDLIB_STRIDED_UNARY_LOOP_PREAMBLE`, the macro defines the following variables: 3243 3244 - **x**: `<tin>` input strided array element. 3245 3246 ```c 3247 #define STDLIB_STRIDED_UNARY_LOOP_CLBK( tin, tout ) \ 3248 STDLIB_STRIDED_UNARY_LOOP_PREAMBLE { \ 3249 const tin x = *(tin *)ip1; \ 3250 *(tout *)op1 = (tout)f( x ); \ 3251 } 3252 ``` 3253 3254 #### STDLIB_STRIDED_UNARY_LOOP_CLBK_ARG_CAST( tin, tout, fin ) 3255 3256 Macro for a unary loop which invokes a callback requiring arguments be explicitly cast to a different type. 3257 3258 ```c 3259 STDLIB_STRIDED_UNARY_LOOP_CLBK_ARG_CAST( float, float, double ) 3260 ``` 3261 3262 The macro expects the following arguments: 3263 3264 - **tin**: input strided array element data type. 3265 - **tout**: output strided array element data type. 3266 - **fin**: callback argument data type. 3267 3268 In addition to the variables expected by `STDLIB_STRIDED_UNARY_LOOP_PREAMBLE`, the macro expects the following variables to be defined: 3269 3270 - **f**: unary callback. 3271 3272 In addition to the variables defined by the `STDLIB_STRIDED_UNARY_LOOP_PREAMBLE`, the macro defines the following variables: 3273 3274 - **x**: `<tin>` input strided array element. 3275 3276 ```c 3277 #define STDLIB_STRIDED_UNARY_LOOP_CLBK_ARG_CAST( tin, tout, fin ) \ 3278 STDLIB_STRIDED_UNARY_LOOP_PREAMBLE { \ 3279 const tin x = *(tin *)ip1; \ 3280 *(tout *)op1 = (tout)f( (fin)x ); \ 3281 } 3282 ``` 3283 3284 </section> 3285 3286 <!-- /.usage --> 3287 3288 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 3289 3290 <section class="notes"> 3291 3292 </section> 3293 3294 <!-- /.notes --> 3295 3296 <!-- C API usage examples. --> 3297 3298 * * * 3299 3300 <section class="examples"> 3301 3302 ### Examples 3303 3304 ```c 3305 #include "stdlib/strided/base/unary.h" 3306 #include <stdint.h> 3307 #include <stdio.h> 3308 #include <inttypes.h> 3309 3310 // Define a callback: 3311 static double scale( const double x ) { 3312 return x * 10.0; 3313 } 3314 3315 int main() { 3316 // Create underlying byte arrays: 3317 uint8_t x[] = { 1, 4, 7 }; 3318 uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 3319 3320 // Define a pointer to an array containing pointers to strided arrays: 3321 uint8_t *arrays[] = { x, out }; 3322 3323 // Define the strides: 3324 int64_t strides[] = { 1, 8 }; // 1 byte per uint8, 8 bytes per double 3325 3326 // Define the number of elements over which to iterate: 3327 int64_t shape[] = { 3 }; 3328 3329 // Apply the callback: 3330 stdlib_strided_b_d_as_d_d( arrays, shape, strides, (void *)scale ); 3331 3332 // Print the contents of the output array: 3333 uint8_t *op1 = out; 3334 for ( int64_t i = 0; i < shape[0]; i++, op1 += strides[1] ) { 3335 const double v = *(double *)op1; 3336 printf( "out[ %"PRId64" ] = %lf\n", i, v ); 3337 } 3338 } 3339 ``` 3340 3341 </section> 3342 3343 <!-- /.examples --> 3344 3345 </section> 3346 3347 <!-- /.c --> 3348 3349 <section class="links"> 3350 3351 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray 3352 3353 </section> 3354 3355 <!-- /.links -->