From 8022a59668f82ead6ab2201662b08cc4f4b4b2e4 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:56:31 +0530 Subject: [PATCH 01/13] bench(blas/ext/base/dcusumkbn): now uses current project conventions --- .../ext/base/dcusumkbn/benchmark/benchmark.js | 19 +++++++++---------- .../dcusumkbn/benchmark/benchmark.native.js | 15 +++++---------- .../dcusumkbn/benchmark/benchmark.ndarray.js | 19 +++++++++---------- .../benchmark/benchmark.ndarray.native.js | 15 +++++---------- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.js index dea4c2e6bc78..0329d65fb689 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.js @@ -21,7 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -29,6 +30,11 @@ var pkg = require( './../package.json' ).name; var dcusumkbn = require( './../lib/dcusumkbn.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,15 +45,8 @@ var dcusumkbn = require( './../lib/dcusumkbn.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var y; - var x; - var i; - - x = new Float64Array( len ); - y = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); + var y = new Float64Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.native.js index 8571b2ad4eb1..8322c189a258 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.native.js @@ -22,7 +22,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -32,6 +33,7 @@ var pkg = require( './../package.json' ).name; // VARIABLES // +var rand = uniform( -10.0, 10.0 ); var dcusumkbn = tryRequire( resolve( __dirname, './../lib/dcusumkbn.native.js' ) ); var opts = { 'skip': ( dcusumkbn instanceof Error ) @@ -48,15 +50,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float64Array( len ); - y = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); + var y = new Float64Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.js index 94a55043d036..e1b43d887d50 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.js @@ -21,7 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -29,6 +30,11 @@ var pkg = require( './../package.json' ).name; var dcusumkbn = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,15 +45,8 @@ var dcusumkbn = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float64Array( len ); - y = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); + var y = new Float64Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.native.js index 15cc2a46b34e..91e60b28cb52 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/benchmark/benchmark.ndarray.native.js @@ -22,7 +22,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -32,6 +33,7 @@ var pkg = require( './../package.json' ).name; // VARIABLES // +var rand = uniform( -10.0, 10.0 ); var dcusumkbn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dcusumkbn instanceof Error ) @@ -48,15 +50,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float64Array( len ); - y = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float64', rand ); + var y = new Float64Array( len ); return benchmark; function benchmark( b ) { From 140f134c6f7d1e2f95cbb69274ff01a3185118dc Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:59:20 +0530 Subject: [PATCH 02/13] docs(blas/ext/base/dcusumkbn): now uses current project conventions --- .../@stdlib/blas/ext/base/dcusumkbn/README.md | 33 +++++-------------- .../blas/ext/base/dcusumkbn/docs/repl.txt | 14 ++++---- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/README.md index 6d3466c456f1..338f4039dab5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/README.md @@ -65,18 +65,15 @@ The function has the following parameters: - **y**: output [`Float64Array`][@stdlib/array/float64]. - **strideY**: index increment for `y`. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in the strided input array, ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); var y = new Float64Array( x.length ); -var N = floor( x.length / 2 ); - -var v = dcusumkbn( N, 0.0, x, 2, y, 1 ); +var v = dcusumkbn( 4, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -86,7 +83,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); // Initial arrays... var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -96,9 +92,7 @@ var y0 = new Float64Array( x0.length ); 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 N = floor( x0.length / 2 ); - -dcusumkbn( N, 0.0, x1, -2, y1, 1 ); +dcusumkbn( 4, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -121,18 +115,15 @@ 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`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in the strided input array starting from the second value and to store in the last `N` elements of the strided output array starting from the last element ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var y = new Float64Array( x.length ); -var N = floor( x.length / 2 ); - -dcusumkbn.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); +dcusumkbn.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -157,20 +148,14 @@ dcusumkbn.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); var dcusumkbn = require( '@stdlib/blas/ext/base/dcusumkbn' ); -var y; -var x; -var i; +var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var y = new Float64Array( x.length ); -x = new Float64Array( 10 ); -y = new Float64Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/docs/repl.txt index eb76527042cf..2561887aeef4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in `x` and `y` are - accessed at runtime. + 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. @@ -47,8 +47,7 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float64}}( x.length ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, 0.0, x, 2, y, 2 ) + > {{alias}}( 3, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -56,12 +55,12 @@ > var y0 = new {{alias:@stdlib/array/float64}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, 0.0, x1, 2, y1, 1 ) + > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) [ -2.0, 0.0, -1.0 ] > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] + {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm and alternative indexing @@ -113,8 +112,7 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float64}}( x.length ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) + > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also From 0bba1b14842895e0b6b13665ed3fdf129ab57654 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:01:13 +0530 Subject: [PATCH 03/13] test(blas/ext/base/dcusumkbn): now uses current project conventions --- .../ext/base/dcusumkbn/test/test.dcusumkbn.js | 34 ++++++------------- .../dcusumkbn/test/test.dcusumkbn.native.js | 34 ++++++------------- .../ext/base/dcusumkbn/test/test.ndarray.js | 27 ++++----------- .../dcusumkbn/test/test.ndarray.native.js | 27 ++++----------- 4 files changed, 36 insertions(+), 86 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.js index d4e1a39f470e..97725aa2a12a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dcusumkbn = require( './../lib/dcusumkbn.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 6', function test( t ) { - t.strictEqual( dcusumkbn.length, 6, 'has expected arity' ); + t.strictEqual( dcusumkbn.length, 6, 'returns expected value' ); t.end(); }); @@ -164,7 +163,6 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -180,13 +178,12 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, y, 1 ); + dcusumkbn( 3, 0.0, x, 2, y, 1 ); expected = new Float64Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -194,7 +191,6 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -210,13 +206,12 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - dcusumkbn( N, 0.0, x, 1, y, 2 ); + dcusumkbn( 3, 0.0, x, 1, y, 2 ); expected = new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -224,7 +219,6 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 2 @@ -240,13 +234,12 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, -2, y, -1 ); + dcusumkbn( 3, 0.0, x, -2, y, -1 ); expected = new Float64Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -254,7 +247,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -272,13 +264,12 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, y, -1 ); + dcusumkbn( 3, 0.0, x, 2, y, -1 ); expected = new Float64Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -288,7 +279,6 @@ tape( 'the function supports view offsets', function test( t ) { var y0; var x1; var y1; - var N; // Initial arrays... x0 = new Float64Array([ @@ -312,11 +302,9 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = floor( x0.length / 2 ); - - dcusumkbn( N, 0.0, x1, -2, y1, 1 ); + dcusumkbn( 3, 0.0, x1, -2, y1, 1 ); expected = new Float64Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); - t.deepEqual( y0, expected, 'deep equal' ); + t.deepEqual( y0, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.native.js index 5fdf294a4558..5031dc3e8701 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.dcusumkbn.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 6', opts, function test( t ) { - t.strictEqual( dcusumkbn.length, 6, 'has expected arity' ); + t.strictEqual( dcusumkbn.length, 6, 'returns expected value' ); t.end(); }); @@ -173,7 +172,6 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -189,13 +187,12 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, y, 1 ); + dcusumkbn( 3, 0.0, x, 2, y, 1 ); expected = new Float64Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -203,7 +200,6 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -219,13 +215,12 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - dcusumkbn( N, 0.0, x, 1, y, 2 ); + dcusumkbn( 3, 0.0, x, 1, y, 2 ); expected = new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -233,7 +228,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 2 @@ -249,13 +243,12 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, -2, y, -1 ); + dcusumkbn( 3, 0.0, x, -2, y, -1 ); expected = new Float64Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -263,7 +256,6 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -281,13 +273,12 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, y, -1 ); + dcusumkbn( 3, 0.0, x, 2, y, -1 ); expected = new Float64Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); - t.deepEqual( y, expected, 'deep equal' ); + t.deepEqual( y, expected, 'returns expected value' ); t.end(); }); @@ -297,7 +288,6 @@ tape( 'the function supports view offsets', opts, function test( t ) { var y0; var x1; var y1; - var N; // Initial arrays... x0 = new Float64Array([ @@ -321,11 +311,9 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = floor( x0.length / 2 ); - - dcusumkbn( N, 0.0, x1, -2, y1, 1 ); + dcusumkbn( 3, 0.0, x1, -2, y1, 1 ); expected = new Float64Array( [ 0.0, 0.0, 0.0, 6.0, 10.0, 12.0 ] ); - t.deepEqual( y0, expected, 'deep equal' ); + t.deepEqual( y0, expected, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.js index 319e5d0b9168..baca8c017e5e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dcusumkbn = require( './../lib/ndarray.js' ); @@ -36,7 +35,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 8', function test( t ) { - t.strictEqual( dcusumkbn.length, 8, 'has expected arity' ); + t.strictEqual( dcusumkbn.length, 8, 'returns expected value' ); t.end(); }); @@ -164,7 +163,6 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -180,9 +178,8 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, 0, y, 1, 0 ); + dcusumkbn( 3, 0.0, x, 2, 0, y, 1, 0 ); expected = new Float64Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -194,7 +191,6 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -210,9 +206,8 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - dcusumkbn( N, 0.0, x, 1, 0, y, 2, 0 ); + dcusumkbn( 3, 0.0, x, 1, 0, y, 2, 0 ); expected = new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -224,7 +219,6 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 2 @@ -240,9 +234,8 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, -2, x.length-1, y, -1, 2 ); + dcusumkbn( 3, 0.0, x, -2, x.length-1, y, -1, 2 ); expected = new Float64Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -252,7 +245,6 @@ tape( 'the function supports negative strides', function test( t ) { tape( 'the function supports an `x` offset', function test( t ) { var expected; - var N; var x; var y; @@ -276,9 +268,8 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.0, 0.0 ]); - N = floor( x.length / 2 ); - dcusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); + dcusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float64Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -288,7 +279,6 @@ tape( 'the function supports an `x` offset', function test( t ) { tape( 'the function supports a `y` offset', function test( t ) { var expected; - var N; var x; var y; @@ -312,9 +302,8 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.0, 0.0 // 3 ]); - N = floor( x.length / 2 ); - dcusumkbn( N, 0.0, x, 1, 0, y, 2, 1 ); + dcusumkbn( 4, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float64Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); @@ -326,7 +315,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -344,9 +332,8 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, 0, y, -1, 2 ); + dcusumkbn( 3, 0.0, x, 2, 0, y, -1, 2 ); expected = new Float64Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.native.js index 5bf6bda9c5ac..d147cbe1412e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -45,7 +44,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 8', opts, function test( t ) { - t.strictEqual( dcusumkbn.length, 8, 'has expected arity' ); + t.strictEqual( dcusumkbn.length, 8, 'returns expected value' ); t.end(); }); @@ -173,7 +172,6 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -189,9 +187,8 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, 0, y, 1, 0 ); + dcusumkbn( 3, 0.0, x, 2, 0, y, 1, 0 ); expected = new Float64Array( [ 1.0, 4.0, 9.0, 0.0, 0.0 ] ); @@ -203,7 +200,6 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -219,9 +215,8 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - dcusumkbn( N, 0.0, x, 1, 0, y, 2, 0 ); + dcusumkbn( 3, 0.0, x, 1, 0, y, 2, 0 ); expected = new Float64Array( [ 1.0, 0.0, 3.0, 0.0, 6.0 ] ); @@ -233,7 +228,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 2 @@ -249,9 +243,8 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, -2, x.length-1, y, -1, 2 ); + dcusumkbn( 3, 0.0, x, -2, x.length-1, y, -1, 2 ); expected = new Float64Array( [ 9.0, 8.0, 5.0, 0.0, 0.0 ] ); @@ -261,7 +254,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { tape( 'the function supports an `x` offset', opts, function test( t ) { var expected; - var N; var x; var y; @@ -285,9 +277,8 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); - N = floor( x.length / 2 ); - dcusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); + dcusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 ); expected = new Float64Array( [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ); @@ -297,7 +288,6 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { tape( 'the function supports a `y` offset', opts, function test( t ) { var expected; - var N; var x; var y; @@ -321,9 +311,8 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); - N = floor( x.length / 2 ); - dcusumkbn( N, 0.0, x, 1, 0, y, 2, 1 ); + dcusumkbn( 4, 0.0, x, 1, 0, y, 2, 1 ); expected = new Float64Array( [ 0.0, 2.0, 0.0, 3.0, 0.0, 5.0, 0.0, 3.0 ] ); @@ -335,7 +324,6 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; - var N; x = new Float64Array([ 1.0, // 0 @@ -353,9 +341,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); - N = 3; - dcusumkbn( N, 0.0, x, 2, 0, y, -1, 2 ); + dcusumkbn( 3, 0.0, x, 2, 0, y, -1, 2 ); expected = new Float64Array( [ 9.0, 4.0, 1.0, 0.0, 0.0, 0.0 ] ); From 6db07b350fd56513ac2387805e4c8b696574eb97 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:04:02 +0530 Subject: [PATCH 04/13] refactor(blas/ext/base/dcusumkbn): JS implementation now uses current project conventions --- .../blas/ext/base/dcusumkbn/lib/dcusumkbn.js | 3 +-- .../base/dcusumkbn/lib/dcusumkbn.native.js | 3 +-- .../blas/ext/base/dcusumkbn/lib/index.js | 7 ++----- .../blas/ext/base/dcusumkbn/lib/ndarray.js | 4 +--- .../ext/base/dcusumkbn/lib/ndarray.native.js | 19 +++++++------------ 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.js index 10fea8f38844..a7787a9f836c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.js @@ -49,9 +49,8 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float64Array( x.length ); -* var N = x.length; * -* var v = dcusumkbn( N, 0.0, x, 1, y, 1 ); +* var v = dcusumkbn( 3, 0.0, x, 1, y, 1 ); * // returns [ 1.0, -1.0, 1.0 ] */ function dcusumkbn( N, sum, x, strideX, y, strideY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.native.js index 4508f017ce3f..ab130f9f5635 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/dcusumkbn.native.js @@ -41,9 +41,8 @@ var addon = require( './../src/addon.node' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float64Array( x.length ); -* var N = x.length; * -* var v = dcusumkbn( N, 0.0, x, 1, y, 1 ); +* var v = dcusumkbn( 3, 0.0, x, 1, y, 1 ); * // returns [ 1.0, -1.0, 1.0 ] */ function dcusumkbn( N, sum, x, strideX, y, strideY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/index.js index 91e7eef3917f..4ee16ef7075e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/index.js @@ -29,21 +29,18 @@ * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float64Array( x.length ); -* var N = x.length; * -* dcusumkbn( N, 0.0, x, 1, y, 1 ); +* dcusumkbn( 3, 0.0, x, 1, y, 1 ); * // y => [ 1.0, -1.0, 1.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dcusumkbn = require( '@stdlib/blas/ext/base/dcusumkbn' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float64Array( x.length ); -* var N = floor( x.length / 2 ); * -* dcusumkbn.ndarray( N, 0.0, x, 2, 1, y, 1, 0 ); +* dcusumkbn.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 ); * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.js index 45195f9fd6b2..e6d35987ad3d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.js @@ -48,13 +48,11 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float64Array( x.length ); -* var N = floor( x.length / 2 ); * -* var v = dcusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); +* var v = dcusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function dcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js index a28d0d44604b..87e0ea0aab46 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js @@ -20,7 +20,8 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); +var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var offsetView = require( '@stdlib/strided/base/offset-view' ); var addon = require( './dcusumkbn.native.js' ); @@ -41,26 +42,20 @@ var addon = require( './dcusumkbn.native.js' ); * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float64Array( x.length ); -* var N = floor( x.length / 2 ); * -* var v = dcusumkbn( N, 0.0, x, 2, 1, y, 1, 0 ); +* var v = dcusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function dcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { var viewX; var viewY; - if ( strideX < 0 ) { - offsetX += (N-1) * strideX; - } - if ( strideY < 0 ) { - offsetY += (N-1) * strideY; - } - viewX = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len - viewY = new Float64Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len + offsetX = minViewBufferIndex( N, strideX, offsetX ); + viewX = offsetView( x, offsetX ); + offsetY = minViewBufferIndex( N, strideY, offsetY ); + viewY = offsetView( y, offsetY ); addon( N, sum, viewX, strideX, viewY, strideY ); return y; } From eed7f598953f84d6f21ff4f5439764aaabf5b7a1 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:05:57 +0530 Subject: [PATCH 05/13] refactor(blas/ext/base/dcusumkbn): C implementation now uses current project conventions --- .../blas/ext/base/dcusumkbn/src/addon.c | 49 ++++++ .../blas/ext/base/dcusumkbn/src/addon.cpp | 164 ------------------ 2 files changed, 49 insertions(+), 164 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c new file mode 100644 index 000000000000..abb63e0137e4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c @@ -0,0 +1,49 @@ +/** + * @license Apache-2.0 + * + * Copyright (c) 2020 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/blas/ext/base/dcusumkbn.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/export.h" + +/** +* Receives JavaScript callback invocation data. +* +* @private +* @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_INT64( env, sum, 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 ); + + napi_value v; + napi_status status = napi_create_double( env, stdlib_strided_dcusumkbn( N, sum, X, strideX, Y, strideY ), &v ); + assert( status == napi_ok ); + return v; +} + + // Register a Node-API module: +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.cpp deleted file mode 100644 index 0f043f4c1be3..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/blas/ext/base/dcusumkbn.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dcusumkbn { - - /** - * Computes the cumulative sum of double-precision floating-point strided array elements using an improved Kahan–Babuška algorithm. - * - * ## Notes - * - * - When called from JavaScript, the function expects six arguments: - * - * - `N`: number of indexed elements - * - `sum`: initial sum - * - `X`: input array - * - `strideX`: `X` stride length - * - `Y`: output array - * - `strideY`: `Y` stride length - */ - napi_value node_dcusumkbn( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 6; - napi_value argv[ 6 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 6 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); - return nullptr; - } - - bool res2; - status = napi_is_typedarray( env, argv[ 2 ], &res2 ); - assert( status == napi_ok ); - if ( res2 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype3; - status = napi_typeof( env, argv[ 3 ], &vtype3 ); - assert( status == napi_ok ); - if ( vtype3 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); - return nullptr; - } - - bool res4; - status = napi_is_typedarray( env, argv[ 4 ], &res4 ); - assert( status == napi_ok ); - if ( res4 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype5; - status = napi_typeof( env, argv[ 5 ], &vtype5 ); - assert( status == napi_ok ); - if ( vtype5 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - double sum; - status = napi_get_value_double( env, argv[ 1 ], &sum ); - assert( status == napi_ok ); - - int64_t strideX; - status = napi_get_value_int64( env, argv[ 3 ], &strideX ); - assert( status == napi_ok ); - - int64_t strideY; - status = napi_get_value_int64( env, argv[ 5 ], &strideY ); - assert( status == napi_ok ); - - napi_typedarray_type vtype2; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype2 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_typedarray_type vtype4; - size_t ylen; - void *Y; - status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype4 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - stdlib_strided_dcusumkbn( N, sum, (double *)X, strideX, (double *)Y, strideY ); - - return nullptr; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dcusumkbn, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dcusumkbn From eec7feb5c0a0bcc8c00a40ad1f7074e47511cc3a Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:06:58 +0530 Subject: [PATCH 06/13] chore(blas/ext/base/dcusumkbn): manifest.json, package.json, include.gypi & examples now uses current project conventions --- .../blas/ext/base/dcusumkbn/examples/index.js | 14 +-- .../blas/ext/base/dcusumkbn/include.gypi | 2 +- .../blas/ext/base/dcusumkbn/manifest.json | 115 ++++++++++++------ .../blas/ext/base/dcusumkbn/package.json | 4 +- 4 files changed, 84 insertions(+), 51 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/examples/index.js index cc6d5f7f3203..b7094f8b7506 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/examples/index.js @@ -18,20 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); var dcusumkbn = require( './../lib' ); -var y; -var x; -var i; +var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var y = new Float64Array( x.length ); -x = new Float64Array( 10 ); -y = new Float64Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' Date: Tue, 26 Mar 2024 16:53:40 +0530 Subject: [PATCH 07/13] chore: apply suggestions from code review Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com> --- .../@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js | 3 ++- lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js index 87e0ea0aab46..969cf12c1562 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/ndarray.native.js @@ -53,8 +53,9 @@ function dcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) { var viewX; var viewY; offsetX = minViewBufferIndex( N, strideX, offsetX ); - viewX = offsetView( x, offsetX ); offsetY = minViewBufferIndex( N, strideY, offsetY ); + + viewX = offsetView( x, offsetX ); viewY = offsetView( y, offsetY ); addon( N, sum, viewX, strideX, viewY, strideY ); return y; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json index 59e7e560f033..393d8cb4194b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json @@ -74,4 +74,4 @@ "dependencies": [] } ] -} \ No newline at end of file +} From 04591d033f8fc18e46b3c94a8afec702d10b46a6 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:11:52 +0530 Subject: [PATCH 08/13] fix(blas/ext/base/dcusumkbn): `addon` now returns `NULL` --- .../@stdlib/blas/ext/base/dcusumkbn/src/addon.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c index abb63e0137e4..24c48c3681f6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c @@ -38,11 +38,8 @@ static napi_value addon( napi_env env, napi_callback_info info ) { 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 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dcusumkbn( N, sum, X, strideX, Y, strideY ), &v ); - assert( status == napi_ok ); - return v; + stdlib_strided_dcusumkbn( N, sum, X, strideX, Y, strideY ); + return NULL; } // Register a Node-API module: From e7cdd3bc89df5e66d3abd8bc556b26d80a3f6a4c Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:14:32 +0530 Subject: [PATCH 09/13] fix(blas/ext/base/dcusumkbn): removed `dcusumkbn` from dependencies --- lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json index 393d8cb4194b..68f3b5c16041 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json @@ -38,7 +38,6 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dcusumkbn", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", From e78f756bb0d864b0ebe1763f7dda99aad037f461 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:23:34 +0530 Subject: [PATCH 10/13] chore(blas/ext/base/dcusumkbn): fixed failing ci due to license indentation --- .../blas/ext/base/dcusumkbn/src/addon.c | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c index 24c48c3681f6..1314817d0672 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c @@ -1,20 +1,20 @@ /** - * @license Apache-2.0 - * - * Copyright (c) 2020 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. - */ +* @license Apache-2.0 +* +* Copyright (c) 2020 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/blas/ext/base/dcusumkbn.h" #include "stdlib/napi/argv.h" From 3250b646043967e17046747c7d45eba5ff298d12 Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Wed, 27 Mar 2024 02:04:59 +0530 Subject: [PATCH 11/13] fix(blas/ext/base/dcusumkbn): change `sum` from `int64` to `double` --- lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json | 1 + lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json index 68f3b5c16041..8130fb55f9b5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json @@ -40,6 +40,7 @@ "dependencies": [ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv_double", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/export" ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c index 1314817d0672..c9a53a00debf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/src/addon.c @@ -19,6 +19,7 @@ #include "stdlib/blas/ext/base/dcusumkbn.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/export.h" @@ -33,7 +34,7 @@ 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_INT64( env, sum, argv, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sum, 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 ); From 5d127255dc0a1bd44f5d7330fd490a5a3dcab56f Mon Sep 17 00:00:00 2001 From: Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Date: Wed, 27 Mar 2024 02:24:25 +0530 Subject: [PATCH 12/13] chore(blas/ext/base/dcusumkbn): removed missing `argv_double` dependency from `manifest.json` --- lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json index 8130fb55f9b5..68f3b5c16041 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json @@ -40,7 +40,6 @@ "dependencies": [ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv_double", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/export" ] From b72d369c2402044cc34cc7cb3613cce3473ba941 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 26 Mar 2024 15:50:41 -0700 Subject: [PATCH 13/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json index 68f3b5c16041..4aeff52b32f7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/manifest.json @@ -40,6 +40,7 @@ "dependencies": [ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/export" ]