time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

k_u.c (2335B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2020 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 #include "stdlib/strided/base/unary/k_u.h"
     20 #include "stdlib/strided/base/unary/typedefs.h"
     21 #include "stdlib/strided/base/unary/macros.h"
     22 #include <stdint.h>
     23 
     24 /**
     25 * 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.
     26 *
     27 * @param arrays   array whose first element is a pointer to a strided input array and whose last element is a pointer to a strided output array
     28 * @param shape    array whose only element is the number of elements over which to iterate
     29 * @param strides  array containing strides (in bytes) for each strided array
     30 * @param fcn      callback
     31 *
     32 * @example
     33 * #include "stdlib/strided/base/unary/k_u.h"
     34 * #include <stdint.h>
     35 *
     36 * // Create underlying byte arrays:
     37 * uint8_t x[] = { 0, 0, 0, 0, 0, 0 };
     38 * uint8_t out[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     39 *
     40 * // Define a pointer to an array containing pointers to strided arrays:
     41 * uint8_t *arrays[] = { x, out };
     42 *
     43 * // Define the strides:
     44 * int64_t strides[] = { 2, 4 }; // 2 bytes per int16, 4 bytes per uint32
     45 *
     46 * // Define the number of elements over which to iterate:
     47 * int64_t shape[] = { 3 };
     48 *
     49 * // Define a callback:
     50 * int16_t abs( const int16_t x ) {
     51 *     if ( x < 0 ) {
     52 *         return -x;
     53 *     }
     54 *     return x;
     55 * }
     56 *
     57 * // Apply the callback:
     58 * stdlib_strided_k_u( arrays, shape, strides, (void *)abs );
     59 */
     60 void stdlib_strided_k_u( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ) {
     61 	UnaryFcnInt16 *f = (UnaryFcnInt16 *)fcn;
     62 	STDLIB_STRIDED_UNARY_LOOP_CLBK( int16_t, uint32_t )
     63 }