Skip to content

feat: add C implementation for blas/ext/base/ndarray/dnansumkbn - #14296

Open
Shravani-Relekar wants to merge 3 commits into
stdlib-js:developfrom
Shravani-Relekar:feat/dnansumkbn
Open

Shravani-Relekar wants to merge 3 commits into
stdlib-js:developfrom
Shravani-Relekar:feat/dnansumkbn

Conversation

@Shravani-Relekar

Copy link
Copy Markdown

Description

What is the purpose of this pull request?

This pull request:

  • feat: add C implementation for blas/ext/base/ndarray/dnansumkbn

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • No.

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.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".


@stdlib-js/reviewers

@Shravani-Relekar
Shravani-Relekar requested a review from a team August 15, 2026 14:59
@stdlib-bot

Copy link
Copy Markdown
Contributor

👋 Hi there! 👋

And thank you for opening your first pull request! We will review it shortly. 🏃 💨

Getting Started

Next Steps

  1. A project maintainer will approve GitHub Actions workflows for your PR.
  2. All CI checks must pass before your submission can be fully reviewed.
  3. You'll need to address any failures in linting or unit tests.

Running Tests Locally

You can use make to run any of the CI commands locally from the root directory of the stdlib repository:

# Run tests for all packages in the math namespace:
make test TESTS_FILTER=".*/@stdlib/math/.*"

# Run benchmarks for a specific package:
make benchmark BENCHMARKS_FILTER=".*/@stdlib/math/base/special/sin/.*"

If you haven't heard back from us within two weeks, please ping us by tagging the "reviewers" team in a comment on this PR.

If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members.

We appreciate your contribution!

Documentation Links

@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Needs Review A pull request which needs code review. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. labels Aug 15, 2026
@kgryte

kgryte commented Aug 23, 2026

Copy link
Copy Markdown
Member

@ujjwalv01 Mind taking a first review on this PR?

@kgryte kgryte added Feature Issue or pull request for adding a new feature. C Issue involves or relates to C. difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. labels Aug 23, 2026
Comment on lines +42 to +44
function vector(buffer, length, stride, offset) {
return new ndarray('float64', buffer, [length], [stride], offset, 'row-major');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
function vector(buffer, length, stride, offset) {
return new ndarray('float64', buffer, [length], [stride], offset, 'row-major');
}
function vector( buffer, length, stride, offset ) {
return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' );
}

Comment on lines +64 to +66
x = new Float64Array([1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0]);
v = dnansumkbn([vector(x, 7, 1, 0)]);
t.strictEqual(v, 3.0, 'returns expected value');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
x = new Float64Array([1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0]);
v = dnansumkbn([vector(x, 7, 1, 0)]);
t.strictEqual(v, 3.0, 'returns expected value');
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ] );
v = dnansumkbn( [ vector( x, 7, 1, 0 ) ] );
t.strictEqual( v, 3.0, 'returns expected value' );

@ujjwalv01 ujjwalv01 Aug 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Shravani-Relekar , According to the stdlib style guidelines, there needs to be a space inside the array brackets for function arguments, as shown in the suggested change above.

I noticed this formatting is used throughout this entire file. Once you apply this suggestion, could you please do a quick find-and-replace to fix all the other instances in test.main.js?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to test.main.js, there is a minor style guideline issue with the array spacing here (see suggested change above).

Could you please ensure this spacing fix is also applied to all similar instances throughout this test.native.js file? Thanks!

Comment on lines +143 to +154
// Create an ndarray:
const double data[] = { 1.0, 0.0/0.0, 3.0, 4.0 };
int64_t shape[] = { 4 };
int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };

struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );

// Compute the sum:
const struct ndarray *arrays[] = { x };
double v = stdlib_blas_ext_dnansumkbn( arrays );
// returns 8.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @kgryte , I noticed a small change in the examples across the languages.

The JS examples (lib/index.js, lib/main.js) use:

var x = new Float64Vector( [ 1.0, -2.0, NaN, 2.0 ] ); // returns 1.0

But the C examples (header docs and README) use different values:

const double data[] = { 1.0, 0.0/0.0, 3.0, 4.0 }; // returns 8.0

I noticed that the original dnansum package also uses different values for its JS vs C examples. Should we keep them different here to mirror what was done in dnansum, or should we update the C examples to match the JS ones ({ 1.0, -2.0, 0.0/0.0, 2.0 }) for consistency?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is fine if they differ slightly.

@ujjwalv01

ujjwalv01 commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

@ujjwalv01 Mind taking a first review on this PR?

Done! Left a few minor spacing suggestions and question about C examples.

@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

No coverage information available.

@kgryte

kgryte commented Aug 25, 2026

Copy link
Copy Markdown
Member

@Shravani-Relekar Mind addressing the lint failures? Looks like there are still spacing issues.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Aug 25, 2026

@ujjwalv01 ujjwalv01 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a heads-up on the CI failure there are a few file formatting issues that need to be fixed to get the tests passing:

  1. There are some spacing and indentation errors in benchmark.js.
  2. Both package.json and manifest.json are missing the required empty newline at the end of the file.

You'll need to fix those formatting issues so the CI can successfully pass;

This branch has not been deployed

No deployments
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. difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. Feature Issue or pull request for adding a new feature. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants