time-to-botec

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

README.md (5454B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2021 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 # Add-on Arguments
     22 
     23 > C API for validating, extracting, and transforming (to native C types) function arguments provided to an ndarray Node-API add-on interface.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var headerDir = require( '@stdlib/ndarray/base/napi/addon-arguments' );
     41 ```
     42 
     43 #### headerDir
     44 
     45 Absolute file path for the directory containing header files for C APIs.
     46 
     47 ```javascript
     48 var dir = headerDir;
     49 // returns <string>
     50 ```
     51 
     52 </section>
     53 
     54 <!-- /.usage -->
     55 
     56 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     57 
     58 <section class="notes">
     59 
     60 </section>
     61 
     62 <!-- /.notes -->
     63 
     64 <!-- Package usage examples. -->
     65 
     66 <section class="examples">
     67 
     68 ## Examples
     69 
     70 ```javascript
     71 var headerDir = require( '@stdlib/ndarray/base/napi/addon-arguments' );
     72 
     73 console.log( headerDir );
     74 // => <string>
     75 ```
     76 
     77 </section>
     78 
     79 <!-- /.examples -->
     80 
     81 <!-- C interface documentation. -->
     82 
     83 * * *
     84 
     85 <section class="c">
     86 
     87 ## C APIs
     88 
     89 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     90 
     91 <section class="intro">
     92 
     93 </section>
     94 
     95 <!-- /.intro -->
     96 
     97 <!-- C usage documentation. -->
     98 
     99 <section class="usage">
    100 
    101 ### Usage
    102 
    103 ```c
    104 #include "stdlib/ndarray/base/napi/addon_arguments.h"
    105 ```
    106 
    107 <!-- lint disable maximum-heading-length -->
    108 
    109 #### stdlib_ndarray_napi_addon_arguments( env, argv, nargs, nin, \*arrays[], \*err )
    110 
    111 Validates, extracts, and transforms (to native C types) function arguments provided to an ndarray Node-API add-on interface.
    112 
    113 ```c
    114 #include <node_api.h>
    115 #include <stdint.h>
    116 #include <assert.h>
    117 
    118 // ...
    119 
    120 /**
    121 * Receives JavaScript callback invocation data.
    122 *
    123 * @param env    environment under which the function is invoked
    124 * @param info   callback data
    125 * @return       Node-API value
    126 */
    127 napi_value addon( napi_env env, napi_callback_info info ) {
    128     napi_status status;
    129 
    130     // ...
    131 
    132     int64_t nargs = 6;
    133     int64_t nin = 2;
    134 
    135     // Get callback arguments:
    136     size_t argc = 6;
    137     napi_value argv[ 6 ];
    138     status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
    139     assert( status == napi_ok );
    140 
    141     // ...
    142 
    143     // Process the provided arguments:
    144     struct ndarray *arrays[ 3 ];
    145 
    146     napi_value err;
    147     status = stdlib_ndarray_napi_addon_arguments( env, argv, nargs, nin, arrays, &err );
    148     assert( status == napi_ok );
    149 
    150     // ...
    151 
    152 }
    153 
    154 // ...
    155 ```
    156 
    157 The function accepts the following arguments:
    158 
    159 -   **env**: `[in] napi_env` environment under which the function is invoked.
    160 -   **argv**: `[in] napi_value*` ndarray function arguments.
    161 -   **nargs**: `[in] int64_t` total number of expected arguments.
    162 -   **nin**: `[in] int64_t` number of input ndarray arguments.
    163 -   **arrays**: `[out] struct ndarrays**` destination array for storing pointers to both input and output ndarrays.
    164 -   **err**: `[out] napi_value*` pointer for storing a JavaScript error.
    165 
    166 ```c
    167 napi_status stdlib_ndarray_napi_addon_arguments( const napi_env env, const napi_value *argv, const int64_t nargs, const int64_t nin, struct ndarray *arrays[], napi_value *err );
    168 ```
    169 
    170 The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success).
    171 
    172 </section>
    173 
    174 <!-- /.usage -->
    175 
    176 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    177 
    178 <section class="notes">
    179 
    180 ### Notes
    181 
    182 -   The function assumes the following argument order:
    183 
    184     ```text
    185     [ ib1, im1, ib2, im2, ..., ob1, om1, ob2, om2, ... ]
    186     ```
    187     where
    188 
    189     -   `ib#` is a data buffer for an input ndarray.
    190     -   `im#` is meta data for an input ndarray.
    191     -   `ob#` is a data buffer for an output ndarray.
    192     -   `om#` is meta data for an output ndarray.
    193 
    194 -   The function may return one of the following JavaScript errors:
    195 
    196     -   `Error`: unable to allocate memory when processing input ndarray.
    197     -   `Error`: unable to allocate memory when processing output ndarray.
    198 
    199 </section>
    200 
    201 <!-- /.notes -->
    202 
    203 <!-- C API usage examples. -->
    204 
    205 <section class="examples">
    206 
    207 </section>
    208 
    209 <!-- /.examples -->
    210 
    211 </section>
    212 
    213 <!-- /.c -->
    214 
    215 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    216 
    217 <section class="references">
    218 
    219 </section>
    220 
    221 <!-- /.references -->
    222 
    223 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    224 
    225 <section class="links">
    226 
    227 </section>
    228 
    229 <!-- /.links -->