Skip to content
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

Closed
wants to merge 3 commits into from
Closed

feat: add napi/argv-complex64 #1760

wants to merge 3 commits into from

Conversation

Rejoan-Sardar
Copy link
Contributor

Resolves #817 .

Description

What is the purpose of this pull request?

This pull request C APIs for converting a JavaScript Complex64 object instance to a native C data type stdlib_complex64_t

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

  • Read, understood, and followed the [contributing guidelines][contributing].

@stdlib-js/reviewers

@Planeshifter Planeshifter changed the title feat: add @stdlib/napi/argv-complex64 feat: add napi/argv-complex64 Mar 7, 2024
Copy link
Member

@Pranavchiku Pranavchiku left a 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.

lib/node_modules/@stdlib/napi/argv-complex64/binding.gyp Outdated Show resolved Hide resolved
@@ -0,0 +1,53 @@
# @license Apache-2.0
#
# Copyright (c) 2022 The Stdlib Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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"
Copy link
Member

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?

Copy link
Contributor Author

@Rejoan-Sardar Rejoan-Sardar Mar 8, 2024

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"
Copy link
Member

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; \
Copy link
Member

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?

Copy link
Member

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.

Comment on lines +40 to +41
* wrapper( x );
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify return value.

Copy link
Member

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.

lib/node_modules/@stdlib/napi/argv-complex64/src/addon.c Outdated Show resolved Hide resolved
@Pranavchiku Pranavchiku added Feature Issue or pull request for adding a new feature. Native Addons Issue involves or relates to Node.js native add-ons. Needs Changes Pull request which needs changes before being merged. labels Mar 8, 2024
@Rejoan-Sardar
Copy link
Contributor Author

@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 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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 ) \
Copy link
Member

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"
Copy link
Member

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"
Copy link
Member

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
Copy link
Member

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"
Copy link
Member

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;
Copy link
Member

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 );
Copy link
Member

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;
Copy link
Member

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." );
Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@kgryte kgryte left a 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.

@kgryte
Copy link
Member

kgryte commented Mar 17, 2024

@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.

@Rejoan-Sardar
Copy link
Contributor Author

Thanks for pointing this out @kgryte

@kgryte kgryte mentioned this pull request Apr 7, 2024
1 task
@Rejoan-Sardar Rejoan-Sardar closed this by deleting the head repository Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Native Addons Issue involves or relates to Node.js native add-ons. Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Add @stdlib/napi/argv-complex64
3 participants