Skip to content

Commit 1d45338

Browse files
Utkarsh GuptaUtkarsh Gupta
Utkarsh Gupta
authored and
Utkarsh Gupta
committed
added stdlib/napi/argv-complex128
1 parent 1faaaa6 commit 1d45338

File tree

11 files changed

+119
-148
lines changed

11 files changed

+119
-148
lines changed

lib/node_modules/@stdlib/napi/argv-complex128/README.md

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2022 The Stdlib Authors.
5+
Copyright (c) 2024 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@ limitations under the License.
1818
1919
-->
2020

21-
# argv_complex128array
21+
# argv_complex128
2222

23-
> Convert a Node-API value to a double-precision complex floating-point array.
23+
> Convert a Node-API value to a double-precision complex floating-point number.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -37,7 +37,7 @@ limitations under the License.
3737
## Usage
3838

3939
```javascript
40-
var headerDir = require( '@stdlib/napi/argv-complex128array' );
40+
var headerDir = require( '@stdlib/napi/argv-complex128' );
4141
```
4242

4343
#### headerDir
@@ -68,7 +68,7 @@ var dir = headerDir;
6868
## Examples
6969

7070
```javascript
71-
var headerDir = require( '@stdlib/napi/argv-complex128array' );
71+
var headerDir = require( '@stdlib/napi/argv-complex128' );
7272

7373
console.log( headerDir );
7474
// => <string>
@@ -101,27 +101,25 @@ console.log( headerDir );
101101
### Usage
102102

103103
```c
104-
#include "stdlib/napi/argv_complex128array.h"
104+
#include "stdlib/napi/argv_complex128.h"
105105
```
106106

107-
#### stdlib_napi_argv_complex128array( env, value, \*\*data, \*length, \*message, \*err )
107+
#### stdlib_napi_argv_complex128( env, value, \*out, \*message, \*err )
108108

109-
Converts a Node-API value to a double-precision complex floating-point array.
109+
Converts a Node-API value to a double-precision complex floating-point number ( stdlib_complex128_t ).
110110

111111
```c
112-
#include "stdlib/napi/argv_complex128array.h"
112+
#include "stdlib/napi/argv_complex128.h"
113113
#include <node_api.h>
114-
#include <stdint.h>
115114

116115
static napi_value addon( napi_env env, napi_callback_info info ) {
117116
napi_value value;
118117

119118
// ...
120119

121-
double *X;
122-
int64_t len;
120+
stdlib_complex128_t out;
123121
napi_value err;
124-
napi_status status = stdlib_napi_argv_complex128array( env, value, &X, &len, "Must be a typed array.", &err );
122+
napi_status status = stdlib_napi_argv_complex128( env, value, &out, "Must be a Complex128 instance.", &err );
125123
assert( status == napi_ok );
126124
if ( err != NULL ) {
127125
assert( napi_throw( env, err ) == napi_ok );
@@ -136,64 +134,49 @@ The function accepts the following arguments:
136134
137135
- **env**: `[in] napi_env` environment under which the function is invoked.
138136
- **value**: `[in] napi_value` Node-API value.
139-
- **data**: `[out] double**` pointer for returning a reference to the output array.
140-
- **length**: `[out] int64_t*` pointer for returning the number of array elements.
137+
- **out**: `[out] stdlib_complex_128_t*` destination for storing output value.
141138
- **message**: `[in] char*` error message.
142139
- **err**: `[out] napi_value*` pointer for storing a JavaScript error. If not provided a number, the function sets `err` with a JavaScript error; otherwise, `err` is set to `NULL`.
143140
144141
```c
145-
napi_status stdlib_napi_argv_complex128array( const napi_env env, const napi_value value, double **data, int64_t *length, const char *message, napi_value *err );
142+
napi_status stdlib_napi_argv_complex128( const napi_env env, const napi_value value, stdlib_complex128_t *out, const char *message, napi_value *err );
146143
```
147144

148145
The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success).
149146

150-
#### STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, X, len, argv, index )
147+
#### STDLIB_NAPI_ARGV_COMPLEX128( env, name, argv, index )
151148

152-
Macro for converting an add-on callback argument to a double-precision complex floating-point array.
149+
Macro for converting an add-on callback argument to a double-precision complex floating-point number.
153150

154151
```c
155-
#include "stdlib/napi/argv_complex128array.h"
152+
#include "stdlib/napi/argv_complex128.h"
156153
#include "stdlib/napi/argv.h"
154+
#include "stdlib/complex/float64.h"
157155
#include <node_api.h>
158-
#include <stdint.h>
159156

160-
static void fcn( const double *X, const int64_t xlen, double *Y, const int64_t ylen ) {
161-
int64_t len;
162-
int64_t i;
163-
164-
if ( xlen > ylen ) {
165-
len = ylen;
166-
} else {
167-
len = xlen;
168-
}
169-
for ( i = 0; i < len*2; i++ ) {
170-
Y[ i ] = X[ i ];
171-
}
157+
static stdlib_complex128_t fcn( const stdlib_complex128_t v ) {
158+
return v;
172159
}
173160

174161
// ...
175162

176163
static napi_value addon( napi_env env, napi_callback_info info ) {
177164
// Retrieve add-on callback arguments:
178-
STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
165+
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
179166

180167
// Convert the first argument to a C type:
181-
STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, X, xlen, argv, 0 );
182-
183-
// Convert the second argument to a C type:
184-
STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, Y, ylen, argv, 1 );
168+
STDLIB_NAPI_ARGV_COMPLEX128( env, value, argv, 0 );
185169

186170
// ...
187171

188-
fcn( X, xlen, Y, ylen );
172+
stdlib_complex128_t out = fcn( value );
189173
}
190174
```
191175
192176
The macro expects the following arguments:
193177
194178
- **env**: environment under which the callback is invoked.
195-
- **X**: output variable name for the array.
196-
- **len**: output variable name for the array length.
179+
- **name**: output variable name.
197180
- **argv**: name of the variable containing add-on callback arguments.
198181
- **index**: argument index.
199182
@@ -205,10 +188,6 @@ The macro expects the following arguments:
205188
206189
<section class="notes">
207190
208-
## Notes
209-
210-
- A double-precision complex floating-point array is a double-precision floating-point array having interleaved real and imaginary components, such that each element of the double-precision complex floating-point array consists of two adjacent (in memory) double-precision floating-point numbers.
211-
212191
</section>
213192
214193
<!-- /.notes -->

lib/node_modules/@stdlib/napi/argv-complex128/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/napi/argv-complex128/docs/types/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -16,67 +16,52 @@
1616
* limitations under the License.
1717
*/
1818

19-
#ifndef STDLIB_NAPI_ARGV_COMPLEX128ARRAY_H
20-
#define STDLIB_NAPI_ARGV_COMPLEX128ARRAY_H
19+
#ifndef STDLIB_NAPI_ARGV_COMPLEX128_H
20+
#define STDLIB_NAPI_ARGV_COMPLEX128_H
2121

2222
#include "stdlib/napi/argv.h"
2323
#include "stdlib/assert/napi/status_ok.h"
24+
#include "stdlib/complex/float64.h"
2425
#include <node_api.h>
25-
#include <stdint.h>
2626

2727
/**
28-
* Macro for converting an add-on callback argument to a double-precision complex floating-point array.
28+
* Macro for converting an add-on callback argument to a double-precision complex floating-point number.
2929
*
3030
* @param env environment under which the function is invoked
31-
* @param X output variable name for the array
32-
* @param len output variable name for the array length
31+
* @param name output variable name for the array
3332
* @param argv name of the variable containing add-on callback arguments
3433
* @param index argument index
3534
*
3635
* @example
37-
* #include "stdlib/napi/argv_complex128array.h"
36+
* #include "stdlib/napi/argv_complex128.h"
3837
* #include "stdlib/napi/argv.h"
38+
* #include "stdlib/complex/float64.h"
3939
* #include <node_api.h>
40-
* #include <stdint.h>
4140
*
42-
* static void fcn( const double *X, const int64_t xlen, double *Y, const int64_t ylen ) {
43-
* int64_t len;
44-
* int64_t i;
45-
*
46-
* if ( xlen > ylen ) {
47-
* len = ylen;
48-
* } else {
49-
* len = xlen;
50-
* }
51-
* for ( i = 0; i < len*2; i++ ) {
52-
* Y[ i ] = X[ i ];
53-
* }
41+
* static stdlib_complex128_t fcn( const stdlib_complex128_t ) {
42+
* return v;
5443
* }
5544
*
5645
* // ...
5746
*
5847
* static napi_value addon( napi_env env, napi_callback_info info ) {
5948
* // Retrieve add-on callback arguments:
60-
* STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
49+
* STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
6150
*
6251
* // Convert the first argument to a C type:
63-
* STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, X, xlen, argv, 0 );
64-
*
65-
* // Convert the second argument to a C type:
66-
* STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, Y, ylen, argv, 1 );
52+
* STDLIB_NAPI_ARGV_COMPLEX128( env, value, argv, 0 );
6753
*
6854
* // ...
6955
*
70-
* fcn( X, xlen, Y, ylen );
56+
* stdlib_complex128_t out = fcn( value );
7157
* }
7258
*/
73-
#define STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, X, len, argv, index ) \
74-
napi_value __STDLIB_NAPI_ARGV_COMPLEX128ARRAY_ERR_ ## X; \
75-
int64_t len; \
76-
double *X; \
77-
stdlib_napi_argv_complex128array( env, argv[ index ], &X, &len, "invalid argument. " STDLIB_NAPI_ARGV_INDEX2ORDINAL( index ) " argument must be a Float64Array.", &__STDLIB_NAPI_ARGV_COMPLEX128ARRAY_ERR_ ## X ); \
78-
if ( __STDLIB_NAPI_ARGV_COMPLEX128ARRAY_ERR_ ## X != NULL ) { \
79-
STDLIB_ASSERT_NAPI_STATUS_OK_RET_NULL( env, napi_throw( env, __STDLIB_NAPI_ARGV_COMPLEX128ARRAY_ERR_ ## X ), "" ) \
59+
#define STDLIB_NAPI_ARGV_COMPLEX128( env, name, argv, index ) \
60+
napi_value __STDLIB_NAPI_ARGV_COMPLEX128_ERR_ ## name; \
61+
stdlib_complex128_t name; \
62+
stdlib_napi_argv_complex128( env, argv[ index ], &name, "invalid argument. " STDLIB_NAPI_ARGV_INDEX2ORDINAL( index ) " argument must be a Complex128 instance.", &__STDLIB_NAPI_ARGV_COMPLEX128_ERR_ ## name ); \
63+
if ( __STDLIB_NAPI_ARGV_COMPLEX128_ERR_ ## name != NULL ) { \
64+
STDLIB_ASSERT_NAPI_STATUS_OK_RET_NULL( env, napi_throw( env, __STDLIB_NAPI_ARGV_COMPLEX128_ERR_ ## name ), "" ) \
8065
return NULL; \
8166
}
8267

@@ -88,12 +73,12 @@ extern "C" {
8873
#endif
8974

9075
/**
91-
* Converts a Node-API value to a double-precision complex floating-point array.
76+
* Converts a Node-API value to a double-precision complex floating-point number.
9277
*/
93-
napi_status stdlib_napi_argv_complex128array( const napi_env env, const napi_value value, double **data, int64_t *length, const char *message, napi_value *err );
78+
napi_status stdlib_napi_argv_complex128( const napi_env env, const napi_value value, stdlib_complex128_t *out, const char *message, napi_value *err );
9479

9580
#ifdef __cplusplus
9681
}
9782
#endif
9883

99-
#endif // !STDLIB_NAPI_ARGV_COMPLEX128ARRAY_H
84+
#endif // !STDLIB_NAPI_ARGV_COMPLEX128_H

lib/node_modules/@stdlib/napi/argv-complex128/lib/native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -38,12 +38,12 @@ var addon = require( './../src/addon.node' );
3838
*
3939
* var x = new Complex128( 5.0, 3.0 );
4040
*
41-
* wrapper( x );
41+
* wrapper( x );
4242
*/
4343
function wrapper( v ) {
44-
// if ( isComplex128Array( v ) ) {
45-
// v = reinterpret( v, 0 );
46-
// }
44+
if ( isComplex128( v ) ) {
45+
v = { re: v.re, im: v.im };
46+
}
4747
return addon( v );
4848
}
4949

lib/node_modules/@stdlib/napi/argv-complex128/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2022 The Stdlib Authors.
4+
# Copyright (c) 2024 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/napi/argv-complex128/src/addon.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -16,11 +16,22 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/napi/argv_complex128array.h"
19+
#include "stdlib/napi/argv_complex128.h"
2020
#include "stdlib/napi/argv.h"
21+
#include "stdlib/complex/flo at64.h"
2122
#include <node_api.h>
2223
#include <assert.h>
23-
#include <stdint.h>
24+
25+
/**
26+
* Identity function.
27+
*
28+
* @private
29+
* @param v input value
30+
* @return input value
31+
*/
32+
static stdlib_complex128_t identity( const stdlib_complex128_t v ) {
33+
return v;
34+
}
2435

2536
/**
2637
* Receives JavaScript callback invocation data.
@@ -31,15 +42,21 @@
3142
* @return Node-API value
3243
*/
3344
static napi_value addon( napi_env env, napi_callback_info info ) {
34-
int64_t i;
35-
3645
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 )
37-
STDLIB_NAPI_ARGV_COMPLEX128ARRAY( env, X, len, argv, 0 )
46+
STDLIB_NAPI_ARGV_COMPLEX128( env, value, argv, 0 )
47+
stdlib_complex128_t out = identity( value );
48+
return out;
49+
// napi_value v;
50+
// napi_status status = napi_create_object(env, &v);
51+
// assert(status == napi_ok);
52+
53+
// status = napi_set_named_property(env, v, "re", out.re);
54+
// assert(status == napi_ok);
55+
56+
// status = napi_set_named_property(env, v, "im", out.im);
57+
// assert(status == napi_ok);
3858

39-
for ( i = 0; i < len*2; i++ ) {
40-
X[ i ] = 1.0;
41-
}
42-
return NULL;
59+
// return v;
4360
}
4461

4562
/**

0 commit comments

Comments
 (0)