-
-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add napi/argv-complex64
#1760
Conversation
napi/argv-complex64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested changes, once addressed this PR can be reviewed.
@@ -0,0 +1,53 @@ | |||
# @license Apache-2.0 | |||
# | |||
# Copyright (c) 2022 The Stdlib Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Copyright (c) 2022 The Stdlib Authors. | |
# Copyright (c) 2024 The Stdlib Authors. |
|
||
#include "stdlib/napi/argv.h" | ||
#include "stdlib/assert/napi/status_ok.h" | ||
#include "stdlib/complex/float32.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pranavchiku I saw that some of argv package already used these that's why I used in my implemented package.
If they are of no use, I will remove them
* @example | ||
* #include "stdlib/napi/argv_complex64.h" | ||
* #include "stdlib/napi/argv.h" | ||
* #include "stdlib/complex/float32.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question
*/ | ||
#define STDLIB_NAPI_ARGV_COMPLEX64( env, name, argv, index ) \ | ||
napi_value __STDLIB_NAPI_ARGV_COMPLEX64_ERR_ ## name; \ | ||
stdlib_complex64_t name; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are using stdlib_complex64_t
we will need to include a particular header, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rejoan-Sardar You did not address this.
* wrapper( x ); | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rejoan-Sardar You did not resolve this.
@Pranavchiku I have addressed all the issues you mentioned in your review. Please take a look at the changes |
Signed-off-by: Rejoan Sardar <[email protected]>
* #include "stdlib/napi/argv_complex64.h" | ||
* #include <node_api.h> | ||
* | ||
* static stdlib_complex64_t fcn( const stdlib_complex64_t ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* static stdlib_complex64_t fcn( const stdlib_complex64_t ) { | |
* static stdlib_complex64_t fcn( const stdlib_complex64_t v ) { |
* stdlib_complex64_t out = fcn( value ); | ||
* } | ||
*/ | ||
#define STDLIB_NAPI_ARGV_COMPLEX64( env, name, argv, index ) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As done elsewhere (see https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/napi/argv-double/include/stdlib/napi/argv_double.h), align \
at 80 characters, except for those lines which are longer than 80 chars.
#ifndef STDLIB_NAPI_ARGV_COMPLEX64_H | ||
#define STDLIB_NAPI_ARGV_COMPLEX64_H | ||
|
||
#include "stdlib/assert/napi/status_ok.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing an include for stdlib/napi/argv.h
.
* @param index argument index | ||
* | ||
* @example | ||
* #include "stdlib/napi/argv_complex64.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing the same header in this example, as well. Please refer to https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/napi/argv-double/include/stdlib/napi/argv_double.h and investigate accordingly.
* | ||
* @private | ||
* @param {Complex64} v - input value | ||
* @returns {stdlib_complex64_t} input value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. We don't embed C types in JavaScript JSDoc.
"confs": [ | ||
{ | ||
"src": [ | ||
"./src/main.c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have mixed TAB and space indentation. This file should be 2-space indentation.
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ) | ||
STDLIB_NAPI_ARGV_COMPLEX64( env, value, argv, 0 ) | ||
stdlib_complex64_t out = identity( value ); | ||
return out; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. out
is not a Node-API value.
static napi_value addon( napi_env env, napi_callback_info info ) { | ||
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ) | ||
STDLIB_NAPI_ARGV_COMPLEX64( env, value, argv, 0 ) | ||
stdlib_complex64_t out = identity( value ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also mirror what we did in https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/napi/argv-double/src/addon.c#L47. Namely, this file is intended to verify that we can successfully extract a complex number object. As such, we will be passing in a known value and we should assert that it has expected values for real and imaginary components. You can use @stdlib/complex/realf
and @stdlib/complex/imagf
to retrieve the individual components.
return napi_ok; | ||
} | ||
|
||
bool hprop; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing the stdbool.h
header in the list of includes above.
status = napi_has_named_property( env, value, "re", &hprop ); | ||
assert( status == napi_ok ); | ||
if ( !hprop ) { | ||
status = napi_throw_type_error( env, NULL, "Invalid argument. The Complex64 object must have a real component." ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow error message conventions.
return NULL; | ||
} | ||
|
||
single real; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is clear to me that you did not actually test this implementation. The C type should be float
. Similarly, there is no napi_get_value_single
API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kgryte This was my first PR and on that time I'm not aware lots of thing. After that I'm not go through it now I will revisit it and change accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs considerable work before it can be merged. I left an initial round of comments.
@Rejoan-Sardar Please ensure you have locally tested before you indicate that a PR is ready for review and please only mark conversations as "resolved" if you have actually resolved the comments. |
Thanks for pointing this out @kgryte |
Resolves #817 .
Description
This pull request C APIs for converting a JavaScript Complex64 object instance to a native C data type stdlib_complex64_t
Related Issues
This pull request:
@stdlib/napi/argv-complex64
#817Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers