Skip to content

refactor: update blas/ext/base/sdssum to follow current project conventions #1727

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

Closed
wants to merge 4 commits into from
Closed

refactor: update blas/ext/base/sdssum to follow current project conventions #1727

wants to merge 4 commits into from

Conversation

kunal-511
Copy link

@kunal-511 kunal-511 commented Mar 6, 2024

Resolves #1525

Description

What is the purpose of this pull request?

This pull request updates @stdlib/blas/ext/base/sdssum to follow current project conventions.

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.


@stdlib-js/reviewers

@kunal-511
Copy link
Author

@Planeshifter Please review my PR?

for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
var x = filledarrayBy( len, 'float64', rand );
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. The dtype should be float32 here and everywhere else in this PR.

@@ -36,7 +37,7 @@ var sdssum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( sdssum instanceof Error )
};

var rand = uniform( -100.0, 100.0 );
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
var rand = uniform( -100.0, 100.0 );
var rand = uniform( -100.0, 100.0 );

Comment on lines 29 to 30
var y = sdssum( x.length, x, 1 );
console.log( y );
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
var y = sdssum( x.length, x, 1 );
console.log( y );
var v = sdssum( x.length, x, 1 );
console.log( v );

No need to change the variable name here.

Comment on lines 51 to 55
offset = minViewBufferIndex( N, stride, offset );
if ( stride < 0 ) {
offset += (N-1) * stride;
}
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
view = offsetView( x, offset );
Copy link
Member

Choose a reason for hiding this comment

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

@@ -1,5 +1,9 @@
{
"options": {},
"options": {
Copy link
Member

Choose a reason for hiding this comment

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

Please convert this file to 2-space indentation.

"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float64array"
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. The input array should be a float32 array.

]
}
]
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Trailing newline. Please ensure you have installed EditorConfig, as mentioned in the development guide.

Comment on lines 37 to 46
STDLIB_NAPI_ARGV(env, info, argv, argc, 3);
STDLIB_NAPI_ARGV_INT64(env, N, argv, 0);
STDLIB_NAPI_ARGV_INT64(env, strideX, argv, 2);
STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY(env, X, N, strideX, argv, 1);

napi_value v;
napi_status status = napi_create_double(env, c_sdssum(N, (double *)X, strideX), &v);
assert(status == napi_ok);

return v;
Copy link
Member

Choose a reason for hiding this comment

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

This should be TAB indentation. As mentioned above, input array should be float32, not float64. L43 should be (float *)X.

* @param info callback data
* @return Node-API value
*/
static napi_value addon(napi_env env, napi_callback_info info)
Copy link
Member

Choose a reason for hiding this comment

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

Please adhere to project spacing conventions.

return v;
}

STDLIB_NAPI_MODULE_EXPORT_FCN(addon)
Copy link
Member

Choose a reason for hiding this comment

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

Trailing newline.

@@ -45,7 +45,7 @@ tape( 'main export is a function', opts, function test( t ) {
});

tape( 'the function has an arity of 4', opts, function test( t ) {
t.strictEqual( sdssum.length, 4, 'has expected arity' );
t.strictEqual( sdssum.length, 4, 'returns expected value' );
Copy link
Member

Choose a reason for hiding this comment

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

The changes in this file are incomplete. You should refactor to avoid the use of floor. See reference PRs linked to in the OP.

@@ -21,7 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );

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

@@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );

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

@@ -36,7 +36,7 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function has an arity of 4', function test( t ) {
t.strictEqual( sdssum.length, 4, 'has expected arity' );
t.strictEqual( sdssum.length, 4, 'returns expected value' );
Copy link
Member

Choose a reason for hiding this comment

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

Refactoring is incomplete. Remove the use of floor.

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.

Left various comments. Please pay particular attention to similar PRs and commits and match changes and conventions in those changesets as closely as possible.

@kgryte kgryte added Native Addons Issue involves or relates to Node.js native add-ons. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. Needs Changes Pull request which needs changes before being merged. labels Mar 6, 2024
@kgryte kgryte changed the title I have make the necessary changes to refactor sdssum to follow curren… refactor: update blas/ext/base/sdssum to follow current project conventions Mar 6, 2024
@kgryte
Copy link
Member

kgryte commented Mar 6, 2024

Please also check the box in the OP indicating that you have read and understood the contribution guidelines.

@kunal-511
Copy link
Author

@kgryte Thanks for your review, I will implement these ass soon as possible

@kunal-511
Copy link
Author

@kgryte
The requested changes have been addressed. Please take a look

@@ -44,8 +44,8 @@
"dependencies": [
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-int64",
"@stdlib/napi/argv-strided-float64array"
"@stdlib/napi/argv-int32",
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. Should be int64.

@@ -19,8 +19,8 @@
#include "stdlib/blas/base/sdssum.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_int64.h"
#include "stdlib/napi/argv_strided_float64array.h"
#include "stdlib/napi/argv_int32.h"
Copy link
Member

Choose a reason for hiding this comment

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

This should be int64.

@@ -21,7 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );
//var floor = require( '@stdlib/math/base/special/floor' );
Copy link
Member

Choose a reason for hiding this comment

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

Don't comment out. Remove.

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );

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

for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
var x = filledarrayBy( len, 'float64', rand );
Copy link
Member

Choose a reason for hiding this comment

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

float32

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );

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

var pkg = require( './../package.json' ).name;
var sdssum = require( './../lib/ndarray.js' );



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

Copy link
Member

Choose a reason for hiding this comment

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

Please ensure you have your local dev environment setup, including running make init. Your PR contains various lint errors which project automated tooling can catch, but only if you have properly set things up locally.

for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
var x = filledarrayBy( len, 'float64', rand );
Copy link
Member

Choose a reason for hiding this comment

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

float32

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );

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

for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
var x = filledarrayBy( len, 'float64', rand );
Copy link
Member

Choose a reason for hiding this comment

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

float32

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 currently has a number of issues. Please consult other packages in blas/ext/base and try to adhere as closely as possible. For example, see https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/ssumors. But don't just copy-paste. Consider what is appropriate to emulate and where to deviate based on the needs of sdssum. I suggested consulting sasum, but only for how ndarray views are handled.

@kunal-511 kunal-511 requested a review from kgryte March 7, 2024 04:35
@kunal-511
Copy link
Author

kunal-511 commented Mar 7, 2024

@kgryte @Planeshifter
The requested changes have been addressed. Please take a look

@kunal-511
Copy link
Author

@kgryte @Planeshifter Please see this

@Planeshifter
Copy link
Member

Closing as this refactoring was meanwhile merged per #2080. Thanks either way for your contribution even though it didn't make it in this time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. 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]: refactor blas/ext/base/sdssum to follow current project conventions
3 participants