Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@anandkaranubc
Copy link
Contributor

Resolves None.

Description

What is the purpose of this pull request?

This pull request:

  • Adds the implementation of dsortnans which partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • Resolves None.

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

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@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. labels Dec 30, 2025
* - The algorithm is not stable, meaning that the relative order of non-NaN elements is not guaranteed to be preserved.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {number} order - NaN placement order
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
* @param {number} order - NaN placement order
* @param {number} order - NaN placement order

Is the naming convention acceptable here?

@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 30, 2025

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/dsortnans $\color{green}418/418$
$\color{green}+0.00%$
$\color{green}31/31$
$\color{green}+0.00%$
$\color{green}4/4$
$\color{green}+0.00%$
$\color{green}418/418$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

*
* ## Notes
*
* - The algorithm is not stable, meaning that the relative order of non-NaN elements is not guaranteed to be preserved.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
* - The algorithm is not stable, meaning that the relative order of non-NaN elements is not guaranteed to be preserved.
* - The algorithm is not stable, meaning that the relative order of non-NaN elements is not guaranteed to be preserved.

If we are using this for dquicksort, the "instability" doesn't cause an issue. We can also add something like dsortnans2 (if needed) later which would preserve the relative order of non-NaN elements.


If `N <= 0` or `order == 0`, the function returns `x` unchanged.

A positive order places `NaN` values at the end of the array, while a
Copy link
Contributor Author

@anandkaranubc anandkaranubc Dec 30, 2025

Choose a reason for hiding this comment

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

In this whole PR, I changed the wording from “increasing order” to “positive order.” The main reason is that we are not actually performing a sort here, and “increasing” or “decreasing” implies that some kind of sorting is taking place.

Same applies for “decreasing order” to “negative order”.

## Notes

- If `N <= 0` or `order == 0.0`, both functions return `x` unchanged.
- A positive order places `NaN` values at the end of the array, while a negative order places `NaN` values at the beginning.
Copy link
Contributor Author

@anandkaranubc anandkaranubc Dec 30, 2025

Choose a reason for hiding this comment

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

Any explicit need to mention that (the point regarding positive/negative order)?

Comment on lines +28 to +36
x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.3 ) {
x[ i ] = NaN;
} else {
x[ i ] = (randu()*20.0) - 10.0;
}
}
console.log( x );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this kind of array generation and population okay? I wanted to inject NaNs into the array, and I couldn’t find a better way to do it.

@anandkaranubc
Copy link
Contributor Author

I have not yet added the C/JS benchmarks because I need some suggestions here. Since no actual “sorting” is being done, I was thinking that we would only need benchmark.js, benchmark.native.js, benchmark.ndarray.js, and benchmark.ndarray.native.js. If this is correct, what would their structure and benchmarking code look like? Could you please share a sample code snippet? Also, how should the isnan checks be handled or adapted in this context?

cc: @kgryte

@anandkaranubc anandkaranubc added JavaScript Issue involves or relates to JavaScript. C Issue involves or relates to C. Feature Issue or pull request for adding a new feature. labels Dec 30, 2025
@anandkaranubc anandkaranubc requested a review from kgryte December 30, 2025 19:54
// MAIN //

/**
* Partitions a double-precision floating-point strided array by moving all NaNs either to the beginning or the end of the array.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function description ok?

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. Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants