From dae90eb8cb9f719721ea56647a0e6678802591be Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 24 Sep 2024 15:37:59 +0500 Subject: [PATCH 1/6] feat: add C ndarray API and code refactor --- .../@stdlib/blas/ext/base/dapxsum/README.md | 140 ++++++++++++++++-- .../ext/base/dapxsum/benchmark/benchmark.js | 9 +- .../dapxsum/benchmark/benchmark.native.js | 9 +- .../dapxsum/benchmark/benchmark.ndarray.js | 9 +- .../benchmark/benchmark.ndarray.native.js | 9 +- .../dapxsum/benchmark/c/benchmark.length.c | 48 +++++- .../blas/ext/base/dapxsum/docs/repl.txt | 18 +-- .../ext/base/dapxsum/docs/types/index.d.ts | 18 +-- .../ext/base/dapxsum/examples/c/example.c | 8 +- .../blas/ext/base/dapxsum/examples/index.js | 7 +- .../include/stdlib/blas/ext/base/dapxsum.h | 10 +- .../blas/ext/base/dapxsum/lib/dapxsum.js | 11 +- .../ext/base/dapxsum/lib/dapxsum.native.js | 8 +- .../blas/ext/base/dapxsum/lib/index.js | 2 +- .../blas/ext/base/dapxsum/lib/ndarray.js | 10 +- .../ext/base/dapxsum/lib/ndarray.native.js | 17 +-- .../blas/ext/base/dapxsum/manifest.json | 15 +- .../blas/ext/base/dapxsum/package.json | 2 +- .../@stdlib/blas/ext/base/dapxsum/src/addon.c | 31 +++- .../blas/ext/base/dapxsum/src/dapxsum.c | 34 ----- .../@stdlib/blas/ext/base/dapxsum/src/main.c | 50 +++++++ 21 files changed, 336 insertions(+), 129 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md index 59e8e6805645..c62d619d4bde 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md @@ -20,7 +20,7 @@ limitations under the License. # dapxsum -> Add a constant to each double-precision floating-point strided array element and compute the sum. +> Add a scalar constant to each double-precision floating-point strided array element and compute the sum.
@@ -36,9 +36,9 @@ limitations under the License. var dapxsum = require( '@stdlib/blas/ext/base/dapxsum' ); ``` -#### dapxsum( N, alpha, x, stride ) +#### dapxsum( N, alpha, x, strideX ) -Adds a constant to each double-precision floating-point strided array element and computes the sum. +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -55,7 +55,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **alpha**: scalar constant. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: index increment for `x`. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`, @@ -82,9 +82,9 @@ var v = dapxsum( 4, 5.0, x1, 2 ); // returns 25.0 ``` -#### dapxsum.ndarray( N, alpha, x, stride, offset ) +#### dapxsum.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -98,9 +98,9 @@ var v = dapxsum.ndarray( N, 5.0, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access every other value in `x` starting from the second value ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -132,11 +132,12 @@ var v = dapxsum.ndarray( 4, 5.0, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dapxsum = require( '@stdlib/blas/ext/base/dapxsum' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +} ); console.log( x ); var v = dapxsum( x.length, 5.0, x, 1 ); @@ -147,6 +148,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dapxsum.h" +``` + +#### stdlib_strided_dapxsum( N, alpha, \*X, strideX ) + +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. + +```c +const double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +stdlib_strided_dapxsum( 4, 5.0, x, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] double` scalar constant. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. + +```c +double stdlib_strided_dapxsum( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dapxsum_ndarray( N, alpha, \*X, strideX, offsetX ) + +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. + +```c +double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +const stdlib_strided_dapxsum_ndarray( 4, 5.0, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] double` scalar constant. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dapxsum_ndarray( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dapxsum.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of indexed elements: + const int N = 8; + + // Specify a stride: + const int strideX = 1; + + // Compute the sum: + double v = stdlib_strided_dapxsum( N, 5.0, x, strideX ); + + // Print the result: + printf( "Sum: %lf\n", sum ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.js index 4ff710173b49..2518756169de 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -31,7 +30,9 @@ var dapxsum = require( './../lib/dapxsum.js' ); // VARIABLES // -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.native.js index 24d742e9bcf9..5298e7985a3f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -36,7 +35,9 @@ var dapxsum = tryRequire( resolve( __dirname, './../lib/dapxsum.native.js' ) ); var opts = { 'skip': ( dapxsum instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.js index cc83b2dc3a22..0b74e9783cc2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -31,7 +30,9 @@ var dapxsum = require( './../lib/ndarray.js' ); // VARIABLES // -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.native.js index a8f1618b4dd6..d2cf7744d04a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/benchmark.ndarray.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -36,7 +35,9 @@ var dapxsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dapxsum instanceof Error ) }; -var rand = uniform( -100.0, 100.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -100.0, 100.0 ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/c/benchmark.length.c index 5f02215916f3..561889f3969c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dapxsum_ndarray( len, 5.0, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/repl.txt index b4380e2e5a6c..ed688f09f39f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/repl.txt @@ -1,7 +1,7 @@ -{{alias}}( N, alpha, x, stride ) - Adds a constant to each double-precision floating-point strided array - element and computes the sum. +{{alias}}( N, alpha, x, strideX ) + Adds a scalar constant to each double-precision floating-point strided + array element and computes the sum. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. @@ -22,7 +22,7 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. Returns @@ -49,9 +49,9 @@ 14.0 -{{alias}}.ndarray( N, alpha, x, stride, offset ) - Adds a constant to each double-precision floating-point strided array - element and computes the sum using alternative indexing semantics. +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) + Adds a scalar constant to each double-precision floating-point strided + array element and computes the sum using alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a @@ -68,10 +68,10 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/types/index.d.ts index a268de79fb34..ce3d34fa05ec 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/docs/types/index.d.ts @@ -23,12 +23,12 @@ */ interface Routine { /** - * Adds a constant to each double-precision floating-point strided array element and computes the sum. + * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -39,16 +39,16 @@ interface Routine { * var v = dapxsum( x.length, 5.0, x, 1 ); * // returns 16.0 */ - ( N: number, alpha: number, x: Float64Array, stride: number ): number; + ( N: number, alpha: number, x: Float64Array, strideX: number ): number; /** - * Adds a constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. + * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. * * @param N - number of indexed elements * @param alpha - constant * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -59,16 +59,16 @@ interface Routine { * var v = dapxsum.ndarray( x.length, 5.0, x, 1, 0 ); * // returns 16.0 */ - ndarray( N: number, alpha: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, alpha: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param N - number of indexed elements * @param alpha - constant * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c index 3eef4c55b621..f76b18abe6dc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c @@ -24,14 +24,14 @@ int main( void ) { // Create a strided array: const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; - // Specify the number of elements: - const int64_t N = 4; + // Specify the number of indexed elements: + const int N = 4; // Specify the stride length: - const int64_t stride = 2; + const int stride = 2; // Compute the sum: - double v = stdlib_strided_dapxsum( N, 5.0, x, stride ); + double v = c_dapxsum( N, 5.0, x, stride ); // Print the result: printf( "sum: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/index.js index 139c53c4876a..1c76c3b37b2b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/index.js @@ -18,11 +18,12 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dapxsum = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = dapxsum( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/include/stdlib/blas/ext/base/dapxsum.h b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/include/stdlib/blas/ext/base/dapxsum.h index 9d2a11dd390a..e2af19246d39 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/include/stdlib/blas/ext/base/dapxsum.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/include/stdlib/blas/ext/base/dapxsum.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DAPXSUM_H #define STDLIB_BLAS_EXT_BASE_DAPXSUM_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,13 @@ extern "C" { /** * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. */ -double stdlib_strided_dapxsum( const int64_t N, const double alpha, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dapxsum)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX ); + +/** +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dapxsum_ndarray)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); + #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.js index e34884fc3090..cb025bb28168 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.js @@ -20,18 +20,19 @@ // MODULES // -var dapxsumkbn = require( '@stdlib/blas/ext/base/dapxsumkbn' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -43,8 +44,8 @@ var dapxsumkbn = require( '@stdlib/blas/ext/base/dapxsumkbn' ); * var v = dapxsum( N, 5.0, x, 1 ); * // returns 16.0 */ -function dapxsum( N, alpha, x, stride ) { - return dapxsumkbn( N, alpha, x, stride ); +function dapxsum( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.native.js index 72e8e3ba83b5..0e70605ac5ff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/dapxsum.native.js @@ -26,12 +26,12 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -43,8 +43,8 @@ var addon = require( './../src/addon.node' ); * var v = dapxsum( N, 5.0, x, 1 ); * // returns 16.0 */ -function dapxsum( N, alpha, x, stride ) { - return addon( N, alpha, x, stride ); +function dapxsum( N, alpha, x, strideX ) { + return addon( N, alpha, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/index.js index d1369a5758e2..2c94d95fc86b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Add a constant to each double-precision floating-point strided array element and compute the sum. +* Add a scalar constant to each double-precision floating-point strided array element and compute the sum. * * @module @stdlib/blas/ext/base/dapxsum * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.js index c9c326b9c398..9a210ae6fa34 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.js @@ -26,13 +26,13 @@ var dapxsumkbn = require( '@stdlib/blas/ext/base/dapxsumkbn' ).ndarray; // MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -43,8 +43,8 @@ var dapxsumkbn = require( '@stdlib/blas/ext/base/dapxsumkbn' ).ndarray; * var v = dapxsum( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dapxsum( N, alpha, x, stride, offset ) { - return dapxsumkbn( N, alpha, x, stride, offset ); +function dapxsum( N, alpha, x, strideX, offsetX ) { + return dapxsumkbn( N, alpha, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.native.js index c8fbbabe9dda..88f82eae0a3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/lib/ndarray.native.js @@ -20,21 +20,19 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dapxsum.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. * * @param {PositiveInteger} N - number of indexed elements * @param {number} alpha - constant * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -45,11 +43,8 @@ var addon = require( './dapxsum.native.js' ); * var v = dapxsum( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dapxsum( N, alpha, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - return addon( N, alpha, view, stride ); +function dapxsum( N, alpha, x, strideX, offsetX ) { + return addon.ndarray( N, alpha, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/manifest.json index 63b825bbc4b0..7ca19d1fef7a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/manifest.json @@ -28,7 +28,7 @@ { "task": "build", "src": [ - "./src/dapxsum.c" + "./src/main.c" ], "include": [ "./include" @@ -36,17 +36,20 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/blas/ext/base/dapxsumkbn" + "@stdlib/blas/ext/base/dapxsumkbn", + "@stdlib/napi/create-double" ] }, { "task": "benchmark", "src": [ - "./src/dapxsum.c" + "./src/main.c" ], "include": [ "./include" @@ -54,13 +57,15 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/blas/ext/base/dapxsumkbn" ] }, { "task": "examples", "src": [ - "./src/dapxsum.c" + "./src/main.c" ], "include": [ "./include" @@ -68,6 +73,8 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/blas/ext/base/dapxsumkbn" ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/package.json b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/package.json index 4c0d6460c557..a1faa86b00cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/dapxsum", "version": "0.0.0", - "description": "Add a constant to each double-precision floating-point strided array element and compute the sum.", + "description": "Add a scalar constant to each double-precision floating-point strided array element and compute the sum.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/addon.c index 29f347ea83f0..9a794fee86bb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/addon.c @@ -17,13 +17,14 @@ */ #include "stdlib/blas/ext/base/dapxsum.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 -#include /** * Receives JavaScript callback invocation data. @@ -36,14 +37,28 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dapxsum( N, alpha, X, stride ), &v ); - assert( status == napi_ok ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dapxsum)( N, alpha, X, strideX ), 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dapxsum_ndarray)( N, alpha, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c deleted file mode 100644 index e0f5df95b412..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/dapxsum.c +++ /dev/null @@ -1,34 +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/dapxsum.h" -#include "stdlib/blas/ext/base/dapxsumkbn.h" -#include - -/** -* Adds a constant to each double-precision floating-point strided array element and computes the sum. -* -* @param N number of indexed elements -* @param alpha constant -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dapxsum( const int64_t N, const double alpha, const double *X, const int64_t stride ) { - return stdlib_strided_dapxsumkbn( N, alpha, X, stride ); -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/main.c new file mode 100644 index 000000000000..99c6aeac4a93 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/src/main.c @@ -0,0 +1,50 @@ +/** +* @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/dapxsum.h" +#include "stdlib/blas/ext/base/dapxsumkbn.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dapxsum)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dapxsum_ndarray)( N, alpha, X, strideX, ox ); +} + +/** +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using alternative indexing semantics. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX index increment +* @param offsetX index offset +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dapxsum_ndarray)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return API_SUFFIX(stdlib_strided_dapxsumkbn_ndarray)( N, alpha, X, strideX, offsetX ); +} From eff87a81ec95dead52db6c045764cff16d282dbf Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 24 Sep 2024 15:41:55 +0500 Subject: [PATCH 2/6] docs: fix C function parameter name --- .../@stdlib/blas/ext/base/dapxsumkbn/src/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/main.c index b1de15c2e53b..ca6cd8c6cbc9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/src/main.c @@ -32,11 +32,11 @@ * * - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). * -* @param N number of indexed elements -* @param alpha constant -* @param X input array -* @param stride stride length -* @return output value +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX stride length +* @return output value */ double API_SUFFIX(stdlib_strided_dapxsumkbn)( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); From fa53e8eb0def2a17b199ffd67d8b9b087d5e6bf5 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 24 Sep 2024 15:48:12 +0500 Subject: [PATCH 3/6] fix: update C function call in example --- .../@stdlib/blas/ext/base/dapxsum/examples/c/example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c index f76b18abe6dc..bdb537989e13 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c @@ -31,7 +31,7 @@ int main( void ) { const int stride = 2; // Compute the sum: - double v = c_dapxsum( N, 5.0, x, stride ); + double v = stdlib_strided_dapxsum( N, 5.0, x, stride ); // Print the result: printf( "sum: %lf\n", v ); From bb78474d86ffd6d1d06d1761987aecce2e9e34b6 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 24 Sep 2024 18:18:11 -0700 Subject: [PATCH 4/6] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md index c62d619d4bde..ee866c495b92 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md @@ -182,6 +182,7 @@ Adds a scalar constant to each double-precision floating-point strided array ele const double x[] = { 1.0, 2.0, 3.0, 4.0 }; stdlib_strided_dapxsum( 4, 5.0, x, 1 ); +// returns 30.0 ``` The function accepts the following arguments: @@ -203,6 +204,7 @@ Adds a scalar constant to each double-precision floating-point strided array ele double x[] = { 1.0, 2.0, 3.0, 4.0 }; const stdlib_strided_dapxsum_ndarray( 4, 5.0, x, 1, 0 ); +// returns 30.0 ``` The function accepts the following arguments: From 526c7a92ea9bb056c7b29c7505b986d8e04e6c4f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 24 Sep 2024 18:19:01 -0700 Subject: [PATCH 5/6] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md index ee866c495b92..e99daa4d3164 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md @@ -181,7 +181,7 @@ Adds a scalar constant to each double-precision floating-point strided array ele ```c const double x[] = { 1.0, 2.0, 3.0, 4.0 }; -stdlib_strided_dapxsum( 4, 5.0, x, 1 ); +double v = stdlib_strided_dapxsum( 4, 5.0, x, 1 ); // returns 30.0 ``` @@ -203,7 +203,7 @@ Adds a scalar constant to each double-precision floating-point strided array ele ```c double x[] = { 1.0, 2.0, 3.0, 4.0 }; -const stdlib_strided_dapxsum_ndarray( 4, 5.0, x, 1, 0 ); +double v = stdlib_strided_dapxsum_ndarray( 4, 5.0, x, 1, 0 ); // returns 30.0 ``` From d48e023441a8581f0ed5af3d0a0f2254e412ac68 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 24 Sep 2024 18:22:52 -0700 Subject: [PATCH 6/6] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md index e99daa4d3164..d98bf9b1ba41 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsum/README.md @@ -193,7 +193,7 @@ The function accepts the following arguments: - **strideX**: `[in] CBLAS_INT` index increment for `X`. ```c -double stdlib_strided_dapxsum( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT strideX ); +double stdlib_strided_dapxsum( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX ); ``` #### stdlib_strided_dapxsum_ndarray( N, alpha, \*X, strideX, offsetX ) @@ -216,7 +216,7 @@ The function accepts the following arguments: - **offsetX**: `[in] CBLAS_INT` starting index for `X`. ```c -double stdlib_strided_dapxsum_ndarray( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +double stdlib_strided_dapxsum_ndarray( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); ```