time-to-botec

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

addon.c (2426B)


      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/napi/unary.h"
     20 #include "stdlib/strided/dtypes.h"
     21 #include "stdlib/strided/base/function_object.h"
     22 #include "stdlib/strided/base/unary.h"
     23 #include <stdint.h>
     24 
     25 /**
     26 * Evaluates the identity function for a double-precision floating-point number.
     27 *
     28 * @param x   input value
     29 * @return    input value
     30 */
     31 static double identity( const double x ) {
     32 	return x;
     33 }
     34 
     35 // Define an interface name:
     36 static const char name[] = "stdlib_strided_unary_test_function";
     37 
     38 // Define a list of strided array functions:
     39 static StridedArrayFcn functions[] = {
     40 	stdlib_strided_d_d
     41 };
     42 
     43 // Define the **strided array** argument types for each strided array function:
     44 static int32_t types[] = {
     45 	STDLIB_STRIDED_FLOAT64, STDLIB_STRIDED_FLOAT64
     46 };
     47 
     48 // Define a list of strided array function "data" (in this case, callbacks):
     49 static void *data[] = {
     50 	(void *)identity
     51 };
     52 
     53 // Create a strided array function object:
     54 static const struct StridedFunctionObject obj = {
     55 	// Strided array function name:
     56 	name,
     57 
     58 	// Number of input strided arrays:
     59 	1,
     60 
     61 	// Number of output strided arrays:
     62 	1,
     63 
     64 	// Total number of strided array arguments (nin + nout):
     65 	2,
     66 
     67 	// Array containing strided array functions:
     68 	functions,
     69 
     70 	// Number of strided array functions:
     71 	1,
     72 
     73 	// Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of strided array argument types for a corresponding strided array function:
     74 	types,
     75 
     76 	// Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective strided array function (note: the number of pointers should match the number of strided array functions):
     77 	data
     78 };
     79 
     80 STDLIB_STRIDED_NAPI_MODULE_UNARY( obj )