Skip to content

Commit 5fff0d1

Browse files
committed
Add C API to return the ndarray data type corresponding to a provided N-API typed array type
1 parent 98292f2 commit 5fff0d1

File tree

6 files changed

+397
-0
lines changed

6 files changed

+397
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2020 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 an N-API typed array type.
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/typedarray_type_to_dtype.h"
41+
```
42+
43+
#### stdlib_ndarray_napi_typedarray_type_to_dtype( napi_typedarray_type vtype )
44+
45+
Returns the ndarray [data type][@stdlib/ndarray/dtypes] corresponding to an N-API typed array type.
46+
47+
```cpp
48+
#include "stdlib/ndarray/base/napi/typedarray_type_to_dtype.h"
49+
#include <node_api.h>
50+
#include <assert.h>
51+
52+
// Add-on function export...
53+
napi_value addon( napi_env env, napi_callback_info info ) {
54+
55+
// ...
56+
57+
// Get function arguments...
58+
size_t argc = 1;
59+
napi_value argv[ 1 ];
60+
napi_status status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
61+
assert( status == napi_ok );
62+
63+
// ...
64+
65+
// Get a typed array argument...
66+
napi_typedarray_type vtype;
67+
size_t xlen;
68+
void *X;
69+
status = napi_get_typedarray_info( env, argv[ 0 ], &vtype, &xlen, &X, nullptr, nullptr );
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_typedarray_type_to_dtype( vtype );
76+
77+
// ...
78+
}
79+
```
80+
81+
</section>
82+
83+
<!-- /.usage -->
84+
85+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
86+
87+
<section class="notes">
88+
89+
</section>
90+
91+
<!-- /.notes -->
92+
93+
<!-- Package usage examples. -->
94+
95+
<section class="examples">
96+
97+
</section>
98+
99+
<!-- /.examples -->
100+
101+
<!-- 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. -->
102+
103+
<section class="references">
104+
105+
</section>
106+
107+
<!-- /.references -->
108+
109+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
110+
111+
<section class="links">
112+
113+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib
114+
115+
</section>
116+
117+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#ifndef STDLIB_NDARRAY_BASE_NAPI_TYPEDARRAY_TYPE_TO_DTYPE_H
20+
#define STDLIB_NDARRAY_BASE_NAPI_TYPEDARRAY_TYPE_TO_DTYPE_H
21+
22+
#include "stdlib/ndarray/dtypes.h"
23+
#include <node_api.h>
24+
25+
/*
26+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
27+
*/
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/**
33+
* Returns the ndarray data type corresponding to an N-API typed array type.
34+
*/
35+
enum STDLIB_NDARRAY_DTYPE stdlib_ndarray_napi_typedarray_type_to_dtype( napi_typedarray_type vtype );
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
41+
#endif // !STDLIB_NDARRAY_BASE_NAPI_TYPEDARRAY_TYPE_TO_DTYPE_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
'use strict';
20+
21+
/**
22+
* C API for returning the ndarray data type corresponding to an N-API typed array type.
23+
*
24+
* @module @stdlib/ndarray/base/napi/typedarray-type-to-dtype
25+
*/
26+
27+
// FUNCTIONS //
28+
29+
/**
30+
* Main execution sequence.
31+
*
32+
* @private
33+
* @throws {Error} invalid import
34+
*/
35+
function main() {
36+
throw new Error( 'invalid import. This module is not intended for use in JavaScript environments.' );
37+
}
38+
39+
40+
// MAIN //
41+
42+
main();
43+
44+
45+
// EXPORTS //
46+
47+
module.exports = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"options": {},
3+
"fields": [
4+
{
5+
"field": "src",
6+
"resolve": true,
7+
"relative": true
8+
},
9+
{
10+
"field": "include",
11+
"resolve": true,
12+
"relative": true
13+
},
14+
{
15+
"field": "libraries",
16+
"resolve": false,
17+
"relative": false
18+
},
19+
{
20+
"field": "libpath",
21+
"resolve": true,
22+
"relative": false
23+
}
24+
],
25+
"confs": [
26+
{
27+
"src": [
28+
"./src/main.c"
29+
],
30+
"include": [
31+
"./include"
32+
],
33+
"libraries": [],
34+
"libpath": [],
35+
"dependencies": [
36+
"@stdlib/ndarray/dtypes"
37+
]
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@stdlib/ndarray/base/napi/typedarray-type-to-dtype",
3+
"version": "0.0.0",
4+
"description": "C API for returning the ndarray data type corresponding to an N-API typed array type.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"include": "./include",
19+
"lib": "./lib",
20+
"src": "./src"
21+
},
22+
"scripts": {},
23+
"homepage": "https://github.com/stdlib-js/stdlib",
24+
"repository": {
25+
"type": "git",
26+
"url": "git://github.com/stdlib-js/stdlib.git"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/stdlib-js/stdlib/issues"
30+
},
31+
"dependencies": {},
32+
"devDependencies": {},
33+
"engines": {
34+
"node": ">=0.10.0",
35+
"npm": ">2.7.0"
36+
},
37+
"os": [
38+
"aix",
39+
"darwin",
40+
"freebsd",
41+
"linux",
42+
"macos",
43+
"openbsd",
44+
"sunos",
45+
"win32",
46+
"windows"
47+
],
48+
"keywords": [
49+
"stdlib",
50+
"stdtypes",
51+
"types",
52+
"base",
53+
"ndarray",
54+
"napi",
55+
"dtype"
56+
],
57+
"__stdlib__": {}
58+
}

0 commit comments

Comments
 (0)