From 3cb1cdd46d733e5e83126e4876307be0ac5983b7 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 28 Feb 2026 15:22:21 +0530 Subject: [PATCH 01/13] feat: add `stats/strided/distances/dminkowski` --- 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 --- --- .../strided/distances/dminkowski/README.md | 340 ++++++++++++++++++ .../dminkowski/benchmark/benchmark.js | 111 ++++++ .../dminkowski/benchmark/benchmark.native.js | 116 ++++++ .../dminkowski/benchmark/benchmark.ndarray.js | 111 ++++++ .../benchmark/benchmark.ndarray.native.js | 116 ++++++ .../distances/dminkowski/benchmark/c/Makefile | 146 ++++++++ .../dminkowski/benchmark/c/benchmark.length.c | 212 +++++++++++ .../strided/distances/dminkowski/binding.gyp | 265 ++++++++++++++ .../distances/dminkowski/docs/repl.txt | 116 ++++++ .../dminkowski/docs/types/index.d.ts | 106 ++++++ .../distances/dminkowski/docs/types/test.ts | 278 ++++++++++++++ .../distances/dminkowski/examples/c/Makefile | 146 ++++++++ .../distances/dminkowski/examples/c/example.c | 46 +++ .../distances/dminkowski/examples/index.js | 34 ++ .../strided/distances/dminkowski/include.gypi | 70 ++++ .../stats/strided/distances/dminkowski.h | 45 +++ .../distances/dminkowski/lib/dminkowski.js | 58 +++ .../dminkowski/lib/dminkowski.native.js | 55 +++ .../strided/distances/dminkowski/lib/index.js | 70 ++++ .../strided/distances/dminkowski/lib/main.js | 35 ++ .../distances/dminkowski/lib/native.js | 35 ++ .../distances/dminkowski/lib/ndarray.js | 92 +++++ .../dminkowski/lib/ndarray.native.js | 57 +++ .../distances/dminkowski/manifest.json | 119 ++++++ .../strided/distances/dminkowski/package.json | 73 ++++ .../strided/distances/dminkowski/src/Makefile | 70 ++++ .../strided/distances/dminkowski/src/addon.c | 69 ++++ .../strided/distances/dminkowski/src/main.c | 91 +++++ .../dminkowski/test/test.dminkowski.js | 283 +++++++++++++++ .../dminkowski/test/test.dminkowski.native.js | 292 +++++++++++++++ .../strided/distances/dminkowski/test/test.js | 82 +++++ .../distances/dminkowski/test/test.ndarray.js | 306 ++++++++++++++++ .../dminkowski/test/test.ndarray.native.js | 315 ++++++++++++++++ 33 files changed, 4360 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include/stdlib/stats/strided/distances/dminkowski.h create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md new file mode 100644 index 000000000000..727d4c94abd8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md @@ -0,0 +1,340 @@ + + +# dminkowski + +> Compute the Minkowski distance between two double-precision floating-point strided arrays. + +
+ +The [minkowski distance][wikipedia-minkowski-distance] is defined as + + + +```math +D(A,B) = \left( \sum_{i=0}^{N-1} \left| a_i - b_i \right|^p \right)^{\frac{1}{p}} +``` + + + +where `a_i` and `b_i` are the _ith_ components of vectors **A** and **B**, respectively. + +
+ + + +
+ +## Usage + +```javascript +var dminkowski = require( '@stdlib/stats/strided/distances/dminkowski' ); +``` + +#### dminkowski( N, P, x, strideX, y, strideY ) + +Computes the Minkowski distance between two double-precision floating-point strided arrays. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + +var z = dminkowski( x.length, 3, x, 1, y, 1 ); +// returns ~11.543 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **P**: order of the Minkowski norm. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length of `x`. +- **y**: input [`Float64Array`][@stdlib/array/float64]. +- **strideY**: stride length of `y`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the Minkowski distance between every other element in `x` and the first `N` elements of `y` in reverse order, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +var z = dminkowski( 3, 3, x, 2, y, -1 ); +// returns ~4.16 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +var z = dminkowski( 3, 3, x1, 1, y1, 1 ); +// returns ~11.538 +``` + +#### dminkowski.ndarray( N, P, x, strideX, offsetX, y, strideY, offsetY ) + +Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + +var z = dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ); +// returns ~11.543 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the Minkowski distance between every other element in `x` starting from the second element with the last 3 elements in `y` in reverse order + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +var z = dminkowski.ndarray( 3, 3, x, 2, 1, y, -1, y.length-1 ); +// returns ~11.206 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dminkowski = require( '@stdlib/stats/strided/distances/dminkowski' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 10, opts ); +console.log( y ); + +var out = dminkowski.ndarray( x.length, 3, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/distances/dminkowski.h" +``` + +#### stdlib_strided_dminkowski( N, P, \*X, strideX, \*Y, strideY ) + +Computes the Minkowski distance between two double-precision floating-point strided arrays. + +```c +const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 }; +const double y[] = { 2.0, 6.0, -1.0, -4.0, 8.0 }; + +double v = stdlib_strided_dminkowski( 5, 3, x, 1, y, 1 ); +// returns ~11.543 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **P**: `[in] double` order of the Minkowski norm. +- **X**: `[in] double*` first input array. +- **strideX**: `[in] CBLAS_INT` stride length of `X`. +- **Y**: `[in] double*` second input array. +- **strideY**: `[in] CBLAS_INT` stride length of `Y`. + +```c +double stdlib_strided_dminkowski( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); +``` + + + +#### stdlib_strided_dminkowski_ndarray( N, P, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + + + +Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. + +```c +const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 }; +const double y[] = { 2.0, 6.0, -1.0, -4.0, 8.0 }; + +double v = stdlib_strided_dminkowski_ndarray( 5, 3, x, -1, 4, y, -1, 4 ); +// returns ~11.543 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **P**: `[in] double` order of the Minkowski norm. +- **X**: `[in] double*` first input array. +- **strideX**: `[in] CBLAS_INT` stride length of `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[in] double*` second input array. +- **strideY**: `[in] CBLAS_INT` stride length of `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +double stdlib_strided_dminkowski_ndarray( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/distances/dminkowski.h" +#include + +int main( void ) { + // Create strided arrays: + const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + const double y[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of elements: + const int N = 8; + + // Specify strides: + const double P = 3.0; + const int strideX = 1; + const int strideY = -1; + + // Compute the Minkowski distance between `x` and `y`: + double d = stdlib_strided_dminkowski( N, P, x, strideX, y, strideY ); + + // Print the result: + printf( "Minkowski distance: %lf\n", d ); + + // Compute the Minkowski distance between `x` and `y` with offsets: + d = stdlib_strided_dminkowski_ndarray( N, P, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "Minkowski distance: %lf\n", d ); +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js new file mode 100644 index 000000000000..115053d58f52 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dminkowski = require( './../lib/dminkowski.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @param {number} p - power +* @returns {Function} benchmark function +*/ +function createBenchmark( len, p ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dminkowski( x.length, p, x, 1, y, 1 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + var j; + var p; + + min = 1; // 10^min + max = 6; // 10^max + p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + + for ( i = 0; i < p.length; i++ ) { + for ( j = min; j <= max; j++ ) { + len = pow( 10, i ); + f = createBenchmark( len, p[ i ] ); + bench( format( '%s:len=%d:p=%.2f', pkg, len, p[ i ] ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js new file mode 100644 index 000000000000..176c5ef49050 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dminkowski = tryRequire( resolve( __dirname, './../lib/dminkowski.native.js' ) ); +var opts = { + 'skip': ( dminkowski instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @param {number} p - power +* @returns {Function} benchmark function +*/ +function createBenchmark( len, p ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dminkowski( x.length, p, x, 1, y, 1 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + var j; + var p; + + min = 1; // 10^min + max = 6; // 10^max + p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + + for ( i = 0; i < p.length; i++ ) { + for ( j = min; j <= max; j++ ) { + len = pow( 10, i ); + f = createBenchmark( len, p[ i ] ); + bench( format( '%s::native:len=%d:p=%.2f', pkg, len, p[ i ] ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..51b6bf9c70e7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dminkowski = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @param {number} p - power +* @returns {Function} benchmark function +*/ +function createBenchmark( len, p ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dminkowski( x.length, p, x, 1, 0, y, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + var j; + var p; + + min = 1; // 10^min + max = 6; // 10^max + p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + + for ( i = 0; i < p.length; i++ ) { + for ( j = min; j <= max; j++ ) { + len = pow( 10, i ); + f = createBenchmark( len, p[ i ] ); + bench( format( '%s:ndarray:len=%d:p=%.2f', pkg, len, p[ i ] ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..6dd84c0c4184 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dminkowski = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dminkowski instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @param {number} p - power +* @returns {Function} benchmark function +*/ +function createBenchmark( len, p ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dminkowski( x.length, p, x, 1, 0, y, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + var j; + var p; + + min = 1; // 10^min + max = 6; // 10^max + p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + + for ( i = 0; i < p.length; i++ ) { + for ( j = min; j <= max; j++ ) { + len = pow( 10, i ); + f = createBenchmark( len, p[ i ] ); + bench( format( '%s::native:ndarray:len=%d:p=%.2f', pkg, len, p[ i ] ), opts, f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/Makefile new file mode 100644 index 000000000000..0756dc7da20a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..7fd807c7e79d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -0,0 +1,212 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/strided/distances/dminkowski.h" +#include +#include +#include +#include +#include + +#define NAME "dminkowski" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @param p power +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len, double p ) { + double elapsed; + double *x; + double *y; + double z; + double t; + int i; + + x = (double *) malloc( len * sizeof( double ) ); + y = (double *) malloc( len * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -10000.0, 10000.0 ); + y[ i ] = random_uniform( -10000.0, 10000.0 ); + } + z = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + z = stdlib_strided_dminkowski( len, p, x, 1, y, 1 ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @param p power +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len, double p ) { + double elapsed; + double *x; + double *y; + double z; + double t; + int i; + + x = (double *) malloc( len * sizeof( double ) ); + y = (double *) malloc( len * sizeof( double ) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -10000.0, 10000.0 ); + y[ i ] = random_uniform( -10000.0, 10000.0 ); + } + z = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + z = stdlib_strided_dminkowski_ndarray( len, p, x, 1, 0, y, 1, 0 ); + if ( z != z ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( z != z ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +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 < 5; 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 ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/binding.gyp b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/binding.gyp new file mode 100644 index 000000000000..60dce9d0b31a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/binding.gyp @@ -0,0 +1,265 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Fortran compiler (to override -Dfortran_compiler=): + 'fortran_compiler%': 'gfortran', + + # Fortran compiler flags: + 'fflags': [ + # Specify the Fortran standard to which a program is expected to conform: + '-std=f95', + + # Indicate that the layout is free-form source code: + '-ffree-form', + + # Aggressive optimization: + '-O3', + + # Enable commonly used warning options: + '-Wall', + + # Warn if source code contains problematic language features: + '-Wextra', + + # Warn if a procedure is called without an explicit interface: + '-Wimplicit-interface', + + # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): + '-fno-underscoring', + + # Warn if source code contains Fortran 95 extensions and C-language constructs: + '-pedantic', + + # Compile but do not link (output is an object file): + '-c', + ], + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + + # Define custom build actions for particular inputs: + 'rules': [ + { + # Define a rule for processing Fortran files: + 'extension': 'f', + + # Define the pathnames to be used as inputs when performing processing: + 'inputs': [ + # Full path of the current input: + '<(RULE_INPUT_PATH)' + ], + + # Define the outputs produced during processing: + 'outputs': [ + # Store an output object file in a directory for placing intermediate results (only accessible within a single target): + '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' + ], + + # Define the rule for compiling Fortran based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + + # Rule to compile Fortran on Windows: + { + 'rule_name': 'compile_fortran_windows', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', + + 'process_outputs_as_sources': 0, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + }, + + # Rule to compile Fortran on non-Windows: + { + 'rule_name': 'compile_fortran_linux', + 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', + + 'process_outputs_as_sources': 1, + + # Define the command-line invocation: + 'action': [ + '<(fortran_compiler)', + '<@(fflags)', + '-fPIC', # generate platform-independent code + '<@(_inputs)', + '-o', + '<@(_outputs)', + ], + } + ], # end condition (OS=="win") + ], # end conditions + }, # end rule (extension=="f") + ], # end rules + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt new file mode 100644 index 000000000000..dc760839f94f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt @@ -0,0 +1,116 @@ + +{{alias}}( N, P, x, strideX, y, strideY ) + Computes the Minkowski distance between two double-precision floating-point + strided arrays. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + P: number + Order of the Minkowski norm. + + x: Float64Array + First input array. + + strideX: integer + Stride length for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + out: number + Minkowski distance. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + > var out = {{alias}}( x.length, 3, x, 1, y, 1 ) + ~11.543 + + // Using N and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); + > out = {{alias}}( 3, 1, x, 1, y, -1 ) + 3.0 + + // Using view offsets: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x.buffer, x.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y.buffer, y.BYTES_PER_ELEMENT*3 ); + > out = {{alias}}( 3, 3, x1, 1, y1, 1 ) + ~11.538 + + +{{alias}}.ndarray( N, P, x, strideX, offsetX, y, strideY, offsetY ) + Computes the Minkowski distance between two double-precision floating-point + strided arrays using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + P: number + Order of the Minkowski norm. + + x: Float64Array + First input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + out: number + Minkowski distance. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + > var out = {{alias}}.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ) + ~11.543 + + // Using starting indices: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > out = {{alias}}.ndarray( 3, 2, x, 1, 1, y, 1, 3 ) + ~13.856 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts new file mode 100644 index 000000000000..eaf1be74d31c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts @@ -0,0 +1,106 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `dminkowski`. +*/ +interface Routine { + /** + * Computes the Minkowski distance between two double-precision floating-point strided arrays. + * + * @param N - number of indexed elements + * @param P - order of the Minkowski norm + * @param x - first input array + * @param strideX - `x` stride length + * @param y - second input array + * @param strideY - `y` stride length + * @returns Minkowski distance + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + * var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + * + * var z = dminkowski( x.length, 3, x, 1, y, 1 ); + * // returns ~11.543 + */ + ( N: number, P: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): number; + + /** + * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param P - order of the Minkowski norm + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns Minkowski distance + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + * var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + * + * var z = dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ); + * // returns ~11.543 + */ + ndarray( N: number, P: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number ): number; +} + +/** +* Computes the Minkowski distance between two double-precision floating-point strided arrays. +* +* @param N - number of indexed elements +* @param P - order of the Minkowski norm +* @param x - first input array +* @param strideX - `x` stride length +* @param y - second input array +* @param strideY - `y` stride length +* @returns Minkowski distance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +* var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); +* +* var z = dminkowski( x.length, 3, x, 1, y, 1 ); +* // returns ~11.543 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +* var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); +* +* var z = dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ); +* // returns ~11.543 +*/ +declare var dminkowski: Routine; + + +// EXPORTS // + +export = dminkowski; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts new file mode 100644 index 000000000000..597d369a9c6f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts @@ -0,0 +1,278 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import dminkowski = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( x.length, 3, x, 1, y, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( '10', 3, x, 1, y, 1 ); // $ExpectError + dminkowski( true, 3, x, 1, y, 1 ); // $ExpectError + dminkowski( false, 3, x, 1, y, 1 ); // $ExpectError + dminkowski( null, 3, x, 1, y, 1 ); // $ExpectError + dminkowski( undefined, 3, x, 1, y, 1 ); // $ExpectError + dminkowski( [], 3, x, 1, y, 1 ); // $ExpectError + dminkowski( {}, 3, x, 1, y, 1 ); // $ExpectError + dminkowski( ( x: number ): number => x, 3, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( x.length, '10', x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, true, x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, false, x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, null, x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, undefined, x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, [], x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, {}, x, 1, y, 1 ); // $ExpectError + dminkowski( x.length, ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( x.length, 3, '10', 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, true, 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, false, 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, null, 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, undefined, 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, [], 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, {}, 1, y, 1 ); // $ExpectError + dminkowski( x.length, 3, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( x.length, 3, x, '10', y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, true, y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, false, y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, null, y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, undefined, y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, [], y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, {}, y, 1 ); // $ExpectError + dminkowski( x.length, 3, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dminkowski( x.length, 3, x, 1, 10, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, '10', 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, true, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, false, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, null, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, undefined, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, [], 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, {}, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski( x.length, 3, x, 1, y, '10' ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, true ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, false ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, null ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, undefined ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, [] ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, {} ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski(); // $ExpectError + dminkowski( x.length ); // $ExpectError + dminkowski( x.length, 3 ); // $ExpectError + dminkowski( x.length, 3, x ); // $ExpectError + dminkowski( x.length, 3, x, 1 ); // $ExpectError + dminkowski( x.length, 3, x, 1, y, 3, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( '10', 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( true, 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( false, 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( null, 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( undefined, 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( [], 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( {}, 3, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( ( x: number ): number => x, 3, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, '10', x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, true, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, false, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, null, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, [], x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, {}, x, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, 10, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, '10', 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, true, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, false, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, null, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, undefined, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, [], 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, {}, 1, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, '10', 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, true, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, false, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, null, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, undefined, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, [], 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, {}, 0, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, 1, '10', y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, true, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, false, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, null, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, undefined, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, [], y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, {}, y, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, 1, 0, 10, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, '10', 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, true, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, false, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, null, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, undefined, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, [], 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, {}, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, 1, 0, y, '10', 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, true, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, false, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, null, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, undefined, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, [], 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, {}, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a eighth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, '10' ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, true ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, false ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, null ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, undefined ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, [] ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, {} ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + dminkowski.ndarray(); // $ExpectError + dminkowski.ndarray( x.length ); // $ExpectError + dminkowski.ndarray( x.length, 3 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1 ); // $ExpectError + dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c new file mode 100644 index 000000000000..310256b1b5ae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/strided/distances/dminkowski.h" +#include + +int main( void ) { + // Create strided arrays: + const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + const double y[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of elements: + const int N = 8; + + // Specify strides: + const double P = 3.0; + const int strideX = 1; + const int strideY = -1; + + // Compute the Minkowski distance between `x` and `y`: + double d = stdlib_strided_dminkowski( N, P, x, strideX, y, strideY ); + + // Print the result: + printf( "Minkowski distance: %lf\n", d ); + + // Compute the Minkowski distance between `x` and `y` with offsets: + d = stdlib_strided_dminkowski_ndarray( N, P, x, strideX, 0, y, strideY, N-1 ); + + // Print the result: + printf( "Minkowski distance: %lf\n", d ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/index.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/index.js new file mode 100644 index 000000000000..72f53d651e65 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dminkowski = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 10, opts ); +console.log( y ); + +var out = dminkowski.ndarray( x.length, 3, x, 1, 0, y, -1, y.length-1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include.gypi b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include.gypi new file mode 100644 index 000000000000..dcb556d250e8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include.gypi @@ -0,0 +1,70 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +# +# Variable nesting hacks: +# +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + 'variables': { + # Host BLAS library (to override -Dblas=): + 'blas%': '', + + # Path to BLAS library (to override -Dblas_dir=): + 'blas_dir%': '', + }, # end variables + + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '<@(blas_dir)', + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "minkowski", + "metric", + "strided", + "strided array", + "typed", + "array", + "float64", + "double", + "float64array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/Makefile b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c new file mode 100644 index 000000000000..972c224b5d70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/strided/distances/dminkowski.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/create_double.h" +#include + +/** +* 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, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, P, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski)( N, P, X, strideX, Y, strideY ), v ); + return v; +} + +/** +* 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_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, P, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 5 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, P, X, strideX, offsetX, Y, strideY, offsetY ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c new file mode 100644 index 000000000000..1c53e9586ed6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/strided/distances/dminkowski.h" +#include "stdlib/stats/strided/distances/deuclidean.h" +#include "stdlib/stats/strided/distances/dcityblock.h" +#include "stdlib/stats/strided/distances/dchebyshev.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/math/base/special/pow.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the Minkowski distance between two double-precision floating-point strided arrays. +* +* @param N number of indexed elements +* @param P order of the Minkowski norm +* @param X first array +* @param strideX X stride length +* @param Y second array +* @param strideY Y stride length +* @return Minkowski distance +*/ +double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + return API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, P, X, strideX, ox, Y, strideY, oy ); +} + +/** +* Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. +* +* @param N number of indexed elements +* @param P order of the Minkowski norm +* @param X first array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y second array +* @param strideY Y stride length +* @param offsetY starting index for Y +* @return Minkowski distance +*/ +double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + CBLAS_INT ox; + CBLAS_INT oy; + CBLAS_INT i; + double s; + double d; + + if ( N <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( P == 1 ) { + return stdlib_strided_dcityblock_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); + } + if ( P == 2 ) { + return stdlib_strided_deuclidean_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); + } + if ( P == 1 / 0.0 ) { // Infinity + return stdlib_strided_dchebyshev_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); + } + ox = offsetX; + oy = offsetY; + + s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); + d = stdlib_base_pow( s, P ); + ox += strideX; + oy += strideY; + for ( i = 1; i < N; i++ ) { + s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); + d += stdlib_base_pow( s, P ); + ox += strideX; + oy += strideY; + } + return stdlib_base_pow( d, 1/P ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js new file mode 100644 index 000000000000..7ce7e9421dbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js @@ -0,0 +1,283 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var dminkowski = require( './../lib/dminkowski.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dminkowski, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dminkowski.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the Minkowski distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 14.138089258179873, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 2.8844991406148166, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 48.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 6.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 18.76166303929372, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 3.4641016151377544, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 9.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 2.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + d = dminkowski( 0, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + + d = dminkowski( -4, 4, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 10.880243650829593, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 1, y, 2 ); + t.strictEqual( isAlmostSameValue( d, 6.009245006917366, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, -2, y, -1 ); + t.strictEqual( isAlmostSameValue( d, 5.999999999999999, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, y, -1 ); + t.strictEqual( isAlmostSameValue( d, 7.416859538532378, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var y0; + var x1; + var y1; + var d; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y0 = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x1, 2, y1, 1 ); + t.strictEqual( isAlmostSameValue( d, 8.810868114910337, 0 ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js new file mode 100644 index 000000000000..87fd693040e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js @@ -0,0 +1,292 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dminkowski = tryRequire( resolve( __dirname, './../lib/dminkowski.native.js' ) ); +var opts = { + 'skip': ( dminkowski instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dminkowski, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', opts, function test( t ) { + t.strictEqual( dminkowski.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the Minkowski distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 14.138089258179873, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 2.8844991406148166, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 48.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 6.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 18.76166303929372, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 3.4641016151377544, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 9.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 2.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + d = dminkowski( 0, 3, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + + d = dminkowski( -4, 4, x, 1, y, 1 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, y, 1 ); + t.strictEqual( isAlmostSameValue( d, 10.880243650829593, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 1, y, 2 ); + t.strictEqual( isAlmostSameValue( d, 6.009245006917366, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, -2, y, -1 ); + t.strictEqual( isAlmostSameValue( d, 5.999999999999999, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, y, -1 ); + t.strictEqual( isAlmostSameValue( d, 7.416859538532378, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var x0; + var y0; + var x1; + var y1; + var d; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y0 = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x1, 2, y1, 1 ); + t.strictEqual( isAlmostSameValue( d, 8.810868114910337, 0 ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.js new file mode 100644 index 000000000000..7b59ca061653 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dminkowski = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dminkowski, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dminkowski.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dminkowski = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dminkowski, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dminkowski; + var main; + + main = require( './../lib/dminkowski.js' ); + + dminkowski = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dminkowski, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js new file mode 100644 index 000000000000..c426d4062a80 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js @@ -0,0 +1,306 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var dminkowski = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dminkowski, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( dminkowski.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the Minkowski distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 14.138089258179873, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 2.8844991406148166, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 48.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 6.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 18.76166303929372, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 3.4641016151377544, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 9.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 2.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + d = dminkowski( 0, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + + d = dminkowski( -4, 4, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 10.880243650829593, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0, + 11.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 1, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 4.626065009182741, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 1, 0, y, 2, 0 ); + t.strictEqual( isAlmostSameValue( d, 6.009245006917366, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, 1, 3 ); + t.strictEqual( isAlmostSameValue( d, 10.23127654683995, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, -2, x.length-1, y, -1, 2 ); + t.strictEqual( isAlmostSameValue( d, 5.999999999999999, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, -1, y.length-2 ); + t.strictEqual( isAlmostSameValue( d, 8.640122597711688, 0 ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js new file mode 100644 index 000000000000..cf7e28709301 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js @@ -0,0 +1,315 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var dminkowski = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dminkowski instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dminkowski, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', opts, function test( t ) { + t.strictEqual( dminkowski.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the function calculates the Minkowski distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 14.138089258179873, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 2.8844991406148166, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 48.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 1, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 6.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 18.76166303929372, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, 2, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 3.4641016151377544, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 9.0, 0 ), true, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( x.length, Infinity, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 2.0, 0 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + d = dminkowski( 0, 3, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + + d = dminkowski( -4, 4, x, 1, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, NaN, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` stride', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 10.880243650829593, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `x` offset', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0, + 11.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 1, y, 1, 0 ); + t.strictEqual( isAlmostSameValue( d, 4.626065009182741, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` stride', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 1, 0, y, 2, 0 ); + t.strictEqual( isAlmostSameValue( d, 6.009245006917366, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `y` offset', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, 1, 3 ); + t.strictEqual( isAlmostSameValue( d, 10.23127654683995, 0 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, -2, x.length-1, y, -1, 2 ); + t.strictEqual( isAlmostSameValue( d, 5.999999999999999, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', opts, function test( t ) { + var d; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + + // Tested against SciPy's `spatial.distances.minkowski`: + d = dminkowski( 3, 3, x, 2, 0, y, -1, y.length-2 ); + t.strictEqual( isAlmostSameValue( d, 8.640122597711688, 0 ), true, 'returns expected value' ); + t.end(); +}); From 6695ab7cb4ca8b6ccf2fdba4b4807838a84b9db9 Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 28 Feb 2026 15:38:45 +0530 Subject: [PATCH 02/13] refactor: update parameter `P` to lowercase --- 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 --- --- .../strided/distances/dminkowski/README.md | 24 +++++++++---------- .../distances/dminkowski/docs/repl.txt | 8 +++---- .../dminkowski/docs/types/index.d.ts | 10 ++++---- .../distances/dminkowski/examples/c/example.c | 6 ++--- .../stats/strided/distances/dminkowski.h | 4 ++-- .../distances/dminkowski/lib/dminkowski.js | 6 ++--- .../dminkowski/lib/dminkowski.native.js | 6 ++--- .../distances/dminkowski/lib/ndarray.js | 16 ++++++------- .../dminkowski/lib/ndarray.native.js | 6 ++--- .../strided/distances/dminkowski/src/addon.c | 8 +++---- .../strided/distances/dminkowski/src/main.c | 22 ++++++++--------- .../dminkowski/test/test.dminkowski.js | 6 ++--- .../dminkowski/test/test.dminkowski.native.js | 6 ++--- .../distances/dminkowski/test/test.ndarray.js | 6 ++--- .../dminkowski/test/test.ndarray.native.js | 6 ++--- 15 files changed, 70 insertions(+), 70 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md index 727d4c94abd8..fbbc7793966f 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md @@ -48,7 +48,7 @@ where `a_i` and `b_i` are the _ith_ components of vectors **A** and **B**, respe var dminkowski = require( '@stdlib/stats/strided/distances/dminkowski' ); ``` -#### dminkowski( N, P, x, strideX, y, strideY ) +#### dminkowski( N, p, x, strideX, y, strideY ) Computes the Minkowski distance between two double-precision floating-point strided arrays. @@ -65,7 +65,7 @@ var z = dminkowski( x.length, 3, x, 1, y, 1 ); The function has the following parameters: - **N**: number of indexed elements. -- **P**: order of the Minkowski norm. +- **p**: order of the Minkowski norm. - **x**: input [`Float64Array`][@stdlib/array/float64]. - **strideX**: stride length of `x`. - **y**: input [`Float64Array`][@stdlib/array/float64]. @@ -102,7 +102,7 @@ var z = dminkowski( 3, 3, x1, 1, y1, 1 ); // returns ~11.538 ``` -#### dminkowski.ndarray( N, P, x, strideX, offsetX, y, strideY, offsetY ) +#### dminkowski.ndarray( N, p, x, strideX, offsetX, y, strideY, offsetY ) Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. @@ -200,7 +200,7 @@ console.log( out ); #include "stdlib/stats/strided/distances/dminkowski.h" ``` -#### stdlib_strided_dminkowski( N, P, \*X, strideX, \*Y, strideY ) +#### stdlib_strided_dminkowski( N, p, \*X, strideX, \*Y, strideY ) Computes the Minkowski distance between two double-precision floating-point strided arrays. @@ -215,19 +215,19 @@ double v = stdlib_strided_dminkowski( 5, 3, x, 1, y, 1 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **P**: `[in] double` order of the Minkowski norm. +- **p**: `[in] double` order of the Minkowski norm. - **X**: `[in] double*` first input array. - **strideX**: `[in] CBLAS_INT` stride length of `X`. - **Y**: `[in] double*` second input array. - **strideY**: `[in] CBLAS_INT` stride length of `Y`. ```c -double stdlib_strided_dminkowski( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); +double stdlib_strided_dminkowski( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); ``` -#### stdlib_strided_dminkowski_ndarray( N, P, \*X, strideX, offsetX, \*Y, strideY, offsetY ) +#### stdlib_strided_dminkowski_ndarray( N, p, \*X, strideX, offsetX, \*Y, strideY, offsetY ) @@ -244,7 +244,7 @@ double v = stdlib_strided_dminkowski_ndarray( 5, 3, x, -1, 4, y, -1, 4 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **P**: `[in] double` order of the Minkowski norm. +- **p**: `[in] double` order of the Minkowski norm. - **X**: `[in] double*` first input array. - **strideX**: `[in] CBLAS_INT` stride length of `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. @@ -253,7 +253,7 @@ The function accepts the following arguments: - **offsetY**: `[in] CBLAS_INT` starting index for `Y`. ```c -double stdlib_strided_dminkowski_ndarray( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +double stdlib_strided_dminkowski_ndarray( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); ``` @@ -287,18 +287,18 @@ int main( void ) { const int N = 8; // Specify strides: - const double P = 3.0; + const double p = 3.0; const int strideX = 1; const int strideY = -1; // Compute the Minkowski distance between `x` and `y`: - double d = stdlib_strided_dminkowski( N, P, x, strideX, y, strideY ); + double d = stdlib_strided_dminkowski( N, p, x, strideX, y, strideY ); // Print the result: printf( "Minkowski distance: %lf\n", d ); // Compute the Minkowski distance between `x` and `y` with offsets: - d = stdlib_strided_dminkowski_ndarray( N, P, x, strideX, 0, y, strideY, N-1 ); + d = stdlib_strided_dminkowski_ndarray( N, p, x, strideX, 0, y, strideY, N-1 ); // Print the result: printf( "Minkowski distance: %lf\n", d ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt index dc760839f94f..56d3ca5a2cdf 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, P, x, strideX, y, strideY ) +{{alias}}( N, p, x, strideX, y, strideY ) Computes the Minkowski distance between two double-precision floating-point strided arrays. @@ -16,7 +16,7 @@ N: integer Number of indexed elements. - P: number + p: number Order of the Minkowski norm. x: Float64Array @@ -59,7 +59,7 @@ ~11.538 -{{alias}}.ndarray( N, P, x, strideX, offsetX, y, strideY, offsetY ) +{{alias}}.ndarray( N, p, x, strideX, offsetX, y, strideY, offsetY ) Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. @@ -72,7 +72,7 @@ N: integer Number of indexed elements. - P: number + p: number Order of the Minkowski norm. x: Float64Array diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts index eaf1be74d31c..7a53ba5719b6 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/index.d.ts @@ -26,7 +26,7 @@ interface Routine { * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param N - number of indexed elements - * @param P - order of the Minkowski norm + * @param p - order of the Minkowski norm * @param x - first input array * @param strideX - `x` stride length * @param y - second input array @@ -42,13 +42,13 @@ interface Routine { * var z = dminkowski( x.length, 3, x, 1, y, 1 ); * // returns ~11.543 */ - ( N: number, P: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): number; + ( N: number, p: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): number; /** * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param N - number of indexed elements - * @param P - order of the Minkowski norm + * @param p - order of the Minkowski norm * @param x - first input array * @param strideX - `x` stride length * @param offsetX - starting index for `x` @@ -66,14 +66,14 @@ interface Routine { * var z = dminkowski.ndarray( x.length, 3, x, 1, 0, y, 1, 0 ); * // returns ~11.543 */ - ndarray( N: number, P: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number ): number; + ndarray( N: number, p: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number ): number; } /** * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param N - number of indexed elements -* @param P - order of the Minkowski norm +* @param p - order of the Minkowski norm * @param x - first input array * @param strideX - `x` stride length * @param y - second input array diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c index 310256b1b5ae..79a9f05dcbff 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c @@ -28,18 +28,18 @@ int main( void ) { const int N = 8; // Specify strides: - const double P = 3.0; + const double p = 3.0; const int strideX = 1; const int strideY = -1; // Compute the Minkowski distance between `x` and `y`: - double d = stdlib_strided_dminkowski( N, P, x, strideX, y, strideY ); + double d = stdlib_strided_dminkowski( N, p, x, strideX, y, strideY ); // Print the result: printf( "Minkowski distance: %lf\n", d ); // Compute the Minkowski distance between `x` and `y` with offsets: - d = stdlib_strided_dminkowski_ndarray( N, P, x, strideX, 0, y, strideY, N-1 ); + d = stdlib_strided_dminkowski_ndarray( N, p, x, strideX, 0, y, strideY, N-1 ); // Print the result: printf( "Minkowski distance: %lf\n", d ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include/stdlib/stats/strided/distances/dminkowski.h b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include/stdlib/stats/strided/distances/dminkowski.h index 3bec9622f592..d6ccc8460153 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include/stdlib/stats/strided/distances/dminkowski.h +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/include/stdlib/stats/strided/distances/dminkowski.h @@ -31,12 +31,12 @@ extern "C" { /** * Computes the Minkowski distance between two double-precision floating-point strided arrays. */ -double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); +double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ); /** * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. */ -double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js index ec23e5de0d8d..a64b865085a6 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js @@ -30,7 +30,7 @@ var ndarray = require( './ndarray.js' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} P - order of the Minkowski norm +* @param {PositiveInteger} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {Float64Array} y - second input array @@ -46,10 +46,10 @@ var ndarray = require( './ndarray.js' ); * var z = dminkowski( x.length, 3, x, 1, y, 1 ); * // returns ~11.543 */ -function dminkowski( N, P, x, strideX, y, strideY ) { +function dminkowski( N, p, x, strideX, y, strideY ) { var ox = stride2offset( N, strideX ); var oy = stride2offset( N, strideY ); - return ndarray( N, P, x, strideX, ox, y, strideY, oy ); + return ndarray( N, p, x, strideX, ox, y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js index 6f37b7822c31..75c52b9f5f61 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} P - order of the Minkowski norm +* @param {PositiveInteger} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {Float64Array} y - second input array @@ -45,8 +45,8 @@ var addon = require( './../src/addon.node' ); * var z = dminkowski( x.length, 3, x, 1, y, 1 ); * // returns ~11.543 */ -function dminkowski( N, P, x, strideX, y, strideY ) { - return addon( N, P, x, strideX, y, strideY ); +function dminkowski( N, p, x, strideX, y, strideY ) { + return addon( N, p, x, strideX, y, strideY ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js index fef65347bc4b..d066cda5fbe2 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js @@ -33,7 +33,7 @@ var dchebyshev = require( '@stdlib/stats/strided/distances/dchebyshev' ).ndarray * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} P - order of the Minkowski norm +* @param {PositiveInteger} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -51,7 +51,7 @@ var dchebyshev = require( '@stdlib/stats/strided/distances/dchebyshev' ).ndarray * var z = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); * // returns ~11.543 */ -function dminkowski( N, P, x, strideX, offsetX, y, strideY, offsetY ) { +function dminkowski( N, p, x, strideX, offsetX, y, strideY, offsetY ) { var ox; var oy; var i; @@ -61,29 +61,29 @@ function dminkowski( N, P, x, strideX, offsetX, y, strideY, offsetY ) { if ( N <= 0 ) { return NaN; } - if ( P === 1 ) { + if ( p === 1 ) { return dcityblock( N, x, strideX, offsetX, y, strideY, offsetY ); } - if ( P === 2 ) { + if ( p === 2 ) { return deuclidean( N, x, strideX, offsetX, y, strideY, offsetY ); } - if ( P === Infinity ) { + if ( p === Infinity ) { return dchebyshev( N, x, strideX, offsetX, y, strideY, offsetY ); } ox = offsetX; oy = offsetY; s = abs( x[ ox ] - y[ oy ] ); - d = pow( s, P ); + d = pow( s, p ); ox += strideX; oy += strideY; for ( i = 1; i < N; i++ ) { s = abs( x[ ox ] - y[ oy ] ); - d += pow( s, P ); + d += pow( s, p ); ox += strideX; oy += strideY; } - return pow( d, 1/P ); + return pow( d, 1/p ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js index b98935d5b0c2..af55c3e876a4 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} P - order of the Minkowski norm +* @param {PositiveInteger} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -47,8 +47,8 @@ var addon = require( './../src/addon.node' ); * var z = dminkowski( x.length, 3, x, 1, 0, y, 1, 0 ); * // returns ~11.543 */ -function dminkowski( N, P, x, strideX, offsetX, y, strideY, offsetY ) { - return addon.ndarray( N, P, x, strideX, offsetX, y, strideY, offsetY ); +function dminkowski( N, p, x, strideX, offsetX, y, strideY, offsetY ) { + return addon.ndarray( N, p, x, strideX, offsetX, y, strideY, offsetY ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c index 972c224b5d70..6f4625b025b9 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/addon.c @@ -36,12 +36,12 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 6 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, P, argv, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, p, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski)( N, P, X, strideX, Y, strideY ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski)( N, p, X, strideX, Y, strideY ), v ); return v; } @@ -55,14 +55,14 @@ static napi_value addon( napi_env env, napi_callback_info info ) { static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, P, argv, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, p, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 ); STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 5 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, P, X, strideX, offsetX, Y, strideY, offsetY ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, p, X, strideX, offsetX, Y, strideY, offsetY ), v ); return v; } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c index 1c53e9586ed6..3f87b0bea4c9 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c @@ -29,24 +29,24 @@ * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param N number of indexed elements -* @param P order of the Minkowski norm +* @param p order of the Minkowski norm * @param X first array * @param strideX X stride length * @param Y second array * @param strideY Y stride length * @return Minkowski distance */ -double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { +double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); - return API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, P, X, strideX, ox, Y, strideY, oy ); + return API_SUFFIX(stdlib_strided_dminkowski_ndarray)( N, p, X, strideX, ox, Y, strideY, oy ); } /** * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param N number of indexed elements -* @param P order of the Minkowski norm +* @param p order of the Minkowski norm * @param X first array * @param strideX X stride length * @param offsetX starting index for X @@ -55,7 +55,7 @@ double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double P, * @param offsetY starting index for Y * @return Minkowski distance */ -double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const double P, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { +double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const double p, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { CBLAS_INT ox; CBLAS_INT oy; CBLAS_INT i; @@ -65,27 +65,27 @@ double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const d if ( N <= 0 ) { return 0.0 / 0.0; // NaN } - if ( P == 1 ) { + if ( p == 1 ) { return stdlib_strided_dcityblock_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } - if ( P == 2 ) { + if ( p == 2 ) { return stdlib_strided_deuclidean_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } - if ( P == 1 / 0.0 ) { // Infinity + if ( p == 1 / 0.0 ) { // Infinity return stdlib_strided_dchebyshev_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } ox = offsetX; oy = offsetY; s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); - d = stdlib_base_pow( s, P ); + d = stdlib_base_pow( s, p ); ox += strideX; oy += strideY; for ( i = 1; i < N; i++ ) { s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); - d += stdlib_base_pow( s, P ); + d += stdlib_base_pow( s, p ); ox += strideX; oy += strideY; } - return stdlib_base_pow( d, 1/P ); + return stdlib_base_pow( d, 1/p ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js index 7ce7e9421dbe..0897f56e7884 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.js @@ -61,7 +61,7 @@ tape( 'the function calculates the Minkowski distance between two strided arrays t.end(); }); -tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { var d; var x; var y; @@ -83,7 +83,7 @@ tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cit t.end(); }); -tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { var d; var x; var y; @@ -105,7 +105,7 @@ tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euc t.end(); }); -tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { var d; var x; var y; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js index 87fd693040e5..dab4410490d5 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.dminkowski.native.js @@ -70,7 +70,7 @@ tape( 'the function calculates the Minkowski distance between two strided arrays t.end(); }); -tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { var d; var x; var y; @@ -92,7 +92,7 @@ tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cit t.end(); }); -tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { var d; var x; var y; @@ -114,7 +114,7 @@ tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euc t.end(); }); -tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { var d; var x; var y; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js index c426d4062a80..9ef17e43e9f7 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.js @@ -61,7 +61,7 @@ tape( 'the function calculates the Minkowski distance between two strided arrays t.end(); }); -tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', function test( t ) { var d; var x; var y; @@ -83,7 +83,7 @@ tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cit t.end(); }); -tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', function test( t ) { var d; var x; var y; @@ -105,7 +105,7 @@ tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euc t.end(); }); -tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { +tape( 'if provided a `p` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', function test( t ) { var d; var x; var y; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js index cf7e28709301..0d3e29bafc09 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/test/test.ndarray.native.js @@ -70,7 +70,7 @@ tape( 'the function calculates the Minkowski distance between two strided arrays t.end(); }); -tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `1`, the function calculates the Cityblock distance between two strided arrays', opts, function test( t ) { var d; var x; var y; @@ -92,7 +92,7 @@ tape( 'if provided a `P` parameter equal to `1`, the function calculates the Cit t.end(); }); -tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `2`, the function calculates the Euclidean distance between two strided arrays', opts, function test( t ) { var d; var x; var y; @@ -114,7 +114,7 @@ tape( 'if provided a `P` parameter equal to `2`, the function calculates the Euc t.end(); }); -tape( 'if provided a `P` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { +tape( 'if provided a `p` parameter equal to `Infinity`, the function calculates the Chebyshev distance between two strided arrays', opts, function test( t ) { var d; var x; var y; From 3d5e6464ec630fcf35bdeebc684a25712e80c412 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 02:44:20 -0800 Subject: [PATCH 03/13] bench: move declaration Signed-off-by: Athan --- .../distances/dminkowski/benchmark/c/benchmark.length.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 7fd807c7e79d..cc12d708bd12 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -174,20 +174,20 @@ static double benchmark2( int iterations, int len, double p ) { */ int main( void ) { double elapsed; - double *powers; int count; int iter; int len; int i; int j; int p; + + const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY }; // 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 ); From c3c6734270e1c471ad966e96202bfdb8168d8b8d Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 02:44:42 -0800 Subject: [PATCH 04/13] bench: fix loop limit Co-authored-by: Nakul Krishnakumar Signed-off-by: Athan --- .../strided/distances/dminkowski/benchmark/c/benchmark.length.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index cc12d708bd12..b0174afd6bf1 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -191,7 +191,7 @@ int main( void ) { for ( i = MIN; i <= MAX; i++ ) { len = pow( 10, i ); iter = ITERATIONS / pow( 10, i-1 ); - for ( p = 0; p < 5; p++ ) { + 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 ] ); From e60279aa16075233608c9710a67baae6852b0c1e Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Sat, 28 Feb 2026 17:11:39 +0530 Subject: [PATCH 05/13] fix: update according to code review Co-authored-by: Athan Signed-off-by: Nakul Krishnakumar --- .../dminkowski/benchmark/benchmark.js | 2 +- .../dminkowski/benchmark/benchmark.native.js | 2 +- .../dminkowski/benchmark/benchmark.ndarray.js | 2 +- .../benchmark/benchmark.ndarray.native.js | 2 +- .../dminkowski/benchmark/c/benchmark.length.c | 8 ++++---- .../distances/dminkowski/docs/types/test.ts | 2 +- .../distances/dminkowski/examples/c/example.c | 4 +++- .../distances/dminkowski/lib/dminkowski.js | 2 +- .../dminkowski/lib/dminkowski.native.js | 2 +- .../distances/dminkowski/lib/ndarray.js | 18 ++++++++---------- .../distances/dminkowski/lib/ndarray.native.js | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js index 115053d58f52..a668d526cb47 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js @@ -103,7 +103,7 @@ function main() { for ( j = min; j <= max; j++ ) { len = pow( 10, i ); f = createBenchmark( len, p[ i ] ); - bench( format( '%s:len=%d:p=%.2f', pkg, len, p[ i ] ), f ); + bench( format( '%s:len=%d,p=%.2f', pkg, len, p[ i ] ), f ); } } } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js index 176c5ef49050..c5fc6391f965 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js @@ -108,7 +108,7 @@ function main() { for ( j = min; j <= max; j++ ) { len = pow( 10, i ); f = createBenchmark( len, p[ i ] ); - bench( format( '%s::native:len=%d:p=%.2f', pkg, len, p[ i ] ), opts, f ); + bench( format( '%s::native:len=%d,p=%.2f', pkg, len, p[ i ] ), opts, f ); } } } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js index 51b6bf9c70e7..9379de1fa4f6 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js @@ -103,7 +103,7 @@ function main() { for ( j = min; j <= max; j++ ) { len = pow( 10, i ); f = createBenchmark( len, p[ i ] ); - bench( format( '%s:ndarray:len=%d:p=%.2f', pkg, len, p[ i ] ), f ); + bench( format( '%s:ndarray:len=%d,p=%.2f', pkg, len, p[ i ] ), f ); } } } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js index 6dd84c0c4184..fe978164bb00 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js @@ -108,7 +108,7 @@ function main() { for ( j = min; j <= max; j++ ) { len = pow( 10, i ); f = createBenchmark( len, p[ i ] ); - bench( format( '%s::native:ndarray:len=%d:p=%.2f', pkg, len, p[ i ] ), opts, f ); + bench( format( '%s::native:ndarray:len=%d,p=%.2f', pkg, len, p[ i ] ), opts, f ); } } } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index b0174afd6bf1..894d82ee3606 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double random_uniform( const double min, const double max ) { * * @param iterations number of iterations * @param len array length -* @param p power +* @param p power * @return elapsed time in seconds */ static double benchmark1( int iterations, int len, double p ) { @@ -134,7 +134,7 @@ static double benchmark1( int iterations, int len, double p ) { * * @param iterations number of iterations * @param len array length -* @param p power +* @param p power * @return elapsed time in seconds */ static double benchmark2( int iterations, int len, double p ) { @@ -194,14 +194,14 @@ int main( void ) { 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 ] ); + 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 ] ); + 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 ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts index 597d369a9c6f..5ae5876922a3 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/docs/types/test.ts @@ -246,7 +246,7 @@ import dminkowski = require( './index' ); dminkowski.ndarray( x.length, 3, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError } -// The compiler throws an error if the `ndarray` method is provided a eighth argument which is not a number... +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... { const x = new Float64Array( 10 ); const y = new Float64Array( 10 ); diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c index 79a9f05dcbff..4a18045130d8 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/examples/c/example.c @@ -27,8 +27,10 @@ int main( void ) { // Specify the number of elements: const int N = 8; - // Specify strides: + // Specify the order of the Minkowski norm: const double p = 3.0; + + // Specify strides: const int strideX = 1; const int strideY = -1; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js index a64b865085a6..870a14bc08b3 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.js @@ -30,7 +30,7 @@ var ndarray = require( './ndarray.js' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} p - order of the Minkowski norm +* @param {number} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {Float64Array} y - second input array diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js index 75c52b9f5f61..9257ed767644 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/dminkowski.native.js @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} p - order of the Minkowski norm +* @param {number} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {Float64Array} y - second input array diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js index d066cda5fbe2..5253d8fbf829 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.js @@ -25,6 +25,7 @@ var pow = require( '@stdlib/math/base/special/pow' ); var dcityblock = require( '@stdlib/stats/strided/distances/dcityblock' ).ndarray; var deuclidean = require( '@stdlib/stats/strided/distances/deuclidean' ).ndarray; var dchebyshev = require( '@stdlib/stats/strided/distances/dchebyshev' ).ndarray; +var PINF = require( '@stdlib/constants/float64/pinf' ); // MAIN // @@ -33,7 +34,7 @@ var dchebyshev = require( '@stdlib/stats/strided/distances/dchebyshev' ).ndarray * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} p - order of the Minkowski norm +* @param {number} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -61,29 +62,26 @@ function dminkowski( N, p, x, strideX, offsetX, y, strideY, offsetY ) { if ( N <= 0 ) { return NaN; } - if ( p === 1 ) { + if ( p === 1.0 ) { return dcityblock( N, x, strideX, offsetX, y, strideY, offsetY ); } - if ( p === 2 ) { + if ( p === 2.0 ) { return deuclidean( N, x, strideX, offsetX, y, strideY, offsetY ); } - if ( p === Infinity ) { + if ( p === PINF ) { return dchebyshev( N, x, strideX, offsetX, y, strideY, offsetY ); } ox = offsetX; oy = offsetY; - s = abs( x[ ox ] - y[ oy ] ); - d = pow( s, p ); - ox += strideX; - oy += strideY; - for ( i = 1; i < N; i++ ) { + d = 0.0; + for ( i = 0; i < N; i++ ) { s = abs( x[ ox ] - y[ oy ] ); d += pow( s, p ); ox += strideX; oy += strideY; } - return pow( d, 1/p ); + return pow( d, 1.0/p ); } diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js index af55c3e876a4..e5cb29cc4447 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/lib/ndarray.native.js @@ -29,7 +29,7 @@ var addon = require( './../src/addon.node' ); * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param {NonNegativeInteger} N - number of indexed elements -* @param {PositiveInteger} p - order of the Minkowski norm +* @param {number} p - order of the Minkowski norm * @param {Float64Array} x - first input array * @param {integer} strideX - stride length of `x` * @param {NonNegativeInteger} offsetX - starting index for `x` From c233c14e07cd85d939c46b2c8638b9720396f13b Mon Sep 17 00:00:00 2001 From: nakul-krishnakumar Date: Sat, 28 Feb 2026 17:21:58 +0530 Subject: [PATCH 06/13] fix: update according to code review --- 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 --- --- .../strided/distances/dminkowski/README.md | 4 +++- .../distances/dminkowski/manifest.json | 4 ++++ .../strided/distances/dminkowski/src/main.c | 20 +++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md index fbbc7793966f..e7c472a8d2c4 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/README.md @@ -286,8 +286,10 @@ int main( void ) { // Specify the number of elements: const int N = 8; - // Specify strides: + // Specify the order of the Minkowski norm: const double p = 3.0; + + // Specify strides: const int strideX = 1; const int strideY = -1; diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/manifest.json b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/manifest.json index 2e350b007319..0cd280d4eb24 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/manifest.json @@ -41,6 +41,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs", + "@stdlib/constants/float64/pinf", "@stdlib/stats/strided/distances/dcityblock", "@stdlib/stats/strided/distances/deuclidean", "@stdlib/stats/strided/distances/dchebyshev", @@ -67,6 +68,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs", + "@stdlib/constants/float64/pinf", "@stdlib/stats/strided/distances/dcityblock", "@stdlib/stats/strided/distances/deuclidean", "@stdlib/stats/strided/distances/dchebyshev", @@ -88,6 +90,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs", + "@stdlib/constants/float64/pinf", "@stdlib/stats/strided/distances/dcityblock", "@stdlib/stats/strided/distances/deuclidean", "@stdlib/stats/strided/distances/dchebyshev", @@ -109,6 +112,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/abs", + "@stdlib/constants/float64/pinf", "@stdlib/stats/strided/distances/dcityblock", "@stdlib/stats/strided/distances/deuclidean", "@stdlib/stats/strided/distances/dchebyshev", diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c index 3f87b0bea4c9..be25e511d415 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/src/main.c @@ -22,6 +22,7 @@ #include "stdlib/stats/strided/distances/dchebyshev.h" #include "stdlib/math/base/special/abs.h" #include "stdlib/math/base/special/pow.h" +#include "stdlib/constants/float64/pinf.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" @@ -29,7 +30,7 @@ * Computes the Minkowski distance between two double-precision floating-point strided arrays. * * @param N number of indexed elements -* @param p order of the Minkowski norm +* @param p order of the Minkowski norm * @param X first array * @param strideX X stride length * @param Y second array @@ -46,7 +47,7 @@ double API_SUFFIX(stdlib_strided_dminkowski)( const CBLAS_INT N, const double p, * Computes the Minkowski distance between two double-precision floating-point strided arrays using alternative indexing semantics. * * @param N number of indexed elements -* @param p order of the Minkowski norm +* @param p order of the Minkowski norm * @param X first array * @param strideX X stride length * @param offsetX starting index for X @@ -65,27 +66,24 @@ double API_SUFFIX(stdlib_strided_dminkowski_ndarray)( const CBLAS_INT N, const d if ( N <= 0 ) { return 0.0 / 0.0; // NaN } - if ( p == 1 ) { + if ( p == 1.0 ) { return stdlib_strided_dcityblock_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } - if ( p == 2 ) { + if ( p == 2.0 ) { return stdlib_strided_deuclidean_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } - if ( p == 1 / 0.0 ) { // Infinity + if ( p == STDLIB_CONSTANT_FLOAT64_PINF ) { return stdlib_strided_dchebyshev_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY ); } ox = offsetX; oy = offsetY; - s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); - d = stdlib_base_pow( s, p ); - ox += strideX; - oy += strideY; - for ( i = 1; i < N; i++ ) { + d = 0.0; + for ( i = 0; i < N; i++ ) { s = stdlib_base_abs( X[ ox ] - Y[ oy ] ); d += stdlib_base_pow( s, p ); ox += strideX; oy += strideY; } - return stdlib_base_pow( d, 1/p ); + return stdlib_base_pow( d, 1.0/p ); } From 13f393b4741c820f20861d45bc5210b5038aadac Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Sat, 28 Feb 2026 17:41:01 +0530 Subject: [PATCH 07/13] style: remove trailing whitespace Signed-off-by: Nakul Krishnakumar --- .../strided/distances/dminkowski/benchmark/c/benchmark.length.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 894d82ee3606..ab7d29d0142d 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -180,7 +180,6 @@ int main( void ) { int i; int j; int p; - const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY }; // Use the current time to seed the random number generator: From c856dbd34d64507b729f869baa112131eef3f45a Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 13:46:11 -0800 Subject: [PATCH 08/13] bench: reorder declarations Signed-off-by: Athan --- .../distances/dminkowski/benchmark/c/benchmark.length.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index ab7d29d0142d..8047b03d5b1c 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -181,6 +181,13 @@ int main( void ) { int j; int p; const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY }; + double elapsed; + 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 ) ); From 6faa84778f9d4b1157e27b19a0fd3d928b9368b9 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 13:46:47 -0800 Subject: [PATCH 09/13] bench: reorder declarations Signed-off-by: Athan --- .../distances/dminkowski/benchmark/c/benchmark.length.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 8047b03d5b1c..5009f3e56f97 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -188,6 +188,13 @@ int main( void ) { int i; int j; int p; + double elapsed; + 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 ) ); From cdf3a62cb2545624e1d2c6a5942ef2909c277e3e Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 13:47:14 -0800 Subject: [PATCH 10/13] bench: reorder declarations Signed-off-by: Athan --- .../distances/dminkowski/benchmark/c/benchmark.length.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 5009f3e56f97..be83863d712e 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -195,6 +195,13 @@ int main( void ) { int i; int j; int p; + double elapsed; + 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 ) ); From 1f924b3ad1876dd8a626f017ba32ba5d818d47c7 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 13:47:37 -0800 Subject: [PATCH 11/13] bench: reorder declarations Signed-off-by: Athan --- .../distances/dminkowski/benchmark/c/benchmark.length.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index be83863d712e..6964979f5116 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -202,6 +202,13 @@ int main( void ) { int i; int j; int p; + double elapsed; + 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 ) ); From 1f04cf29c68fa63147361cd5fcbcc2a458573d23 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 28 Feb 2026 13:48:21 -0800 Subject: [PATCH 12/13] bench: fix declarations Signed-off-by: Athan --- .../dminkowski/benchmark/c/benchmark.length.c | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 6964979f5116..91a88163896e 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -173,13 +173,6 @@ static double benchmark2( int iterations, int len, double p ) { * Main execution sequence. */ int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - int p; const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY }; double elapsed; int count; @@ -188,27 +181,6 @@ int main( void ) { int i; int j; int p; - double elapsed; - int count; - int iter; - int len; - int i; - int j; - int p; - double elapsed; - int count; - int iter; - int len; - int i; - int j; - int p; - double elapsed; - 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 ) ); From e28dc9fd4a1595c54ad752f2427c54086fb2d908 Mon Sep 17 00:00:00 2001 From: Nakul Krishnakumar Date: Sun, 1 Mar 2026 14:37:30 +0530 Subject: [PATCH 13/13] chore: update according to code review Co-authored-by: Athan Signed-off-by: Nakul Krishnakumar --- .../stats/strided/distances/dminkowski/benchmark/benchmark.js | 3 ++- .../strided/distances/dminkowski/benchmark/benchmark.native.js | 3 ++- .../distances/dminkowski/benchmark/benchmark.ndarray.js | 3 ++- .../distances/dminkowski/benchmark/benchmark.ndarray.native.js | 3 ++- .../distances/dminkowski/benchmark/c/benchmark.length.c | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js index a668d526cb47..a794056cee31 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.js @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); var pkg = require( './../package.json' ).name; var dminkowski = require( './../lib/dminkowski.js' ); @@ -97,7 +98,7 @@ function main() { min = 1; // 10^min max = 6; // 10^max - p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] ); for ( i = 0; i < p.length; i++ ) { for ( j = min; j <= max; j++ ) { diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js index c5fc6391f965..5ef987cb13f4 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.native.js @@ -28,6 +28,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); var pkg = require( './../package.json' ).name; @@ -102,7 +103,7 @@ function main() { min = 1; // 10^min max = 6; // 10^max - p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] ); for ( i = 0; i < p.length; i++ ) { for ( j = min; j <= max; j++ ) { diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js index 9379de1fa4f6..a20a3e4dd390 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.js @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); var pkg = require( './../package.json' ).name; var dminkowski = require( './../lib/ndarray.js' ); @@ -97,7 +98,7 @@ function main() { min = 1; // 10^min max = 6; // 10^max - p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] ); for ( i = 0; i < p.length; i++ ) { for ( j = min; j <= max; j++ ) { diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js index fe978164bb00..d719d07ed165 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/benchmark.ndarray.native.js @@ -28,6 +28,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); var pkg = require( './../package.json' ).name; @@ -102,7 +103,7 @@ function main() { min = 1; // 10^min max = 6; // 10^max - p = new Float64Array( [ 1.0, 2.0, 10.0, Infinity ] ); + p = new Float64Array( [ 1.0, 2.0, 10.0, PINF ] ); for ( i = 0; i < p.length; i++ ) { for ( j = min; j <= max; j++ ) { diff --git a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c index 91a88163896e..865c8578d0b7 100644 --- a/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/strided/distances/dminkowski/benchmark/c/benchmark.length.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/strided/distances/dminkowski.h" +#include "stdlib/constants/float64/pinf.h" #include #include #include @@ -173,7 +174,7 @@ static double benchmark2( int iterations, int len, double p ) { * Main execution sequence. */ int main( void ) { - const double powers[ 4 ] = { 1.0, 2.0, 10.0, INFINITY }; + const double powers[ 4 ] = { 1.0, 2.0, 10.0, STDLIB_CONSTANT_FLOAT64_PINF }; double elapsed; int count; int iter;