Skip to content

Commit 7d02ddf

Browse files
committed
feat: add napi/argv-strided-booleanarray2d
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent c1d72a0 commit 7d02ddf

19 files changed

Lines changed: 1414 additions & 0 deletions

File tree

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
<!-- lint disable maximum-heading-length -->
22+
23+
# argv_strided_booleanarray2d
24+
25+
> Convert a Node-API value representing a two-dimensional strided array to a boolean array.
26+
27+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
28+
29+
<section class="intro">
30+
31+
</section>
32+
33+
<!-- /.intro -->
34+
35+
<!-- Package usage documentation. -->
36+
37+
<section class="usage">
38+
39+
## Usage
40+
41+
```javascript
42+
var headerDir = require( '@stdlib/napi/argv-strided-booleanarray2d' );
43+
```
44+
45+
#### headerDir
46+
47+
Absolute file path for the directory containing header files for C APIs.
48+
49+
```javascript
50+
var dir = headerDir;
51+
// returns <string>
52+
```
53+
54+
</section>
55+
56+
<!-- /.usage -->
57+
58+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
59+
60+
<section class="notes">
61+
62+
</section>
63+
64+
<!-- /.notes -->
65+
66+
<!-- Package usage examples. -->
67+
68+
<section class="examples">
69+
70+
## Examples
71+
72+
```javascript
73+
var headerDir = require( '@stdlib/napi/argv-strided-booleanarray2d' );
74+
75+
console.log( headerDir );
76+
// => <string>
77+
```
78+
79+
</section>
80+
81+
<!-- /.examples -->
82+
83+
<!-- C interface documentation. -->
84+
85+
* * *
86+
87+
<section class="c">
88+
89+
## C APIs
90+
91+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
92+
93+
<section class="intro">
94+
95+
</section>
96+
97+
<!-- /.intro -->
98+
99+
<!-- C usage documentation. -->
100+
101+
<section class="usage">
102+
103+
### Usage
104+
105+
```c
106+
#include "stdlib/napi/argv_strided_booleanarray2d.h"
107+
```
108+
109+
#### stdlib_napi_argv_strided_booleanarray2d( env, M, N, strideX1, strideX2, value, \*\*data, \*message1, \*message2, \*err )
110+
111+
Converts a Node-API value representing a two-dimensional strided array to a boolean array.
112+
113+
```c
114+
#include "stdlib/napi/argv_strided_booleanarray2d.h"
115+
#include <node_api.h>
116+
#include <stdint.h>
117+
#include <stdbool.h>
118+
119+
static napi_value addon( napi_env env, napi_callback_info info ) {
120+
napi_value value;
121+
122+
// ...
123+
124+
int64_t M = 100;
125+
int64_t N = 100;
126+
int64_t strideX1 = 100;
127+
int64_t strideX2 = 1;
128+
129+
// ...
130+
131+
bool *X;
132+
napi_value err;
133+
napi_status status = stdlib_napi_argv_strided_booleanarray2d( env, M, N, strideX1, strideX2, value, &X, "Must be a typed array.", "Must have sufficient elements.", &err );
134+
assert( status == napi_ok );
135+
if ( err != NULL ) {
136+
assert( napi_throw( env, err ) == napi_ok );
137+
return NULL;
138+
}
139+
140+
// ...
141+
}
142+
```
143+
144+
The function accepts the following arguments:
145+
146+
- **env**: `[in] napi_env` environment under which the function is invoked.
147+
- **M**: `[in] int64_t` number of rows.
148+
- **N**: `[in] int64_t` number of columns.
149+
- **strideX1**: `[in] int64_t` stride length along the first dimension.
150+
- **strideX2**: `[in] int64_t` stride length along the second dimension.
151+
- **value**: `[in] napi_value` Node-API value.
152+
- **data**: `[out] bool**` pointer for returning a reference to the output array.
153+
- **message1**: `[in] char*` error message if a value is not a `Uint8Array`.
154+
- **message2**: `[in] char*` error message if a value has insufficient elements.
155+
- **err**: `[out] napi_value*` pointer for storing a JavaScript error. If not provided a `Uint8Array` or sufficient elements, the function sets `err` with a JavaScript error; otherwise, `err` is set to `NULL`.
156+
157+
```c
158+
napi_status stdlib_napi_argv_strided_booleanarray2d( const napi_env env, const int64_t M, const int64_t N, const int64_t strideX1, const int64_t strideX2, const napi_value value, bool **data, const char *message1, const char *message2, napi_value *err );
159+
```
160+
161+
The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success).
162+
163+
#### STDLIB_NAPI_ARGV_STRIDED_BOOLEANARRAY2D( env, X, M, N, strideX1, strideX2, argv, index )
164+
165+
Macro for converting an add-on callback argument to a two-dimensional strided boolean array.
166+
167+
```c
168+
#include "stdlib/napi/argv_strided_booleanarray2d.h"
169+
#include "stdlib/napi/argv_int64.h"
170+
#include "stdlib/napi/argv.h"
171+
#include <node_api.h>
172+
#include <stdint.h>
173+
#include <stdbool.h>
174+
175+
static void fcn( const int64_t M, const int64_t N, const bool *X, const int64_t strideX1, const int64_t strideX2, bool *Y, const int64_t strideY1, const int64_t strideY2 ) {
176+
int64_t i;
177+
int64_t j;
178+
for ( i = 0; i < M; i++ ) {
179+
for ( j = 0; j < N; j++ ) {
180+
Y[ (i*strideY1)+(j*strideY2) ] = X[ (i*strideX1)+(j*strideX2) ];
181+
}
182+
}
183+
}
184+
185+
// ...
186+
187+
static napi_value addon( napi_env env, napi_callback_info info ) {
188+
// Retrieve add-on callback arguments:
189+
STDLIB_NAPI_ARGV( env, info, argv, argc, 8 );
190+
191+
// Convert the number of rows and columns to C types:
192+
STDLIB_NAPI_ARGV_INT64( env, M, argv, 0 );
193+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 1 );
194+
195+
// Convert the stride arguments to C types:
196+
STDLIB_NAPI_ARGV_INT64( env, strideX1, argv, 3 );
197+
STDLIB_NAPI_ARGV_INT64( env, strideX2, argv, 4 );
198+
STDLIB_NAPI_ARGV_INT64( env, strideY1, argv, 6 );
199+
STDLIB_NAPI_ARGV_INT64( env, strideY2, argv, 7 );
200+
201+
// Convert the arrays to C types:
202+
STDLIB_NAPI_ARGV_STRIDED_BOOLEANARRAY2D( env, X, M, N, strideX1, strideX2, argv, 2 );
203+
STDLIB_NAPI_ARGV_STRIDED_BOOLEANARRAY2D( env, Y, M, N, strideY1, strideY2, argv, 5 );
204+
205+
// ...
206+
207+
fcn( M, N, X, strideX1, strideX2, Y, strideY1, strideY2 );
208+
}
209+
```
210+
211+
The macro expects the following arguments:
212+
213+
- **env**: environment under which the callback is invoked.
214+
- **X**: output variable name for the array.
215+
- **M**: number of rows.
216+
- **N**: number of columns.
217+
- **strideX1**: stride length along the first dimension.
218+
- **strideX2**: stride length along the second dimension.
219+
- **argv**: name of the variable containing add-on callback arguments.
220+
- **index**: argument index.
221+
222+
</section>
223+
224+
<!-- /.usage -->
225+
226+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
227+
228+
<section class="notes">
229+
230+
</section>
231+
232+
<!-- /.notes -->
233+
234+
<!-- C API usage examples. -->
235+
236+
<section class="examples">
237+
238+
</section>
239+
240+
<!-- /.examples -->
241+
242+
</section>
243+
244+
<!-- /.c -->
245+
246+
<!-- 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. -->
247+
248+
<section class="references">
249+
250+
</section>
251+
252+
<!-- /.references -->
253+
254+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
255+
256+
<section class="related">
257+
258+
</section>
259+
260+
<!-- /.related -->
261+
262+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
263+
264+
<section class="links">
265+
266+
</section>
267+
268+
<!-- /.links -->

0 commit comments

Comments
 (0)