-
-
Notifications
You must be signed in to change notification settings - Fork 771
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 C implementation for math/base/special/minmax
#6296
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
* @param info callback data | ||
* @return Node-API value | ||
*/ | ||
static napi_value addon( napi_env env, napi_callback_info info ) { |
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.
Have kept the addon logic as this for now and going through https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/napi to have an idea for a utility for void
functions.
for this file I have refactored this code-block.
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.
Turns out we can convert it a very simplified fashion like:-
static napi_value addon( napi_env env, napi_callback_info info ) {
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, y, argv, 1 );
STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, z, zlen, argv, 2 );
double min;
double max;
stdlib_base_minmax( x, y, &min, &max );
double *op = (double *)z;
op[ 0 ] = min;
op[ 1 ] = max;
return NULL;
}
just searching for an utility that can accumulate void
function.
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.
something similar was also done in rempio2
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.
@Neerajpathak07 You can do something like this:
In addon.c
, you can have:
#include "stdlib/math/base/special/minmax.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_double.h"
#include "stdlib/napi/argv_float64array.h"
#include <node_api.h>
/**
* Receives JavaScript callback invocation data.
*
* @param env environment under which the function is invoked
* @param info callback data
* @return Node-API value
*/
static napi_value addon( napi_env env, napi_callback_info info ) {
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, y, argv, 1 );
STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, out, outlen, argv, 2 );
stdlib_base_minmax( x, y, &out[ 0 ], &out[ 1 ] );
return NULL;
}
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
And, for native.js
:
function minmax( x, y ) {
var out = new Float64Array( 2 );
addon( x, y, out );
return [ out[ 0 ], out[ 1 ] ];
}
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.
@gunjjoshi Bingo!!
I had drafted a similar logic earlier but was confused on how to go about the void function. But you just clarified it thank you soo much!!
@gunjjoshi LMK your opinion on this!! |
Not sure though why only C examples CI tests are failing for |
Progresses #649,
Resolves #2106.
Description
This pull request:
math/base/special/minmax
Related Issues
This pull request:
@stdlib/math/base/special/minmax
#2106Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers