diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/README.md index 83c8bbb5f931..13dbbaae5665 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/README.md @@ -20,7 +20,7 @@ limitations under the License. # dapxsumkbn2 -> Add a constant to each double-precision floating-point strided array element and compute the sum using a second-order iterative Kahan–Babuška algorithm. +> Add a scalar constant to each double-precision floating-point strided array element and compute the sum using a second-order iterative Kahan–Babuška algorithm.
@@ -36,9 +36,9 @@ limitations under the License. var dapxsumkbn2 = require( '@stdlib/blas/ext/base/dapxsumkbn2' ); ``` -#### dapxsumkbn2( N, alpha, x, stride ) +#### dapxsumkbn2( N, alpha, x, strideX ) -Adds a constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -53,7 +53,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **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`, @@ -80,9 +80,9 @@ var v = dapxsumkbn2( 4, 5.0, x1, 2 ); // returns 25.0 ``` -#### dapxsumkbn2.ndarray( N, alpha, x, stride, offset ) +#### dapxsumkbn2.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -95,9 +95,9 @@ var v = dapxsumkbn2.ndarray( 3, 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' ); @@ -129,11 +129,12 @@ var v = dapxsumkbn2.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 dapxsumkbn2 = require( '@stdlib/blas/ext/base/dapxsumkbn2' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = dapxsumkbn2( x.length, 5.0, x, 1 ); @@ -144,8 +145,125 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dapxsumkbn2.h" +``` + +#### stdlib_strided_dapxsumkbn2( N, alpha, \*X, strideX ) + +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. + +```c +const double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +double v = stdlib_strided_dapxsumkbn2( 4, 5.0, x, 1 ); +// returns 30.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`. + +```c +double stdlib_strided_dapxsumkbn2( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dapxsumkbn2_ndarray( N, alpha, \*X, strideX, offsetX ) + +Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 3.0, 4.0 }; + +double v = stdlib_strided_dapxsumkbn2_ndarray( 4, 5.0, x, 1, 0 ); +// returns 30.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_dapxsumkbn2_ndarray( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dapxsumkbn2.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_dapxsumkbn2( N, 5.0, x, strideX ); + + // Print the result: + printf( "Sum: %lf\n", sum ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.js index 1e691c643a1f..ef95a8074271 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 dapxsumkbn2 = require( './../lib/dapxsumkbn2.js' ); // VARIABLES // -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.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/dapxsumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.native.js index bb2878baa55d..81281155b883 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 dapxsumkbn2 = tryRequire( resolve( __dirname, './../lib/dapxsumkbn2.native.j var opts = { 'skip': ( dapxsumkbn2 instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -10.0, 10.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/dapxsumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.ndarray.js index 2d7f24c90101..0589b207f0af 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 dapxsumkbn2 = require( './../lib/ndarray.js' ); // VARIABLES // -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.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/dapxsumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.ndarray.native.js index 2c9993a3e386..0a6096ca904d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 dapxsumkbn2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( dapxsumkbn2 instanceof Error ) }; -var rand = uniform( -10.0, 10.0 ); +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -49,7 +50,7 @@ var rand = uniform( -10.0, 10.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/dapxsumkbn2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/c/benchmark.length.c index 66d90ba1aa6e..104cc9a9a984 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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_dapxsumkbn2_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/dapxsumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/repl.txt index dad790e96f5e..ed8c60ad82f9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, alpha, x, stride ) - Adds a constant to each double-precision floating-point strided array - element and computes the sum using a second-order iterative Kahan–Babuška - algorithm. +{{alias}}( N, alpha, x, strideX ) + Adds a scalar constant to each double-precision floating-point strided + array element and computes the sum using a second-order iterative + Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in the strided + The `N` and stride parameters determine which elements in the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -23,7 +23,7 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. Returns @@ -50,13 +50,13 @@ 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 a second-order iterative Kahan–Babuška - algorithm and 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 a second-order iterative + Kahan–Babuška algorithm and 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 + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -70,10 +70,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/dapxsumkbn2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/types/index.d.ts index 523db7cbec4d..54056a107a3a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 using a second-order iterative Kahan–Babuška algorithm. + * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * @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 = dapxsumkbn2( 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 a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. + * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and 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 = dapxsumkbn2.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 using a second-order iterative Kahan–Babuška algorithm. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * @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/dapxsumkbn2/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/c/example.c index 245dc883a84e..08422d30a6d6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/c/example.c @@ -25,13 +25,13 @@ int main( void ) { 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; + const int N = 4; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Compute the sum: - double v = stdlib_strided_dapxsumkbn2( N, 5.0, x, stride ); + double v = stdlib_strided_dapxsumkbn2( N, 5.0, x, strideX ); // Print the result: printf( "sum: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/index.js index 61f5f8a3589c..a1b0ca0a4852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 dapxsumkbn2 = require( './../lib' ); -var x = filledarrayBy( 10, 'float64', discreteUniform( 0.0, 100.0 ) ); +var x =discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = dapxsumkbn2( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/include/stdlib/blas/ext/base/dapxsumkbn2.h b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/include/stdlib/blas/ext/base/dapxsumkbn2.h index 880f2b4331aa..f521e0ba4445 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/include/stdlib/blas/ext/base/dapxsumkbn2.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/include/stdlib/blas/ext/base/dapxsumkbn2.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DAPXSUMKBN2_H #define STDLIB_BLAS_EXT_BASE_DAPXSUMKBN2_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,12 @@ extern "C" { /** * Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. */ -double stdlib_strided_dapxsumkbn2( const int64_t N, const double alpha, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dapxsumkbn2)( 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 a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dapxsumkbn2_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/dapxsumkbn2/lib/dapxsumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.js index 4765f0cdf205..a8983376ea59 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.js @@ -20,13 +20,14 @@ // MODULES // -var abs = require( '@stdlib/math/base/special/abs' ); +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 using a second-order iterative Kahan–Babuška algorithm. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * ## Method * @@ -39,7 +40,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); * @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 @@ -51,51 +52,8 @@ var abs = require( '@stdlib/math/base/special/abs' ); * var v = dapxsumkbn2( N, 5.0, x, 1 ); * // returns 16.0 */ -function dapxsumkbn2( N, alpha, x, stride ) { - var sum; - var ccs; - var ix; - var cs; - var cc; - var v; - var t; - var c; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return alpha + x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - sum = 0.0; - ccs = 0.0; // second order correction term for lost low order bits - cs = 0.0; // first order correction term for lost low order bits - for ( i = 0; i < N; i++ ) { - v = alpha + x[ ix ]; - t = sum + v; - if ( abs( sum ) >= abs( v ) ) { - c = (sum-t) + v; - } else { - c = (v-t) + sum; - } - sum = t; - t = cs + c; - if ( abs( cs ) >= abs( c ) ) { - cc = (cs-t) + c; - } else { - cc = (c-t) + cs; - } - cs = t; - ccs += cc; - ix += stride; - } - return sum + cs + ccs; +function dapxsumkbn2( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.native.js index 30a9ca3ea7a8..5d9b338d8ab4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/dapxsumkbn2.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 using a second-order iterative Kahan–Babuška algorithm. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * @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 = dapxsumkbn2( N, 5.0, x, 1 ); * // returns 16.0 */ -function dapxsumkbn2( N, alpha, x, stride ) { - return addon( N, alpha, x, stride ); +function dapxsumkbn2( N, alpha, x, strideX ) { + return addon( N, alpha, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/index.js index a9a7eb15ef6d..3d163d1274c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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 using a second-order iterative Kahan–Babuška algorithm. +* Add a scalar constant to each double-precision floating-point strided array element and compute the sum using a second-order iterative Kahan–Babuška algorithm. * * @module @stdlib/blas/ext/base/dapxsumkbn2 * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.js index 180c029a73ee..658a838aff87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.js @@ -26,7 +26,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); // MAIN // /** -* Adds a constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * ## Method * @@ -39,8 +39,8 @@ var abs = require( '@stdlib/math/base/special/abs' ); * @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 @@ -51,7 +51,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); * var v = dapxsumkbn2( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dapxsumkbn2( N, alpha, x, stride, offset ) { +function dapxsumkbn2( N, alpha, x, strideX, offsetX ) { var sum; var ccs; var ix; @@ -65,10 +65,10 @@ function dapxsumkbn2( N, alpha, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return alpha + x[ 0 ]; } - ix = offset; + ix = offsetX; sum = 0.0; ccs = 0.0; // second order correction term for lost low order bits cs = 0.0; // first order correction term for lost low order bits @@ -89,7 +89,7 @@ function dapxsumkbn2( N, alpha, x, stride, offset ) { } cs = t; ccs += cc; - ix += stride; + ix += strideX; } return sum + cs + ccs; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.native.js index 50d8c9b9ef00..67a1ecd9f3d6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/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( './dapxsumkbn2.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 using a second-order iterative Kahan–Babuška algorithm. +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. * * @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,14 +43,8 @@ var addon = require( './dapxsumkbn2.native.js' ); * var v = dapxsumkbn2( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function dapxsumkbn2( N, alpha, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - - view = offsetView( x, offset ); - - return addon( N, alpha, view, stride ); +function dapxsumkbn2( N, alpha, x, strideX, offsetX ) { + return addon.ndarray( N, alpha, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/manifest.json index 98f1e13e57d4..81c9d3af44e5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/manifest.json @@ -28,50 +28,56 @@ { "task": "build", "src": [ - "./src/dapxsumkbn2.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/create-double" ] }, { "task": "benchmark", "src": [ - "./src/dapxsumkbn2.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", "src": [ - "./src/dapxsumkbn2.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/package.json b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/package.json index deecb4a33c91..f252be979eb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/dapxsumkbn2", "version": "0.0.0", - "description": "Add a constant to each double-precision floating-point strided array element and compute the sum using a second-order iterative Kahan–Babuška algorithm.", + "description": "Add a scalar constant to each double-precision floating-point strided array element and compute the sum using a second-order iterative Kahan–Babuška algorithm.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/addon.c index ee392ba968cf..2793fbca1e5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/addon.c @@ -17,13 +17,14 @@ */ #include "stdlib/blas/ext/base/dapxsumkbn2.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_dapxsumkbn2( 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_dapxsumkbn2)( N, alpha, X, strideX ), v ); + return 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_dapxsumkbn2_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/dapxsumkbn2/src/dapxsumkbn2.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/dapxsumkbn2.c deleted file mode 100644 index d2b2ec32c056..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/dapxsumkbn2.c +++ /dev/null @@ -1,85 +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/dapxsumkbn2.h" -#include -#include - -/** -* Adds a constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. -* -* ## Method -* -* - This implementation uses a second-order iterative Kahan–Babuška algorithm, as described by Klein (2005). -* -* ## References -* -* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x). -* -* @param N number of indexed elements -* @param alpha constant -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dapxsumkbn2( const int64_t N, const double alpha, const double *X, const int64_t stride ) { - double sum; - double ccs; - int64_t ix; - int64_t i; - double cs; - double cc; - double v; - double t; - double c; - - if ( N <= 0 ) { - return 0.0; - } - if ( N == 1 || stride == 0 ) { - return alpha + X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - sum = 0.0; - ccs = 0.0; // second order correction term for lost low order bits - cs = 0.0; // first order correction term for lost low order bits - for ( i = 0; i < N; i++ ) { - v = alpha + X[ ix ]; - t = sum + v; - if ( fabs( sum ) >= fabs( v ) ) { - c = (sum-t) + v; - } else { - c = (v-t) + sum; - } - sum = t; - t = cs + c; - if ( fabs( cs ) >= fabs( c ) ) { - cc = (cs-t) + c; - } else { - cc = (c-t) + cs; - } - cs = t; - ccs += cc; - ix += stride; - } - return sum + cs + ccs; -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/main.c new file mode 100644 index 000000000000..9687320510a4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/src/main.c @@ -0,0 +1,105 @@ +/** +* @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/dapxsumkbn2.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/math/base/special/abs.h" + +/** +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm. +* +* ## Method +* +* - This implementation uses a second-order iterative Kahan–Babuška algorithm, as described by Klein (2005). +* +* ## References +* +* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x). +* +* @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_dapxsumkbn2)( 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_dapxsumkbn2_ndarray)( N, alpha, X, strideX, ox ); +} + +/** +* Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. +* +* ## Method +* +* - This implementation uses a second-order iterative Kahan–Babuška algorithm, as described by Klein (2005). +* +* ## References +* +* - Klein, Andreas. 2005. "A Generalized Kahan-Babuška-Summation-Algorithm." _Computing_ 76 (3): 279–93. doi:[10.1007/s00607-005-0139-x](https://doi.org/10.1007/s00607-005-0139-x).* +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX index increment +* @param offsetX starting index +* @return output value +*/ +double stdlib_strided_dapxsumkbn2_ndarray( const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + double sum; + double ccs; + CBLAS_INT ix; + CBLAS_INT i; + double cs; + double cc; + double v; + double t; + double c; + + if ( N <= 0 ) { + return 0.0; + } + if ( N == 1 || strideX == 0 ) { + return alpha + X[ 0 ]; + } + ix = offsetX; + sum = 0.0; + ccs = 0.0; // second order correction term for lost low order bits + cs = 0.0; // first order correction term for lost low order bits + for ( i = 0; i < N; i++ ) { + v = alpha + X[ ix ]; + t = sum + v; + if ( stdlib_base_abs( sum ) >= stdlib_base_abs( v ) ) { + c = (sum-t) + v; + } else { + c = (v-t) + sum; + } + sum = t; + t = cs + c; + if ( stdlib_base_abs( cs ) >= stdlib_base_abs( c ) ) { + cc = (cs-t) + c; + } else { + cc = (c-t) + cs; + } + cs = t; + ccs += cc; + ix += strideX; + } + return sum + cs + ccs; +}