addon.c (2337B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "stdlib/ndarray/base/napi/unary.h" 20 #include "stdlib/ndarray/base/function_object.h" 21 #include "stdlib/ndarray/base/unary.h" 22 #include "stdlib/ndarray/dtypes.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_ndarray_unary_test_function"; 37 38 // Define a list of ndarray functions: 39 static ndarrayFcn functions[] = { 40 stdlib_ndarray_d_d 41 }; 42 43 // Define the **ndarray** argument types for each ndarray function: 44 static int32_t types[] = { 45 STDLIB_NDARRAY_FLOAT64, STDLIB_NDARRAY_FLOAT64 46 }; 47 48 // Define a list of ndarray function "data" (in this case, callbacks): 49 static void *data[] = { 50 (void *)identity 51 }; 52 53 // Create an ndarray function object: 54 static const struct ndarrayFunctionObject obj = { 55 // ndarray function name: 56 name, 57 58 // Number of input ndarrays: 59 1, 60 61 // Number of output ndarrays: 62 1, 63 64 // Total number of ndarray arguments (nin + nout): 65 2, 66 67 // Array containing ndarray functions: 68 functions, 69 70 // Number of ndarray 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 ndarray argument types for a corresponding ndarray function: 74 types, 75 76 // Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective ndarray function (note: the number of pointers should match the number of ndarray functions): 77 data 78 }; 79 80 STDLIB_NDARRAY_NAPI_MODULE_UNARY( obj )