Skip to content

feat: add stats/strided/distances/dminkowski#10567

Open
nakul-krishnakumar wants to merge 12 commits intostdlib-js:developfrom
nakul-krishnakumar:dist-minkowski
Open

feat: add stats/strided/distances/dminkowski#10567
nakul-krishnakumar wants to merge 12 commits intostdlib-js:developfrom
nakul-krishnakumar:dist-minkowski

Conversation

@nakul-krishnakumar
Copy link
Member

Resolves None.

Description

What is the purpose of this pull request?

This pull request:

  • Adds stats/strided/distances/dminkowski.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • 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.".

None.


@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: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - task: lint_c_examples
    status: missing_dependencies
  - task: lint_c_benchmarks
    status: missing_dependencies
  - 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
---
---
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: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - 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: missing_dependencies
  - task: lint_c_examples
    status: missing_dependencies
  - 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 Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Feb 28, 2026
@nakul-krishnakumar
Copy link
Member Author

nakul-krishnakumar commented Feb 28, 2026

Please note that the c benchmarks takes longer than other stats/strided/distances implementations as here we benchmark for 4 different values of parameter p.

@kgryte kgryte added Feature Issue or pull request for adding a new feature. difficulty: 3 Likely to be challenging but manageable. review: 5 labels Feb 28, 2026
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 28, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/strided/distances/dminkowski $\color{green}400/400$
$\color{green}+100.00%$
$\color{green}23/23$
$\color{green}+100.00%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{green}400/400$
$\color{green}+100.00%$

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

@kgryte
Copy link
Member

kgryte commented Feb 28, 2026

@nakul-krishnakumar Mind resolving the C lint errors?

@nakul-krishnakumar
Copy link
Member Author

@nakul-krishnakumar Mind resolving the C lint errors?

How do you want me to fix the error? Currently it raises error because of the powers array implementation done in the benchmark.length.c

int main( void ) {
	double elapsed;
	double *powers;
	int count;
	int iter;
	int len;
	int i;
	int j;
	int p;

	// Use the current time to seed the random number generator:
	srand( time( NULL ) );

	print_version();
	count = 0;
	powers = (double[]) { 1.0, 2.0, 10.0, INFINITY };
	for ( i = MIN; i <= MAX; i++ ) {
		len = pow( 10, i );
		iter = ITERATIONS / pow( 10, i-1 );
		for ( p = 0; p < 4; p++ ) {
			for ( j = 0; j < REPEATS; j++ ) {
				count += 1;
				printf( "# c::%s:len=%d:p=%.2f\n", NAME, len, powers[ p ] );
				elapsed = benchmark1( iter, len, powers[ p ] );
				print_results( iter, elapsed );
				printf( "ok %d benchmark finished\n", count );
			}
			for ( j = 0; j < REPEATS; j++ ) {
				count += 1;
				printf( "# c::%s:ndarray:len=%d:p=%.2f\n", NAME, len, powers[ p ] );
				elapsed = benchmark2( iter, len, powers[ p ] );
				print_results( iter, elapsed );
				printf( "ok %d benchmark finished\n", count );
			}
		}
	}
	print_summary( count, count );
}

Can I instead do static const double powers[4] = { 1.0, 2.0, 10.0, INFINITY }; ? @kgryte

kgryte and others added 2 commits February 28, 2026 02:44
Signed-off-by: Athan <kgryte@gmail.com>
Co-authored-by: Nakul Krishnakumar <nakulkrishnakumar86@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
s = abs( x[ ox ] - y[ oy ] );
d = pow( s, p );
ox += strideX;
oy += strideY;
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of unrolling the first element? Could you not just initialize d = 0.0 and then have the loop go from i = 0 to i < N? Seems like this is currently just wasting additional characters without a strong motivation.

Copy link
Member Author

Choose a reason for hiding this comment

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

What is the point of unrolling the first element? Could you not just initialize d = 0.0 and then have the loop go from i = 0 to i < N? Seems like this is currently just wasting additional characters without a strong motivation.

I was just trying to mimic the implementation of dchebyshev where it is useful as it takes the max of residuals, but here as you said it does look redundant. Thank you for pointing that out. We will have to do the same refactoring for stats/strided/distances/dcityblock too then.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. review: 3 and removed Needs Review A pull request which needs code review. review: 5 labels Feb 28, 2026
nakul-krishnakumar and others added 2 commits February 28, 2026 17:11
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Nakul Krishnakumar <nakulkrishnakumar86@gmail.com>
---
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: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - task: lint_c_examples
    status: na
  - 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: na
  - task: lint_license_headers
    status: passed
---
Signed-off-by: Nakul Krishnakumar <nakulkrishnakumar86@gmail.com>
@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label Feb 28, 2026
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>

min = 1; // 10^min
max = 6; // 10^max
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
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
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] );

Use the stdlib constant.


min = 1; // 10^min
max = 6; // 10^max
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
Copy link
Member

Choose a reason for hiding this comment

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

Use the stdlib constant.

Suggested change
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] );


min = 1; // 10^min
max = 6; // 10^max
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
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
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] );


min = 1; // 10^min
max = 6; // 10^max
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
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
p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] );
p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] );

* Main execution sequence.
*/
int main( void ) {
const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY };
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 really want to be pedantic, you can also use the stdlib constant here, as well.

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.

Other than the use of PINF, this PR is looking good.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. review: 3 Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants