|
| 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 | +# N-API ndarray dtype |
| 22 | + |
| 23 | +> C API for returning the ndarray [data type][@stdlib/ndarray/dtypes] corresponding to a data type string. |
| 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 | +```c |
| 40 | +#include "stdlib/ndarray/base/napi/dtype_string_to_dtype.h" |
| 41 | +``` |
| 42 | + |
| 43 | +#### stdlib_ndarray_napi_dtype_string_to_dtype( const char \*str ) |
| 44 | + |
| 45 | +Returns the ndarray [data type][@stdlib/ndarray/dtypes] corresponding to a data type string. |
| 46 | + |
| 47 | +```cpp |
| 48 | +#include "stdlib/ndarray/base/napi/dtype_string_to_dtype.h" |
| 49 | +#include "stdlib/ndarray/dtypes.h" |
| 50 | +#include <node_api.h> |
| 51 | +#include <assert.h> |
| 52 | + |
| 53 | +// Add-on function export... |
| 54 | +napi_value addon( napi_env env, napi_callback_info info ) { |
| 55 | + |
| 56 | + // ... |
| 57 | + |
| 58 | + // Get function arguments... |
| 59 | + size_t argc = 1; |
| 60 | + napi_value argv[ 1 ]; |
| 61 | + napi_status status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); |
| 62 | + assert( status == napi_ok ); |
| 63 | + |
| 64 | + // ... |
| 65 | + |
| 66 | + // Get a string argument... |
| 67 | + char str[ 1024 ]; |
| 68 | + size_t len; |
| 69 | + status = napi_get_value_string_utf8( env, argv[ 0 ], (char *)str, 1024, &len ); |
| 70 | + assert( status == napi_ok ); |
| 71 | + |
| 72 | + // ... |
| 73 | + |
| 74 | + // Return the corresponding ndarray data type for the input typed array: |
| 75 | + enum STDLIB_NDARRAY_DTYPE dtype = stdlib_ndarray_napi_dtype_string_to_dtype( str ); |
| 76 | + |
| 77 | + // ... |
| 78 | + |
| 79 | +} |
| 80 | +``` |
| 81 | +
|
| 82 | +</section> |
| 83 | +
|
| 84 | +<!-- /.usage --> |
| 85 | +
|
| 86 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 87 | +
|
| 88 | +<section class="notes"> |
| 89 | +
|
| 90 | +</section> |
| 91 | +
|
| 92 | +<!-- /.notes --> |
| 93 | +
|
| 94 | +<!-- Package usage examples. --> |
| 95 | +
|
| 96 | +<section class="examples"> |
| 97 | +
|
| 98 | +</section> |
| 99 | +
|
| 100 | +<!-- /.examples --> |
| 101 | +
|
| 102 | +<!-- 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. --> |
| 103 | +
|
| 104 | +<section class="references"> |
| 105 | +
|
| 106 | +</section> |
| 107 | +
|
| 108 | +<!-- /.references --> |
| 109 | +
|
| 110 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 111 | +
|
| 112 | +<section class="links"> |
| 113 | +
|
| 114 | +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib |
| 115 | +
|
| 116 | +</section> |
| 117 | +
|
| 118 | +<!-- /.links --> |
0 commit comments